ctest: Exit with failure when tests-from-file input is missing

If the options added by

* commit 022f20f663 (ctest: add command line option to run the tests listed
                     in a given file, 2023-11-29, v3.29.0-rc1~66^2~2)
* commit dbacc1d5a8 (ctest: add command line option to exclude tests listed
                     in a given file, 2023-11-30, v3.29.0-rc1~66^2~1)
* commit 701029726f (ctest_test: add options INCLUDE_FROM_FILE and
                     EXCLUDE_FROM_FILE, 2023-12-03, v3.29.0-rc1~66^2)

are given a missing file, fail instead of ignoring it.

Fixes: #25740
This commit is contained in:
Brad King
2024-03-06 13:22:01 -05:00
parent 60433fc6e8
commit ca0a9def2e
16 changed files with 38 additions and 10 deletions

View File

@@ -1845,11 +1845,15 @@ bool cmCTestTestHandler::GetListOfTests()
}
if (!this->TestListFile.empty()) {
this->TestsToRunByName = this->ReadTestListFile(this->TestListFile);
if (!this->ReadTestListFile(this->TestListFile, this->TestsToRunByName)) {
return false;
}
}
if (!this->ExcludeTestListFile.empty()) {
this->TestsToExcludeByName =
this->ReadTestListFile(this->ExcludeTestListFile);
if (!this->ReadTestListFile(this->ExcludeTestListFile,
this->TestsToExcludeByName)) {
return false;
}
}
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
@@ -2020,11 +2024,10 @@ void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed()
}
}
std::set<std::string> cmCTestTestHandler::ReadTestListFile(
const std::string& testListFileName) const
bool cmCTestTestHandler::ReadTestListFile(
std::string const& testListFileName, std::set<std::string>& testNames) const
{
std::set<std::string> testNames;
testNames.clear();
cmsys::ifstream ifs(testListFileName.c_str());
if (ifs) {
std::string line;
@@ -2043,9 +2046,10 @@ std::set<std::string> cmCTestTestHandler::ReadTestListFile(
"Problem reading test list file: "
<< testListFileName
<< " while generating list of tests to run." << std::endl);
return false;
}
return testNames;
return true;
}
void cmCTestTestHandler::RecordCustomTestMeasurements(cmXMLWriter& xml,

View File

@@ -341,8 +341,8 @@ private:
std::string GetTestStatus(cmCTestTestResult const&);
void ExpandTestsToRunInformation(size_t numPossibleTests);
void ExpandTestsToRunInformationForRerunFailed();
std::set<std::string> ReadTestListFile(
const std::string& testListFileName) const;
bool ReadTestListFile(std::string const& testListFileName,
std::set<std::string>& testNames) const;
std::vector<std::string> CustomPreTest;
std::vector<std::string> CustomPostTest;

View File

@@ -223,6 +223,8 @@ add_test(Test11 \"${CMAKE_COMMAND}\" -E echo \"test11\")
endfunction()
run_TestsFromFileTest(include --tests-from-file ${RunCMake_SOURCE_DIR}/TestsFromFile-TestList.txt)
run_TestsFromFileTest(exclude --exclude-from-file ${RunCMake_SOURCE_DIR}/TestsFromFile-TestList.txt)
run_TestsFromFileTest(include-missing --tests-from-file ${RunCMake_SOURCE_DIR}/TestsFromFile-TestList-missing.txt)
run_TestsFromFileTest(exclude-missing --exclude-from-file ${RunCMake_SOURCE_DIR}/TestsFromFile-TestList-missing.txt)
function(run_SerialFailed)

View File

@@ -0,0 +1,2 @@
Problem reading test list file: [^
]*/Tests/RunCMake/CTestCommandLine/TestsFromFile-TestList-missing\.txt while generating list of tests to run\.

View File

@@ -0,0 +1,2 @@
Test project [^
]*/Tests/RunCMake/CTestCommandLine/TestsFromFile$

View File

@@ -0,0 +1,2 @@
Problem reading test list file: [^
]*/Tests/RunCMake/CTestCommandLine/TestsFromFile-TestList-missing\.txt while generating list of tests to run\.

View File

@@ -0,0 +1,2 @@
Test project [^
]*/Tests/RunCMake/CTestCommandLine/TestsFromFile$

View File

@@ -177,6 +177,8 @@ add_test(NAME Test11 COMMAND ${CMAKE_COMMAND} -E true)
endfunction()
run_tests_from_file(include INCLUDE_FROM_FILE ${RunCMake_SOURCE_DIR}/TestsFromFile-TestList.txt)
run_tests_from_file(exclude EXCLUDE_FROM_FILE ${RunCMake_SOURCE_DIR}/TestsFromFile-TestList.txt)
run_tests_from_file(include-missing INCLUDE_FROM_FILE ${RunCMake_SOURCE_DIR}/TestsFromFile-TestList-missing.txt)
run_tests_from_file(exclude-missing EXCLUDE_FROM_FILE ${RunCMake_SOURCE_DIR}/TestsFromFile-TestList-missing.txt)
# Make sure environment gets logged

View File

@@ -0,0 +1 @@
(-1|255)

View File

@@ -0,0 +1,2 @@
Problem reading test list file: [^
]*/Tests/RunCMake/ctest_test/TestsFromFile-TestList-missing\.txt while generating list of tests to run\.

View File

@@ -0,0 +1,2 @@
Test project [^
]*/Tests/RunCMake/ctest_test/TestsFromFile-exclude-missing-build$

View File

@@ -0,0 +1 @@
(-1|255)

View File

@@ -0,0 +1,2 @@
Problem reading test list file: [^
]*/Tests/RunCMake/ctest_test/TestsFromFile-TestList-missing\.txt while generating list of tests to run\.

View File

@@ -0,0 +1,2 @@
Test project [^
]*/Tests/RunCMake/ctest_test/TestsFromFile-include-missing-build$