summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--Help/manual/ctest.1.rst12
-rw-r--r--Help/release/dev/ctest-tests-from-file.rst5
-rw-r--r--Source/CTest/cmCTestTestHandler.cxx41
-rw-r--r--Source/CTest/cmCTestTestHandler.h3
-rw-r--r--Source/cmCTest.cxx7
-rw-r--r--Source/ctest.cxx1
-rw-r--r--Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake17
-rw-r--r--Tests/RunCMake/CTestCommandLine/TestsFromFile-TestList.txt2
-rw-r--r--Tests/RunCMake/CTestCommandLine/TestsFromFile-tests-from-file-stdout.txt5
9 files changed, 93 insertions, 0 deletions
diff --git a/Help/manual/ctest.1.rst b/Help/manual/ctest.1.rst
index 1924d4f..1174725 100644
--- a/Help/manual/ctest.1.rst
+++ b/Help/manual/ctest.1.rst
@@ -234,6 +234,18 @@ Run Tests
of the test's labels (i.e. the multiple ``-LE`` labels form an ``AND``
relationship). See `Label Matching`_.
+.. option:: --tests-from-file <filename>
+
+ .. versionadded:: 3.29
+
+ Run tests listed in the given file.
+
+ This option tells CTest to run the tests which are listed in the given
+ file. The file must contain one exact test name per line.
+ Lines can be commented out using a ``#``.
+ This option can be combined with the other options like
+ ``-R``, ``-E``, ``-L`` or ``-LE``.
+
.. option:: -FA <regex>, --fixture-exclude-any <regex>
Exclude fixtures matching ``<regex>`` from automatically adding any tests to
diff --git a/Help/release/dev/ctest-tests-from-file.rst b/Help/release/dev/ctest-tests-from-file.rst
new file mode 100644
index 0000000..f0abda9
--- /dev/null
+++ b/Help/release/dev/ctest-tests-from-file.rst
@@ -0,0 +1,5 @@
+ctest-tests-from-file
+---------------------
+
+* :manual:`ctest(1)` gained the :option:`--tests-from-file <ctest
+ --tests-from-file>` option to run tests named in a file.
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;
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx
index 6e684a3..a333c44 100644
--- a/Source/cmCTest.cxx
+++ b/Source/cmCTest.cxx
@@ -2224,6 +2224,13 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
args[i]);
}
+ else if (this->CheckArgument(arg, "--tests-from-file"_s) &&
+ i < args.size() - 1) {
+ i++;
+ this->GetTestHandler()->SetPersistentOption("TestListFile", args[i]);
+ this->GetMemCheckHandler()->SetPersistentOption("TestListFile", args[i]);
+ }
+
else if (this->CheckArgument(arg, "--rerun-failed"_s)) {
this->GetTestHandler()->SetPersistentOption("RerunFailed", "true");
this->GetMemCheckHandler()->SetPersistentOption("RerunFailed", "true");
diff --git a/Source/ctest.cxx b/Source/ctest.cxx
index b2867e2..fbd90cd 100644
--- a/Source/ctest.cxx
+++ b/Source/ctest.cxx
@@ -107,6 +107,7 @@ const cmDocumentationEntry cmDocumentationOptions[] = {
"Run a specific number of tests by number." },
{ "-U, --union", "Take the Union of -I and -R" },
{ "--rerun-failed", "Run only the tests that failed previously" },
+ { "--tests-from-file <file>", "Run the tests listed in the given file" },
{ "--repeat until-fail:<n>, --repeat-until-fail <n>",
"Require each test to run <n> times without failing in order to pass" },
{ "--repeat until-pass:<n>",
diff --git a/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake
index 1b8d0d9..96bef92 100644
--- a/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake
@@ -207,6 +207,23 @@ set_tests_properties(test1 PROPERTIES SKIP_REGULAR_EXPRESSION \"test1\")
endfunction()
run_SkipRegexFoundTest()
+
+function(run_TestsFromFileTest arg)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/TestsFromFile)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+
+ file(WRITE "${RunCMake_TEST_BINARY_DIR}/CTestTestfile.cmake" "
+add_test(Test1 \"${CMAKE_COMMAND}\" -E echo \"test1\")
+add_test(Test2 \"${CMAKE_COMMAND}\" -E echo \"test2\")
+add_test(Test11 \"${CMAKE_COMMAND}\" -E echo \"test11\")
+")
+ run_cmake_command(TestsFromFile-${arg} ${CMAKE_CTEST_COMMAND} --${arg} ${RunCMake_SOURCE_DIR}/TestsFromFile-TestList.txt )
+endfunction()
+run_TestsFromFileTest(tests-from-file)
+
+
function(run_SerialFailed)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/SerialFailed)
set(RunCMake_TEST_NO_CLEAN 1)
diff --git a/Tests/RunCMake/CTestCommandLine/TestsFromFile-TestList.txt b/Tests/RunCMake/CTestCommandLine/TestsFromFile-TestList.txt
new file mode 100644
index 0000000..91f6504
--- /dev/null
+++ b/Tests/RunCMake/CTestCommandLine/TestsFromFile-TestList.txt
@@ -0,0 +1,2 @@
+Test1
+# Test11
diff --git a/Tests/RunCMake/CTestCommandLine/TestsFromFile-tests-from-file-stdout.txt b/Tests/RunCMake/CTestCommandLine/TestsFromFile-tests-from-file-stdout.txt
new file mode 100644
index 0000000..653d56c
--- /dev/null
+++ b/Tests/RunCMake/CTestCommandLine/TestsFromFile-tests-from-file-stdout.txt
@@ -0,0 +1,5 @@
+ +Start 1: Test1
+1/1 Test #1: Test1 ............................ Passed +[0-9.]+ sec
++
+100% tests passed, 0 tests failed out of 1
++