From 11a7cf54ebbfb38eb225ee47f69ab93102a1ea1d Mon Sep 17 00:00:00 2001 From: Michael Michaux Date: Wed, 26 Aug 2020 11:14:41 +0200 Subject: [PATCH] Created simple dummy unit tests. --- CMakeLists.txt | 10 ++++++++++ testing/CMakeLists.txt | 12 ++++++++++++ testing/unit/failure.cpp | 5 +++++ testing/unit/success.cpp | 5 +++++ 4 files changed, 32 insertions(+) create mode 100644 testing/CMakeLists.txt create mode 100644 testing/unit/failure.cpp create mode 100644 testing/unit/success.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index cd32a71..b83b4bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -264,4 +264,14 @@ if(ENABLE_GENERICIO) include(${CMAKE_CURRENT_SOURCE_DIR}/external/genericio.cmake) target_link_libraries(${PRGNAME} PRIVATE genericio::genericio_mpi) target_compile_definitions(${PRGNAME} PRIVATE "ENABLE_GENERICIO") +endif() + +################################### Testing #################################### +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + include(CTest) + enable_testing() +endif() + +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) + add_subdirectory(testing) endif() \ No newline at end of file diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt new file mode 100644 index 0000000..34caccc --- /dev/null +++ b/testing/CMakeLists.txt @@ -0,0 +1,12 @@ +# get all unit test sources +file(GLOB UNIT_TEST_SOURCES "${PROJECT_SOURCE_DIR}/testing/unit/*.cpp") + +# create the tests +foreach(UNIT_TEST_CPP ${UNIT_TEST_SOURCES}) + get_filename_component(UNIT_TEST_NAME ${UNIT_TEST_CPP} NAME_WE) + add_executable(${UNIT_TEST_NAME} ${UNIT_TEST_CPP}) + add_test(NAME ${UNIT_TEST_NAME} COMMAND ${UNIT_TEST_NAME}) +endforeach() + +# add properties to specific tests +set_tests_properties(failure PROPERTIES WILL_FAIL true) \ No newline at end of file diff --git a/testing/unit/failure.cpp b/testing/unit/failure.cpp new file mode 100644 index 0000000..5c43d0b --- /dev/null +++ b/testing/unit/failure.cpp @@ -0,0 +1,5 @@ +#include + +int main(int argc, char const *argv[]) { + return EXIT_FAILURE; +} diff --git a/testing/unit/success.cpp b/testing/unit/success.cpp new file mode 100644 index 0000000..f57318c --- /dev/null +++ b/testing/unit/success.cpp @@ -0,0 +1,5 @@ +#include + +int main(int argc, char const *argv[]) { + return EXIT_SUCCESS; +}