From 68caf51b297c31d249c4375ee4ec3884eef3cacd Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sun, 9 Jun 2024 10:09:03 +0200 Subject: [PATCH] add test enviroment cmocka --- CMakeLists.txt | 6 ++++-- src/CMakeLists.txt | 5 +++++ main.c => src/main.c | 0 tests/CMakeLists.txt | 15 +++++++++++++++ tests/main.c | 20 ++++++++++++++++++++ 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/CMakeLists.txt rename main.c => src/main.c (100%) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/main.c 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/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/main.c b/src/main.c similarity index 100% rename from main.c rename to src/main.c 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 -- 2.39.5