]> gitweb.hhaalo.de Git - feierabend.git/commitdiff
add test enviroment cmocka
authorBastian Dehn <hhaalo@arcor.de>
Sun, 9 Jun 2024 08:09:03 +0000 (10:09 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 9 Jun 2024 08:09:03 +0000 (10:09 +0200)
CMakeLists.txt
main.c [deleted file]
src/CMakeLists.txt [new file with mode: 0644]
src/main.c [new file with mode: 0644]
tests/CMakeLists.txt [new file with mode: 0644]
tests/main.c [new file with mode: 0644]

index 39cd63894aecd1984c75fdbc19f8d437f020bc71..b33b1de119f6d9935679d5934738a01c076386da 100644 (file)
@@ -2,12 +2,14 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.25.1)
 
 SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING "build type")
 
+
 IF(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
        SET(CMAKE_C_FLAGS "-Wall -g -fsanitize=address")
 ENDIF()
 
 MESSAGE(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
 
-PROJECT(feierabend VERSION 0.0.1)
+PROJECT(feierabend-c)
 
-ADD_EXECUTABLE(${PROJECT_NAME} main.c)
\ No newline at end of file
+ADD_SUBDIRECTORY(src)
+ADD_SUBDIRECTORY(tests)
\ No newline at end of file
diff --git a/main.c b/main.c
deleted file mode 100644 (file)
index e3bfac7..0000000
--- a/main.c
+++ /dev/null
@@ -1,7 +0,0 @@
-#include <stdio.h>
-
-int main()
-{
-       printf("Hello World!\n");
-       return 0;
-}
\ No newline at end of file
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644 (file)
index 0000000..a838995
--- /dev/null
@@ -0,0 +1,5 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 3.25.1)
+
+PROJECT(feierabend VERSION 0.0.1)
+
+ADD_EXECUTABLE(${PROJECT_NAME} main.c)
\ No newline at end of file
diff --git a/src/main.c b/src/main.c
new file mode 100644 (file)
index 0000000..e3bfac7
--- /dev/null
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main()
+{
+       printf("Hello World!\n");
+       return 0;
+}
\ No newline at end of file
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644 (file)
index 0000000..3c27b93
--- /dev/null
@@ -0,0 +1,15 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 3.25.1)
+
+FIND_LIBRARY(CMOCKA cmocka REQUIRED)
+
+ADD_EXECUTABLE(feierabend-test main.c)
+TARGET_LINK_LIBRARIES(feierabend-test
+       ${CMOCKA})
+
+INCLUDE(CTest)
+ADD_TEST(NAME feierabendtest
+       COMMAND feierabend-test)
+
+ADD_CUSTOM_TARGET(run-tests
+       ALL "ctest" "--verbose"
+       DEPENDS feierabend-test)
\ No newline at end of file
diff --git a/tests/main.c b/tests/main.c
new file mode 100644 (file)
index 0000000..2b03b4a
--- /dev/null
@@ -0,0 +1,20 @@
+#define UNIT_TESTING
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+void sanity_check()
+{
+       assert_false(0);
+}
+
+int main()
+{
+       const struct CMUnitTest tests[] = {
+               cmocka_unit_test(sanity_check)
+       };
+
+       return cmocka_run_group_tests(tests, NULL, NULL);
+}
\ No newline at end of file