CTest 未检测到测试
CTest not detecting tests
我有一个具有结构的项目
├── 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
顶层目录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})
并且 tests/CMakeLists.txt
是
# 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})
在我添加第二个测试之前一切正常mzl-communication-test
。添加它和 # Communications test
之后 tests/CMakeLists.txt
中的行之后,运行ning ctest
没有做任何额外的事情——它仍然只是 运行 第一个测试。
删除构建目录并再次 运行ning cmake
后,初始 CMake 运行 没有错误,但是 运行ning make
运行s CMake 再次,导致 CMake 出错:
CMake Error: Parse error in cache file build/CMakeCache.txt. Offending entry: include
后跟 Make 错误:
Makefile:203: recipe for target 'cmake_check_build_system' failed
make: *** [cmake_check_build_system] Error 1
运行 make
再次导致构建所有内容,包括测试;但是,运行宁 ctest
结果
Test project build
No tests were found!!!
问题似乎出在我用 CMake 做的事情上,但我无法从这里弄清楚该怎么做,因为我看不到我所做的事情与最初工作时有什么不同。甚至我对 git 的最后一次提交,在我提交它时是有效的,现在也不再有效了。
您需要先将 enable_testing()
调用移至 add_subdirectory(tests)
# Enable testing for the project
enable_testing()
add_subdirectory(tests)
我有一个具有结构的项目
├── 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
顶层目录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})
并且 tests/CMakeLists.txt
是
# 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})
在我添加第二个测试之前一切正常mzl-communication-test
。添加它和 # Communications test
之后 tests/CMakeLists.txt
中的行之后,运行ning ctest
没有做任何额外的事情——它仍然只是 运行 第一个测试。
删除构建目录并再次 运行ning cmake
后,初始 CMake 运行 没有错误,但是 运行ning make
运行s CMake 再次,导致 CMake 出错:
CMake Error: Parse error in cache file build/CMakeCache.txt. Offending entry: include
后跟 Make 错误:
Makefile:203: recipe for target 'cmake_check_build_system' failed
make: *** [cmake_check_build_system] Error 1
运行 make
再次导致构建所有内容,包括测试;但是,运行宁 ctest
结果
Test project build
No tests were found!!!
问题似乎出在我用 CMake 做的事情上,但我无法从这里弄清楚该怎么做,因为我看不到我所做的事情与最初工作时有什么不同。甚至我对 git 的最后一次提交,在我提交它时是有效的,现在也不再有效了。
您需要先将 enable_testing()
调用移至 add_subdirectory(tests)
# Enable testing for the project
enable_testing()
add_subdirectory(tests)