Skip to content

Commit

Permalink
add ctest as test driver
Browse files Browse the repository at this point in the history
* add `enable_testing()` in top level CMakeLists to discover tests
* add `add_test` for both unit tests as well as integration tests with
  prefixing the tests with the corresponding test type
  • Loading branch information
felixschurk committed May 7, 2024
1 parent 60575a1 commit 8e6cc9c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required (VERSION 3.22)
enable_testing()

set (CMAKE_EXPORT_COMPILE_COMMANDS ON)

Expand Down
14 changes: 10 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ set (test_SRCS
view.test.cpp
)

add_custom_target (test ./run_all --verbose
DEPENDS ${test_SRCS} task_executable
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test)

add_custom_target (build_tests DEPENDS ${test_SRCS}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test)

Expand All @@ -71,6 +67,11 @@ foreach (src_FILE ${test_SRCS})
./${src_FILE}
DEPENDS ${src_FILE}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test)

add_test(NAME unittest_${src_FILE}
COMMAND ${src_FILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
endforeach (src_FILE)

configure_file(run_all run_all COPYONLY)
Expand Down Expand Up @@ -211,6 +212,11 @@ foreach (python_Test ${pythonTests})
./${python_Test}
DEPENDS ${python_Test}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test)

add_test(NAME integrationtest_${python_Test}
COMMAND ${Python_EXECUTABLE} ${python_Test}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
endforeach(python_Test)

#SET(CMAKE_BUILD_TYPE gcov)
Expand Down

0 comments on commit 8e6cc9c

Please sign in to comment.