ctest: Honor tests-from-file options with empty input

If the `--tests-from-file` input file is empty, no tests should run.
This commit is contained in:
Brad King
2024-03-08 16:05:34 -05:00
parent 8673264e25
commit d52c66bfb3
11 changed files with 53 additions and 22 deletions

View File

@@ -347,6 +347,8 @@ void cmCTestTestHandler::Initialize()
this->ExcludeFixtureCleanupRegExp.clear();
this->TestListFile.clear();
this->ExcludeTestListFile.clear();
this->TestsToRunByName.reset();
this->TestsToExcludeByName.reset();
this->TestsToRunString.clear();
this->UseUnion = false;
@@ -944,16 +946,16 @@ bool cmCTestTestHandler::ComputeTestList()
}
}
if (!this->TestsToRunByName.empty()) {
if (this->TestsToRunByName.find(tp.Name) ==
this->TestsToRunByName.end()) {
if (this->TestsToRunByName) {
if (this->TestsToRunByName->find(tp.Name) ==
this->TestsToRunByName->end()) {
continue;
}
}
if (!this->TestsToExcludeByName.empty()) {
if (this->TestsToExcludeByName.find(tp.Name) !=
this->TestsToExcludeByName.end()) {
if (this->TestsToExcludeByName) {
if (this->TestsToExcludeByName->find(tp.Name) !=
this->TestsToExcludeByName->end()) {
continue;
}
}
@@ -1845,13 +1847,15 @@ bool cmCTestTestHandler::GetListOfTests()
}
if (!this->TestListFile.empty()) {
if (!this->ReadTestListFile(this->TestListFile, this->TestsToRunByName)) {
this->TestsToRunByName = this->ReadTestListFile(this->TestListFile);
if (!this->TestsToRunByName) {
return false;
}
}
if (!this->ExcludeTestListFile.empty()) {
if (!this->ReadTestListFile(this->ExcludeTestListFile,
this->TestsToExcludeByName)) {
this->TestsToExcludeByName =
this->ReadTestListFile(this->ExcludeTestListFile);
if (!this->TestsToExcludeByName) {
return false;
}
}
@@ -2024,12 +2028,13 @@ void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed()
}
}
bool cmCTestTestHandler::ReadTestListFile(
std::string const& testListFileName, std::set<std::string>& testNames) const
cm::optional<std::set<std::string>> cmCTestTestHandler::ReadTestListFile(
std::string const& testListFileName) const
{
testNames.clear();
cm::optional<std::set<std::string>> result;
cmsys::ifstream ifs(testListFileName.c_str());
if (ifs) {
std::set<std::string> testNames;
std::string line;
while (cmSystemTools::GetLineFromStream(ifs, line)) {
std::string trimmed = cmTrimWhitespace(line);
@@ -2039,17 +2044,14 @@ bool cmCTestTestHandler::ReadTestListFile(
testNames.insert(trimmed);
}
ifs.close();
} else if (!this->CTest->GetShowOnly() &&
!this->CTest->ShouldPrintLabels()) {
result = std::move(testNames);
} else {
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Problem reading test list file: "
<< testListFileName
<< " while generating list of tests to run." << std::endl);
return false;
}
return true;
return result;
}
void cmCTestTestHandler::RecordCustomTestMeasurements(cmXMLWriter& xml,

View File

@@ -341,8 +341,8 @@ private:
std::string GetTestStatus(cmCTestTestResult const&);
void ExpandTestsToRunInformation(size_t numPossibleTests);
void ExpandTestsToRunInformationForRerunFailed();
bool ReadTestListFile(std::string const& testListFileName,
std::set<std::string>& testNames) const;
cm::optional<std::set<std::string>> ReadTestListFile(
std::string const& testListFileName) const;
std::vector<std::string> CustomPreTest;
std::vector<std::string> CustomPostTest;
@@ -363,8 +363,8 @@ private:
cmsys::RegularExpression ExcludeTestsRegularExpression;
std::string TestListFile;
std::string ExcludeTestListFile;
std::set<std::string> TestsToRunByName;
std::set<std::string> TestsToExcludeByName;
cm::optional<std::set<std::string>> TestsToRunByName;
cm::optional<std::set<std::string>> TestsToExcludeByName;
std::string ResourceSpecFile;

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-empty --tests-from-file ${RunCMake_SOURCE_DIR}/TestsFromFile-TestList-empty.txt)
run_TestsFromFileTest(exclude-empty --exclude-from-file ${RunCMake_SOURCE_DIR}/TestsFromFile-TestList-empty.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)

View File

@@ -0,0 +1,10 @@
Test project [^
]*/Tests/RunCMake/CTestCommandLine/TestsFromFile-exclude-empty
+Start 1: Test1
1/3 Test #1: Test1 ............................ Passed +[0-9.]+ sec
+Start 2: Test2
2/3 Test #2: Test2 ............................ Passed +[0-9.]+ sec
+Start 3: Test11
3/3 Test #3: Test11 ........................... Passed +[0-9.]+ sec
+
100% tests passed, 0 tests failed out of 3

View File

@@ -0,0 +1 @@
^No tests were found!!!$

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-empty INCLUDE_FROM_FILE ${RunCMake_SOURCE_DIR}/TestsFromFile-TestList-empty.txt)
run_tests_from_file(exclude-empty EXCLUDE_FROM_FILE ${RunCMake_SOURCE_DIR}/TestsFromFile-TestList-empty.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)

View File

@@ -0,0 +1,12 @@
Test project [^
]*/Tests/RunCMake/ctest_test/TestsFromFile-exclude-empty-build
+Start 1: RunCMakeVersion
1/4 Test #1: RunCMakeVersion .................. Passed +[0-9.]+ sec
+Start 2: Test1
2/4 Test #2: Test1 ............................ Passed +[0-9.]+ sec
+Start 3: Test2
3/4 Test #3: Test2 ............................ Passed +[0-9.]+ sec
+Start 4: Test11
4/4 Test #4: Test11 ........................... Passed +[0-9.]+ sec
+
100% tests passed, 0 tests failed out of 4

View File

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

View File

@@ -0,0 +1 @@
^No tests were found!!!$