summaryrefslogtreecommitdiffstats
path: root/Source/CTest
diff options
context:
space:
mode:
authorAlex Neundorf <neundorf@kde.org>2023-11-29 21:51:00 (GMT)
committerBrad King <brad.king@kitware.com>2024-01-25 17:37:16 (GMT)
commit022f20f6632c934169f440271cabe8c7e52cce6e (patch)
tree3bd6022853103fede5e82a0b15089327fbfa4b80 /Source/CTest
parent5d1e689e6814283f3920cbb963fe22393e790eae (diff)
downloadCMake-022f20f6632c934169f440271cabe8c7e52cce6e.zip
CMake-022f20f6632c934169f440271cabe8c7e52cce6e.tar.gz
CMake-022f20f6632c934169f440271cabe8c7e52cce6e.tar.bz2
ctest: add command line option to run the tests listed in a given file
Add `--tests-from-file <filename>` to run only the tests listed in the given file. The test names must match exactly, no regexps or something. The listed tests can still be filtered with a regexp using -R. Issue: #25455
Diffstat (limited to 'Source/CTest')
-rw-r--r--Source/CTest/cmCTestTestHandler.cxx41
-rw-r--r--Source/CTest/cmCTestTestHandler.h3
2 files changed, 44 insertions, 0 deletions
diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx
index 1918b2c..3754ec2 100644
--- a/Source/CTest/cmCTestTestHandler.cxx
+++ b/Source/CTest/cmCTestTestHandler.cxx
@@ -345,6 +345,7 @@ void cmCTestTestHandler::Initialize()
this->ExcludeFixtureRegExp.clear();
this->ExcludeFixtureSetupRegExp.clear();
this->ExcludeFixtureCleanupRegExp.clear();
+ this->TestListFile.clear();
this->TestsToRunString.clear();
this->UseUnion = false;
@@ -585,6 +586,10 @@ bool cmCTestTestHandler::ProcessOptions()
if (val) {
this->ResourceSpecFile = *val;
}
+ val = this->GetOption("TestListFile");
+ if (val) {
+ this->TestListFile = val;
+ }
this->SetRerunFailed(cmIsOn(this->GetOption("RerunFailed")));
return true;
@@ -933,6 +938,14 @@ bool cmCTestTestHandler::ComputeTestList()
continue;
}
}
+
+ if (!this->TestsToRunByName.empty()) {
+ if (this->TestsToRunByName.find(tp.Name) ==
+ this->TestsToRunByName.end()) {
+ continue;
+ }
+ }
+
tp.Index = cnt; // save the index into the test list for this test
finalList.push_back(tp);
}
@@ -1818,6 +1831,11 @@ bool cmCTestTestHandler::GetListOfTests()
if (this->ResourceSpecFile.empty() && specFile) {
this->ResourceSpecFile = *specFile;
}
+
+ if (!this->TestListFile.empty()) {
+ this->ReadTestListFile(this->TestListFile);
+ }
+
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Done constructing a list of tests" << std::endl,
this->Quiet);
@@ -1986,6 +2004,29 @@ void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed()
}
}
+void cmCTestTestHandler::ReadTestListFile(const std::string& testListFileName)
+{
+ 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;
+ }
+
+ this->TestsToRunByName.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);
+ }
+}
+
void cmCTestTestHandler::RecordCustomTestMeasurements(cmXMLWriter& xml,
std::string content)
{
diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h
index b81fcd5..c03bed8 100644
--- a/Source/CTest/cmCTestTestHandler.h
+++ b/Source/CTest/cmCTestTestHandler.h
@@ -341,6 +341,7 @@ private:
std::string GetTestStatus(cmCTestTestResult const&);
void ExpandTestsToRunInformation(size_t numPossibleTests);
void ExpandTestsToRunInformationForRerunFailed();
+ void ReadTestListFile(const std::string& testListFileName);
std::vector<std::string> CustomPreTest;
std::vector<std::string> CustomPostTest;
@@ -359,6 +360,8 @@ private:
std::vector<cmsys::RegularExpression> ExcludeLabelRegularExpressions;
cmsys::RegularExpression IncludeTestsRegularExpression;
cmsys::RegularExpression ExcludeTestsRegularExpression;
+ std::string TestListFile;
+ std::set<std::string> TestsToRunByName;
std::string ResourceSpecFile;