aboutsummaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/kstd/CMakeLists.txt48
-rw-r--r--libs/kstd/tests/os_mock.cpp15
-rw-r--r--libs/kstd/tests/vector.cpp11
3 files changed, 64 insertions, 10 deletions
diff --git a/libs/kstd/CMakeLists.txt b/libs/kstd/CMakeLists.txt
index b0c9c63..2f360cd 100644
--- a/libs/kstd/CMakeLists.txt
+++ b/libs/kstd/CMakeLists.txt
@@ -1,16 +1,22 @@
add_library("kstd" STATIC)
add_library("libs::kstd" ALIAS "kstd")
-set(KSTD_LIBC_SYMBOLS
- "abort"
- "strlen"
- "memcmp"
- "memcpy"
-)
+if(CMAKE_CROSSCOMPILING)
+ set(KSTD_LIBC_SYMBOLS
+ "abort"
+ "strlen"
+ "memcmp"
+ "memcpy"
+ )
+
+ set(KSTD_LIBC_SOURCES
+ "src/libc/stdlib.cpp"
+ "src/libc/string.cpp"
+ )
+endif()
target_sources("kstd" PRIVATE
- "src/libc/stdlib.cpp"
- "src/libc/string.cpp"
+ ${KSTD_LIBC_SOURCES}
"src/os/error.cpp"
@@ -30,6 +36,28 @@ target_include_directories("kstd" PUBLIC
"include"
)
-list(TRANSFORM KSTD_LIBC_SYMBOLS PREPEND "-Wl,--undefined=")
+if(CMAKE_CROSSCOMPILING)
+ list(TRANSFORM KSTD_LIBC_SYMBOLS PREPEND "-Wl,--undefined=")
+
+ target_link_options("kstd" INTERFACE ${KSTD_LIBC_SYMBOLS})
+endif()
+
+if(NOT CMAKE_CROSSCOMPILING)
+ add_executable("kstd_tests"
+ "tests/vector.cpp"
+ "tests/os_mock.cpp"
+ )
+
+ target_link_libraries("kstd_tests" PRIVATE
+ "Catch2::Catch2WithMain"
+ "libs::kstd"
+ )
+
+ set_target_properties("kstd_tests" PROPERTIES
+ C_CLANG_TIDY ""
+ CXX_CLANG_TIDY ""
+ EXCLUDE_FROM_ALL NO
+ )
-target_link_options("kstd" INTERFACE ${KSTD_LIBC_SYMBOLS}) \ No newline at end of file
+ catch_discover_tests("kstd_tests")
+endif() \ No newline at end of file
diff --git a/libs/kstd/tests/os_mock.cpp b/libs/kstd/tests/os_mock.cpp
new file mode 100644
index 0000000..39b7f0d
--- /dev/null
+++ b/libs/kstd/tests/os_mock.cpp
@@ -0,0 +1,15 @@
+#include <exception>
+#include <format>
+#include <source_location>
+#include <stdexcept>
+#include <string_view>
+
+namespace kstd::os
+{
+ auto panic(std::string_view message, std::source_location location)
+ {
+ auto full_message =
+ std::format("OS Panic Handler called '{}' at {}:{}", message, location.file_name(), location.line());
+ throw std::runtime_error{full_message};
+ }
+} // namespace kstd::os \ No newline at end of file
diff --git a/libs/kstd/tests/vector.cpp b/libs/kstd/tests/vector.cpp
new file mode 100644
index 0000000..3a45008
--- /dev/null
+++ b/libs/kstd/tests/vector.cpp
@@ -0,0 +1,11 @@
+#include <kstd/vector>
+
+#include <catch2/catch_test_macros.hpp>
+
+TEST_CASE("Creating an empty vector")
+{
+ kstd::vector<int> v;
+ REQUIRE(v.empty());
+ REQUIRE(v.size() == 0);
+ REQUIRE(v.capacity() == 0);
+}