diff options
author | Brad King <brad.king@kitware.com> | 2024-01-26 15:14:49 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2024-01-26 15:14:58 (GMT) |
commit | d9b9f630832174c2b6ee31d8a06f6e587ab2dd84 (patch) | |
tree | 2e9096991944408275534306f4d9573e75d4d83e /Source/CTest | |
parent | 409ab01039dd3c8f5ae0df48a1ee1c356132a9bf (diff) | |
parent | 701029726f17759a84b963e2f318742a1761670a (diff) | |
download | CMake-d9b9f630832174c2b6ee31d8a06f6e587ab2dd84.zip CMake-d9b9f630832174c2b6ee31d8a06f6e587ab2dd84.tar.gz CMake-d9b9f630832174c2b6ee31d8a06f6e587ab2dd84.tar.bz2 |
Merge topic 'ctest-tests-from-file'
701029726f ctest_test: add options INCLUDE_FROM_FILE and EXCLUDE_FROM_FILE
dbacc1d5a8 ctest: add command line option to exclude tests listed in a given file
022f20f663 ctest: add command line option to run the tests listed in a given file
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Alex <leha-bot@yandex.ru>
Merge-request: !9128
Diffstat (limited to 'Source/CTest')
-rw-r--r-- | Source/CTest/cmCTestTestCommand.cxx | 10 | ||||
-rw-r--r-- | Source/CTest/cmCTestTestCommand.h | 2 | ||||
-rw-r--r-- | Source/CTest/cmCTestTestHandler.cxx | 62 | ||||
-rw-r--r-- | Source/CTest/cmCTestTestHandler.h | 6 |
4 files changed, 80 insertions, 0 deletions
diff --git a/Source/CTest/cmCTestTestCommand.cxx b/Source/CTest/cmCTestTestCommand.cxx index c717868..ed16354 100644 --- a/Source/CTest/cmCTestTestCommand.cxx +++ b/Source/CTest/cmCTestTestCommand.cxx @@ -26,6 +26,8 @@ void cmCTestTestCommand::BindArguments() this->Bind("INCLUDE"_s, this->Include); this->Bind("EXCLUDE_LABEL"_s, this->ExcludeLabel); this->Bind("INCLUDE_LABEL"_s, this->IncludeLabel); + this->Bind("EXCLUDE_FROM_FILE"_s, this->ExcludeTestsFromFile); + this->Bind("INCLUDE_FROM_FILE"_s, this->IncludeTestsFromFile); this->Bind("EXCLUDE_FIXTURE"_s, this->ExcludeFixture); this->Bind("EXCLUDE_FIXTURE_SETUP"_s, this->ExcludeFixtureSetup); this->Bind("EXCLUDE_FIXTURE_CLEANUP"_s, this->ExcludeFixtureCleanup); @@ -80,6 +82,14 @@ cmCTestGenericHandler* cmCTestTestCommand::InitializeHandler() if (!this->IncludeLabel.empty()) { handler->AddMultiOption("LabelRegularExpression", this->IncludeLabel); } + + if (!this->ExcludeTestsFromFile.empty()) { + handler->SetOption("ExcludeTestListFile", this->ExcludeTestsFromFile); + } + if (!this->IncludeTestsFromFile.empty()) { + handler->SetOption("TestListFile", this->IncludeTestsFromFile); + } + if (!this->ExcludeFixture.empty()) { handler->SetOption("ExcludeFixtureRegularExpression", this->ExcludeFixture); diff --git a/Source/CTest/cmCTestTestCommand.h b/Source/CTest/cmCTestTestCommand.h index 24e74e2..ce054ed 100644 --- a/Source/CTest/cmCTestTestCommand.h +++ b/Source/CTest/cmCTestTestCommand.h @@ -51,6 +51,8 @@ protected: std::string Include; std::string ExcludeLabel; std::string IncludeLabel; + std::string IncludeTestsFromFile; + std::string ExcludeTestsFromFile; std::string ExcludeFixture; std::string ExcludeFixtureSetup; std::string ExcludeFixtureCleanup; diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 1918b2c..dc16f66 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -345,6 +345,8 @@ void cmCTestTestHandler::Initialize() this->ExcludeFixtureRegExp.clear(); this->ExcludeFixtureSetupRegExp.clear(); this->ExcludeFixtureCleanupRegExp.clear(); + this->TestListFile.clear(); + this->ExcludeTestListFile.clear(); this->TestsToRunString.clear(); this->UseUnion = false; @@ -585,6 +587,14 @@ bool cmCTestTestHandler::ProcessOptions() if (val) { this->ResourceSpecFile = *val; } + val = this->GetOption("TestListFile"); + if (val) { + this->TestListFile = val; + } + val = this->GetOption("ExcludeTestListFile"); + if (val) { + this->ExcludeTestListFile = val; + } this->SetRerunFailed(cmIsOn(this->GetOption("RerunFailed"))); return true; @@ -933,6 +943,21 @@ bool cmCTestTestHandler::ComputeTestList() continue; } } + + if (!this->TestsToRunByName.empty()) { + if (this->TestsToRunByName.find(tp.Name) == + this->TestsToRunByName.end()) { + continue; + } + } + + if (!this->TestsToExcludeByName.empty()) { + if (this->TestsToExcludeByName.find(tp.Name) != + this->TestsToExcludeByName.end()) { + continue; + } + } + tp.Index = cnt; // save the index into the test list for this test finalList.push_back(tp); } @@ -1818,6 +1843,15 @@ bool cmCTestTestHandler::GetListOfTests() if (this->ResourceSpecFile.empty() && specFile) { this->ResourceSpecFile = *specFile; } + + if (!this->TestListFile.empty()) { + this->TestsToRunByName = this->ReadTestListFile(this->TestListFile); + } + if (!this->ExcludeTestListFile.empty()) { + this->TestsToExcludeByName = + this->ReadTestListFile(this->ExcludeTestListFile); + } + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Done constructing a list of tests" << std::endl, this->Quiet); @@ -1986,6 +2020,34 @@ void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed() } } +std::set<std::string> cmCTestTestHandler::ReadTestListFile( + const std::string& testListFileName) const +{ + std::set<std::string> testNames; + + cmsys::ifstream ifs(testListFileName.c_str()); + if (ifs) { + std::string line; + while (cmSystemTools::GetLineFromStream(ifs, line)) { + std::string trimmed = cmTrimWhitespace(line); + if (trimmed.empty() || (trimmed[0] == '#')) { + continue; + } + + testNames.insert(trimmed); + } + ifs.close(); + } else if (!this->CTest->GetShowOnly() && + !this->CTest->ShouldPrintLabels()) { + cmCTestLog(this->CTest, ERROR_MESSAGE, + "Problem reading test list file: " + << testListFileName + << " while generating list of tests to run." << std::endl); + } + + return testNames; +} + void cmCTestTestHandler::RecordCustomTestMeasurements(cmXMLWriter& xml, std::string content) { diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h index b81fcd5..84e6098 100644 --- a/Source/CTest/cmCTestTestHandler.h +++ b/Source/CTest/cmCTestTestHandler.h @@ -341,6 +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; std::vector<std::string> CustomPreTest; std::vector<std::string> CustomPostTest; @@ -359,6 +361,10 @@ private: std::vector<cmsys::RegularExpression> ExcludeLabelRegularExpressions; cmsys::RegularExpression IncludeTestsRegularExpression; cmsys::RegularExpression ExcludeTestsRegularExpression; + std::string TestListFile; + std::string ExcludeTestListFile; + std::set<std::string> TestsToRunByName; + std::set<std::string> TestsToExcludeByName; std::string ResourceSpecFile; |