CTEST未检测到测试



我有一个带有结构的项目

├── 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中的行之后,运行ctest什么也没做 - 它仍然只进行了第一个测试。

删除构建目录并再次运行cmake后,我没有对初始CMake运行的错误,但是运行make再次运行CMAKE,导致CMAKE的错误:

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

随后是一个错误:

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)

相关内容

  • 没有找到相关文章

最新更新