From: Bastian Dehn Date: Sun, 9 Jun 2024 08:09:03 +0000 (+0200) Subject: add test enviroment cmocka X-Git-Tag: 1.0.0^2~56 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=68caf51b297c31d249c4375ee4ec3884eef3cacd;p=feierabend.git add test enviroment cmocka --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 39cd638..b33b1de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 index e3bfac7..0000000 --- a/main.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -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 index 0000000..a838995 --- /dev/null +++ b/src/CMakeLists.txt @@ -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 index 0000000..e3bfac7 --- /dev/null +++ b/src/main.c @@ -0,0 +1,7 @@ +#include + +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 index 0000000..3c27b93 --- /dev/null +++ b/tests/CMakeLists.txt @@ -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 index 0000000..2b03b4a --- /dev/null +++ b/tests/main.c @@ -0,0 +1,20 @@ +#define UNIT_TESTING +#include +#include +#include +#include +#include + +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