diff options
author | Brad King <brad.king@kitware.com> | 2024-03-08 21:05:34 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2024-03-08 21:06:35 (GMT) |
commit | d52c66bfb3ec6bbf79fab9ef6ff4cdc9ba27a45b (patch) | |
tree | ec5273dca8b998b89757b7c52275f0e0580e7caf /Source/CTest | |
parent | 8673264e25b4abfb3b328131d983e7668a8c5e1a (diff) | |
download | CMake-d52c66bfb3ec6bbf79fab9ef6ff4cdc9ba27a45b.zip CMake-d52c66bfb3ec6bbf79fab9ef6ff4cdc9ba27a45b.tar.gz CMake-d52c66bfb3ec6bbf79fab9ef6ff4cdc9ba27a45b.tar.bz2 |
ctest: Honor tests-from-file options with empty input
If the `--tests-from-file` input file is empty, no tests should run.
Diffstat (limited to 'Source/CTest')
-rw-r--r-- | Source/CTest/cmCTestTestHandler.cxx | 38 | ||||
-rw-r--r-- | Source/CTest/cmCTestTestHandler.h | 8 |
2 files changed, 24 insertions, 22 deletions
diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index ebb5073..63ff8d1 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -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, diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h index e9c964b..6932800 100644 --- a/Source/CTest/cmCTestTestHandler.h +++ b/Source/CTest/cmCTestTestHandler.h @@ -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; |