CTest: Add support for relative paths in GENERATED_RESOURCE_SPEC_FILE

This commit is contained in:
Arha Gatram
2026-07-22 09:49:28 -07:00
parent 3eda12235e
commit 4c2d06e69b
10 changed files with 50 additions and 13 deletions
@@ -5,3 +5,9 @@ GENERATED_RESOURCE_SPEC_FILE
Path to the :ref:`dynamically-generated resource spec file
<ctest-resource-dynamically-generated-spec-file>` generated by this test.
.. versionchanged:: 4.5
Relative paths are interpreted relative to the
:variable:`CMAKE_BINARY_DIR` or the directory specified by the
CTest option :ctest-option:`--test-dir` if provided. Prior to CMake 4.5,
this property only accepted absolute paths.
@@ -0,0 +1,5 @@
ctest-dyn-rsrc-spec-rel-path
----------------------------
* The :prop_test:`GENERATED_RESOURCE_SPEC_FILE` test property gained support
for relative paths.
@@ -1650,14 +1650,6 @@ bool cmCTestMultiProcessHandler::CheckGeneratedResourceSpec()
return false;
}
if (!cmSystemTools::FileIsFullPath(
test.second->GeneratedResourceSpecFile)) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
"GENERATED_RESOURCE_SPEC_FILE must be an absolute path"
<< std::endl);
return false;
}
this->ResourceSpecSetupTest = test.first;
this->ResourceSpecSetupFixture = *test.second->FixturesSetup.begin();
}
@@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.10)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)
@@ -205,3 +205,25 @@ run_ctest_resource_dynamic(dynamic-resource-conflicting-spec -DCTEST_RESOURCE_SP
run_ctest_resource_dynamic(dynamic-resource-circular)
run_ctest_resource_dynamic(dynamic-resource-circular-no-required-fixtures)
run_ctest_resource_dynamic(dynamic-resource-relative-path)
function(run_resource_dynamic_subdirectory_cli test_name test_dir)
set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${test_name}-build")
run_cmake(${test_name})
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_OUTPUT_MERGE 1)
if(test_dir)
set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY "${test_dir}")
endif()
run_cmake_command(${test_name}-test ${CMAKE_CTEST_COMMAND} -C Debug ${ARGN})
endfunction()
block()
run_resource_dynamic_subdirectory_cli(
dynamic-resource-relative-path-subdirectory ""
--test-dir "${RunCMake_BINARY_DIR}/dynamic-resource-relative-path-subdirectory-build"
)
run_resource_dynamic_subdirectory_cli(
dynamic-resource-relative-path-test-dir "${RunCMake_BINARY_DIR}"
--test-dir "${RunCMake_BINARY_DIR}/dynamic-resource-relative-path-test-dir-build"
)
endblock()
@@ -1,4 +0,0 @@
^GENERATED_RESOURCE_SPEC_FILE must be an absolute path
CMake Error at [^
]*/Tests/RunCMake/CTestResourceAllocation/dynamic-resource-relative-path-ctest-s/test\.cmake:[0-9]+ \(message\):
Tests did not pass$
@@ -0,0 +1,2 @@
enable_testing()
add_subdirectory(subdir)
@@ -0,0 +1,2 @@
enable_testing()
add_subdirectory(subdir)
@@ -0,0 +1,10 @@
add_test(NAME RealTest COMMAND "${CMAKE_COMMAND}" -E true)
add_test(NAME GenerateSpecFile COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_SOURCE_DIR}/dynamic-resspec.json" "${CMAKE_CURRENT_BINARY_DIR}")
set_tests_properties(GenerateSpecFile PROPERTIES
GENERATED_RESOURCE_SPEC_FILE "subdir/dynamic-resspec.json"
FIXTURES_SETUP "ResourceSpec"
)
set_tests_properties(RealTest PROPERTIES
FIXTURES_REQUIRED "ResourceSpec"
RESOURCE_GROUPS "widgets:1"
)