From c3fc6e6701429780ea3bee29f387bfdac10b24fa Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Sun, 4 Dec 2022 09:01:32 +0100 Subject: [PATCH] started idea for testing --- .gitmodules | 3 +++ CMakeLists.txt | 11 +++++++++-- test/CMakeLists.txt | 8 ++++++++ test/test_dynarray.c | 17 +++++++++++++++++ vendor/unity | 1 + 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 .gitmodules create mode 100644 test/CMakeLists.txt create mode 100644 test/test_dynarray.c create mode 160000 vendor/unity diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..c07dee7 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vendor/unity"] + path = vendor/unity + url = https://github.com/ThrowTheSwitch/Unity diff --git a/CMakeLists.txt b/CMakeLists.txt index 14ad55d..ffe4db1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,8 @@ set(CMAKE_C_STANDARD 17) find_package(LibArchive REQUIRED) -include_directories(include) +add_subdirectory(vendor/unity) +include_directories(include vendor/unity/src) file(GLOB CIETER_SRCS src/cieter/**.c) @@ -14,6 +15,12 @@ if(CMAKE_BUILD_TYPE STREQUAL Release) endif() add_library(cieter SHARED ${CIETER_SRCS}) +target_link_libraries(cieter LibArchive::LibArchive) + +if(CMAKE_BUILD_TYPE MATCHES "^Test") + enable_testing() + add_subdirectory(test) +endif() option(BUILD_CIETERD "Build cieterd binary" ON) @@ -21,5 +28,5 @@ if (BUILD_CIETERD) file(GLOB CIETERD_SRCS src/cieterd/**.c) add_executable(cieterd ${CIETERD_SRCS}) - target_link_libraries(cieterd cieter LibArchive::LibArchive) + target_link_libraries(cieterd cieter) endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..2bc400f --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,8 @@ +file(GLOB TEST_SRCS **.c) + +foreach(TEST_SRC ${TEST_SRCS}) + get_filename_component(EXEC_NAME ${TEST_SRC} NAME_WLE) + add_executable(${EXEC_NAME} ${TEST_SRC}) + add_test(NAME ${EXEC_NAME} COMMAND ${EXEC_NAME}) + target_link_libraries(${EXEC_NAME} cieter unity) +endforeach() diff --git a/test/test_dynarray.c b/test/test_dynarray.c new file mode 100644 index 0000000..0cf436b --- /dev/null +++ b/test/test_dynarray.c @@ -0,0 +1,17 @@ +#include "unity.h" +#include "cieter_dynarray.h" + +void setUp(void) {} +void tearDown(void) {} + +void test_init() { + CieterDynArray *arr = cieter_dynarray_init(2); + + TEST_ASSERT_NOT_NULL(arr); +} + +int main(void) { + UNITY_BEGIN(); + RUN_TEST(test_init); + return UNITY_END(); +} diff --git a/vendor/unity b/vendor/unity new file mode 160000 index 0000000..0b92f9b --- /dev/null +++ b/vendor/unity @@ -0,0 +1 @@ +Subproject commit 0b92f9b960e4af9afc2b2d0918ce602111682e54