CTest does not detect tests

I have a project with a structure

β”œβ”€β”€ CMakeLists.txt β”œβ”€β”€ mzl.c β”œβ”€β”€ mzl.h └── tests β”œβ”€β”€ CMakeLists.txt β”œβ”€β”€ mzl-communication-test.c β”œβ”€β”€ mzl-setup-test.c β”œβ”€β”€ mzl-test-errors.c └── mzl-test-errors.h 

Where is the top directory CMakeLists.txt

 project(mzl) cmake_minimum_required(VERSION 2.8) add_subdirectory(tests) # Enable testing for the project enable_testing() # Find zmq find_library(ZMQ_LIB zmq REQUIRED) message(STATUS "ZMQ Library: ${ZMQ_LIB}") # Find threading library set(CMAKE_THREAD_PREFER_PTHREAD ON) find_package(Threads REQUIRED) message(STATUS "Threading Library: ${CMAKE_THREAD_LIBS_INIT}") # Set include directories for headers set ( MZL_INCLUDE_DIRS ${CMAKE_SOURCE_DIR} CACHE STRING "MZL Include Directories" ) include_directories(${MZL_INCLUDE_DIRS}) # Set source files set ( MZL_SRC_FILES mzl.c ) # Add library add_library(${PROJECT_NAME} STATIC ${MZL_SRC_FILES}) # Link to zmq target_link_libraries(${PROJECT_NAME} ${ZMQ_LIB} ${CMAKE_THREAD_LIBS_INIT}) 

and tests/CMakeLists.txt is

 # Use MZL Source Directories (mzl headers are in top directory) include_directories(${CMAKE_SOURCE_DIR}) # Variable from here is empty message(STATUS "MZL Include Directories: ${MZL_INCLUDE_DIRS}") # Files common to all tests set ( TEST_COMMON_SOURCES mzl-test-errors.c ) # Library setup/shutdown testing set(SETUP_TEST_NAME mzl-setup-test) add_executable(${SETUP_TEST_NAME} ${TEST_COMMON_SOURCES} ${SETUP_TEST_NAME}.c) target_link_libraries(${SETUP_TEST_NAME} ${PROJECT_NAME} ${ZMQ_LIB}) add_test(${SETUP_TEST_NAME} ${SETUP_TEST_NAME}) # Communcations test set(COMMUNICATION_TEST_NAME mzl-communication-test) add_executable(${COMMUNICATION_TEST_NAME} ${TEST_COMMON_SOURCES} ${COMMUNICATION_TEST_NAME}.c) target_link_libraries(${COMMUNICATION_TEST_NAME} ${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT} ${ZMQ_LIB}) add_test(${COMMUNICATION_TEST_NAME} ${COMMUNICATION_TEST_NAME}) 

Everything worked fine before adding the second mzl-communication-test . After adding it and the lines to tests/CMakeLists.txt after the # Communications test running ctest did nothing - it still ran only the first test.

After deleting the build directory and starting cmake again, I get no errors for starting CMake initially, but running make starts CMake again, resulting in an error with CMake:

 CMake Error: Parse error in cache file build/CMakeCache.txt. Offending entry: include 

followed by a make error:

 Makefile:203: recipe for target 'cmake_check_build_system' failed make: *** [cmake_check_build_system] Error 1 

Running make again leads to the creation of everything, including tests; however running ctest results in

 Test project build No tests were found!!! 

The problem seems to be related to something that I am doing with CMake, but I can’t figure out what to do next, because I don’t see anything that I do other than when it originally worked. Even my last fix on git, which worked when I did it, no longer works.

+5
source share
1 answer

You need to move the enable_testing() call before you do add_subdirectory(tests)

 # Enable testing for the project enable_testing() add_subdirectory(tests) 
+11
source

All Articles