Define the tests in tests/CMakeLists.txt
The fixture targets, the test binary, and the six test cases live beside the sources they build, leaving the top-level file with enable_testing, the ctest scratch-area write, and the add_subdirectory call. The paths both files need are set once above that call, so the child's output directories and the parent's clean rule refer to the same variables rather than repeating the paths.
This commit is contained in:
@@ -78,79 +78,26 @@ set_target_properties(info PROPERTIES
|
||||
add_dependencies(dpm info)
|
||||
|
||||
# ---------------------------------------------------------------------
|
||||
# Test fixture modules: one known-good stub, two deliberately broken
|
||||
# Tests
|
||||
#
|
||||
# The test targets and cases are defined in tests/CMakeLists.txt. The
|
||||
# paths they build into are named here, above that directory, so each is
|
||||
# written once and the clean rule below refers to the same values.
|
||||
# ---------------------------------------------------------------------
|
||||
enable_testing()
|
||||
|
||||
set(DPM_TEST_DIR ${CMAKE_BINARY_DIR}/tests)
|
||||
set(DPM_TEST_FIXTURE_DIR ${DPM_TEST_DIR}/fixtures)
|
||||
set(DPM_TEST_RESULTS_DIR ${CMAKE_BINARY_DIR}/test-results)
|
||||
|
||||
# CTest's scratch area is named by its BuildDirectory configuration option.
|
||||
# Writing it into DartConfiguration.tcl puts it where ctest reads it on every
|
||||
# invocation — the test target, a bare ctest, and the IDE's test discovery
|
||||
# alike — rather than only the ones the build drives.
|
||||
file(WRITE ${CMAKE_BINARY_DIR}/DartConfiguration.tcl
|
||||
"BuildDirectory: ${CMAKE_BINARY_DIR}/test-results\n")
|
||||
"BuildDirectory: ${DPM_TEST_RESULTS_DIR}\n")
|
||||
|
||||
set(FIXTURE_MODULE_DIR ${CMAKE_BINARY_DIR}/tests/fixtures)
|
||||
|
||||
foreach(fixture good missing_symbols bad_version)
|
||||
add_library(fixture_${fixture} MODULE tests/fixtures/src/${fixture}.cpp)
|
||||
set_target_properties(fixture_${fixture} PROPERTIES
|
||||
PREFIX ""
|
||||
SUFFIX ".so"
|
||||
OUTPUT_NAME ${fixture}
|
||||
LIBRARY_OUTPUT_DIRECTORY ${FIXTURE_MODULE_DIR}
|
||||
)
|
||||
endforeach()
|
||||
|
||||
# ---------------------------------------------------------------------
|
||||
# API test binary — drives libdpm-core through its public C API
|
||||
# ---------------------------------------------------------------------
|
||||
add_executable(test_core tests/test_core.cpp)
|
||||
|
||||
target_link_libraries(test_core PRIVATE dpm-core)
|
||||
|
||||
target_compile_definitions(test_core PRIVATE
|
||||
TEST_FIXTURE_MODULES="${FIXTURE_MODULE_DIR}"
|
||||
TEST_FIXTURE_CONF="${CMAKE_CURRENT_SOURCE_DIR}/tests/fixtures/conf"
|
||||
DPM_CORE_VERSION_EXPECTED="${PROJECT_VERSION}"
|
||||
)
|
||||
|
||||
set_target_properties(test_core PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests
|
||||
BUILD_RPATH "$ORIGIN/../lib"
|
||||
)
|
||||
|
||||
foreach(fixture good missing_symbols bad_version)
|
||||
add_dependencies(test_core fixture_${fixture})
|
||||
endforeach()
|
||||
|
||||
add_test(NAME core_api COMMAND test_core)
|
||||
|
||||
# ---------------------------------------------------------------------
|
||||
# CLI end-to-end tests (the dpm binary is the cheapest full-stack client)
|
||||
# ---------------------------------------------------------------------
|
||||
add_test(NAME cli_help COMMAND dpm --help)
|
||||
set_tests_properties(cli_help PROPERTIES PASS_REGULAR_EXPRESSION "Usage: dpm")
|
||||
|
||||
add_test(NAME cli_list
|
||||
COMMAND dpm -c ${CMAKE_CURRENT_SOURCE_DIR}/tests/fixtures/conf
|
||||
-m ${CMAKE_BINARY_DIR}/modules --list-modules)
|
||||
set_tests_properties(cli_list PROPERTIES PASS_REGULAR_EXPRESSION "info")
|
||||
|
||||
add_test(NAME cli_info_version
|
||||
COMMAND dpm -c ${CMAKE_CURRENT_SOURCE_DIR}/tests/fixtures/conf
|
||||
-m ${CMAKE_BINARY_DIR}/modules -L INFO info version)
|
||||
set_tests_properties(cli_info_version PROPERTIES
|
||||
PASS_REGULAR_EXPRESSION "libdpm-core Version: ${PROJECT_VERSION}")
|
||||
|
||||
add_test(NAME cli_module_not_found
|
||||
COMMAND dpm -c ${CMAKE_CURRENT_SOURCE_DIR}/tests/fixtures/conf
|
||||
-m ${CMAKE_BINARY_DIR}/modules nonexistent)
|
||||
set_tests_properties(cli_module_not_found PROPERTIES WILL_FAIL TRUE)
|
||||
|
||||
add_test(NAME cli_rejects_invalid_module
|
||||
COMMAND dpm -c ${CMAKE_CURRENT_SOURCE_DIR}/tests/fixtures/conf
|
||||
-m ${FIXTURE_MODULE_DIR} missing_symbols)
|
||||
set_tests_properties(cli_rejects_invalid_module PROPERTIES WILL_FAIL TRUE)
|
||||
add_subdirectory(tests)
|
||||
|
||||
# ---------------------------------------------------------------------
|
||||
# Code reference (Doxygen) — optional 'docs' target
|
||||
@@ -261,12 +208,12 @@ endif()
|
||||
# the project is reloaded. Removing the build system is what configuring a
|
||||
# fresh directory is for.
|
||||
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES
|
||||
${CMAKE_BINARY_DIR}/test-results
|
||||
${DPM_TEST_RESULTS_DIR}
|
||||
${CMAKE_BINARY_DIR}/Testing
|
||||
${CMAKE_BINARY_DIR}/bin
|
||||
${CMAKE_BINARY_DIR}/lib
|
||||
${CMAKE_BINARY_DIR}/modules
|
||||
${CMAKE_BINARY_DIR}/tests
|
||||
${DPM_TEST_DIR}
|
||||
${CMAKE_BINARY_DIR}/docs
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user