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
* remove custom targets for tests
* remove uneeded warning from https://gitlab.kitware.com/cmake/cmake/-/issues/16062
  • Loading branch information
felixschurk committed May 7, 2024
1 parent 60575a1 commit 8f6a0d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 31 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
40 changes: 9 additions & 31 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
cmake_minimum_required (VERSION 3.22)

# This is a work-around for the following CMake issue:
# https://gitlab.kitware.com/cmake/cmake/issues/16062
# The issue has been fixed in CMake 3.11.0; the policy is set
# to OLD for compatibility with older versions of CMake only.
if(POLICY CMP0037 AND ${CMAKE_VERSION} VERSION_LESS "3.11.0")
cmake_policy(SET CMP0037 OLD)
endif()

include_directories (${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/src/tc/lib
Expand Down Expand Up @@ -51,30 +43,23 @@ 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)

foreach (src_FILE ${test_SRCS})
add_executable (${src_FILE} ${src_FILE} test.cpp)
target_link_libraries (${src_FILE} task tc commands columns libshared task tc commands columns libshared task commands columns libshared ${TASK_LIBRARIES})
add_dependencies (${src_FILE} task_executable)
if (DARWIN)
target_link_libraries (${src_FILE} "-framework CoreFoundation -framework Security -framework SystemConfiguration")
endif (DARWIN)

# Add a custom `foo.test` target.
string(REGEX REPLACE "\\.[^.]*$" "" test_target ${src_FILE})
add_custom_target (${test_target}
./${src_FILE}
DEPENDS ${src_FILE}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test)
add_test(NAME ${src_FILE}
COMMAND ${src_FILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
endforeach (src_FILE)

configure_file(run_all run_all COPYONLY)
configure_file(problems problems COPYONLY)
configure_file(bash_tap.sh bash_tap.sh COPYONLY)
configure_file(bash_tap_tw.sh bash_tap_tw.sh COPYONLY)

Expand Down Expand Up @@ -205,15 +190,8 @@ set (pythonTests
foreach (python_Test ${pythonTests})
configure_file(${python_Test} ${python_Test} COPYONLY)

# Add a custom `foo.test` target.
string(REGEX REPLACE "\\.[^.]*$" "" test_target ${python_Test})
add_custom_target (${test_target}
./${python_Test}
DEPENDS ${python_Test}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test)
add_test(NAME ${python_Test}
COMMAND ${Python_EXECUTABLE} ${python_Test}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
endforeach(python_Test)

#SET(CMAKE_BUILD_TYPE gcov)
#SET(CMAKE_CXX_FLAGS_GCOV "--coverage")
#SET(CMAKE_C_FLAGS_GCOV "--coverage")
#SET(CMAKE_EXE_LINKER_FLAGS_GCOV "--coverage")

0 comments on commit 8f6a0d5

Please sign in to comment.