cmCTestTestHandler: Consolidate File options into cmCTestTestOptions

This commit is contained in:
Daniel Pfeifer
2024-10-24 22:01:12 +02:00
parent f7181175ad
commit b43d3dcfba
4 changed files with 30 additions and 55 deletions

View File

@@ -84,10 +84,10 @@ cmCTestGenericHandler* cmCTestTestCommand::InitializeHandler()
}
if (!this->ExcludeTestsFromFile.empty()) {
handler->SetOption("ExcludeTestListFile", this->ExcludeTestsFromFile);
handler->TestOptions.ExcludeTestListFile = this->ExcludeTestsFromFile;
}
if (!this->IncludeTestsFromFile.empty()) {
handler->SetOption("TestListFile", this->IncludeTestsFromFile);
handler->TestOptions.TestListFile = this->IncludeTestsFromFile;
}
if (!this->ExcludeFixture.empty()) {
@@ -115,7 +115,7 @@ cmCTestGenericHandler* cmCTestTestCommand::InitializeHandler()
handler->SetOption("ScheduleRandom", this->ScheduleRandom);
}
if (!this->ResourceSpecFile.empty()) {
handler->SetOption("ResourceSpecFile", this->ResourceSpecFile);
handler->TestOptions.ResourceSpecFile = this->ResourceSpecFile;
}
if (!this->StopTime.empty()) {
this->CTest->SetStopTime(this->StopTime);

View File

@@ -286,9 +286,6 @@ cmCTestTestHandler::cmCTestTestHandler()
this->LogFile = nullptr;
// Support for JUnit XML output.
this->JUnitXMLFileName = "";
// Regular expressions to scan test output for custom measurements.
// Capture the whole section of test output from the first opening
@@ -332,8 +329,6 @@ void cmCTestTestHandler::Initialize(cmCTest* ctest)
this->UseExcludeRegExpFirst = false;
this->IncludeLabelRegularExpressions.clear();
this->ExcludeLabelRegularExpressions.clear();
this->TestListFile.clear();
this->ExcludeTestListFile.clear();
this->TestsToRunByName.reset();
this->TestsToExcludeByName.reset();
@@ -578,18 +573,6 @@ bool cmCTestTestHandler::ProcessOptions()
if (!this->TestOptions.ExcludeRegularExpression.empty()) {
this->UseExcludeRegExp();
}
cmValue val = this->GetOption("ResourceSpecFile");
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(this->GetOption("RerunFailed").IsOn());
return true;
@@ -1414,7 +1397,7 @@ bool cmCTestTestHandler::ProcessDirectory(std::vector<std::string>& passed,
tests[p.Index].Depends = depends;
properties[p.Index] = &p;
}
parallel->SetResourceSpecFile(this->ResourceSpecFile);
parallel->SetResourceSpecFile(this->TestOptions.ResourceSpecFile);
if (!parallel->SetTests(std::move(tests), std::move(properties))) {
return false;
}
@@ -1849,19 +1832,20 @@ bool cmCTestTestHandler::GetListOfTests()
return false;
}
cmValue specFile = mf.GetDefinition("CTEST_RESOURCE_SPEC_FILE");
if (this->ResourceSpecFile.empty() && specFile) {
this->ResourceSpecFile = *specFile;
if (this->TestOptions.ResourceSpecFile.empty() && specFile) {
this->TestOptions.ResourceSpecFile = *specFile;
}
if (!this->TestListFile.empty()) {
this->TestsToRunByName = this->ReadTestListFile(this->TestListFile);
if (!this->TestOptions.TestListFile.empty()) {
this->TestsToRunByName =
this->ReadTestListFile(this->TestOptions.TestListFile);
if (!this->TestsToRunByName) {
return false;
}
}
if (!this->ExcludeTestListFile.empty()) {
if (!this->TestOptions.ExcludeTestListFile.empty()) {
this->TestsToExcludeByName =
this->ReadTestListFile(this->ExcludeTestListFile);
this->ReadTestListFile(this->TestOptions.ExcludeTestListFile);
if (!this->TestsToExcludeByName) {
return false;
}
@@ -2548,22 +2532,22 @@ bool cmCTestTestHandler::cmCTestTestResourceRequirement::operator!=(
void cmCTestTestHandler::SetJUnitXMLFileName(const std::string& filename)
{
this->JUnitXMLFileName = filename;
this->TestOptions.JUnitXMLFileName = filename;
}
bool cmCTestTestHandler::WriteJUnitXML()
{
if (this->JUnitXMLFileName.empty()) {
if (this->TestOptions.JUnitXMLFileName.empty()) {
return true;
}
// Open new XML file for writing.
cmGeneratedFileStream xmlfile;
xmlfile.SetTempExt("tmp");
xmlfile.Open(this->JUnitXMLFileName);
xmlfile.Open(this->TestOptions.JUnitXMLFileName);
if (!xmlfile) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Problem opening file: " << this->JUnitXMLFileName
"Problem opening file: " << this->TestOptions.JUnitXMLFileName
<< std::endl);
return false;
}

View File

@@ -45,6 +45,11 @@ struct cmCTestTestOptions
std::string ExcludeFixtureRegularExpression;
std::string ExcludeFixtureSetupRegularExpression;
std::string ExcludeFixtureCleanupRegularExpression;
std::string TestListFile;
std::string ExcludeTestListFile;
std::string ResourceSpecFile;
std::string JUnitXMLFileName;
};
/** \class cmCTestTestHandler
@@ -365,13 +370,9 @@ private:
std::vector<cmsys::RegularExpression> ExcludeLabelRegularExpressions;
cmsys::RegularExpression IncludeTestsRegularExpression;
cmsys::RegularExpression ExcludeTestsRegularExpression;
std::string TestListFile;
std::string ExcludeTestListFile;
cm::optional<std::set<std::string>> TestsToRunByName;
cm::optional<std::set<std::string>> TestsToExcludeByName;
std::string ResourceSpecFile;
void RecordCustomTestMeasurements(cmXMLWriter& xml, std::string content);
void CheckLabelFilter(cmCTestTestProperties& it);
void CheckLabelFilterExclude(cmCTestTestProperties& it);
@@ -392,7 +393,5 @@ private:
int RepeatCount = 1;
bool RerunFailed;
std::string JUnitXMLFileName;
friend class cmCTestTestCommand;
};

View File

@@ -1856,8 +1856,8 @@ bool cmCTest::SetArgsFromPreset(const std::string& presetName,
this->Impl->ParallelLevelSetInCli = true;
}
this->SetPersistentOptionIfNotEmpty(
expandedPreset->Execution->ResourceSpecFile, "ResourceSpecFile");
this->Impl->TestOptions.ResourceSpecFile =
expandedPreset->Execution->ResourceSpecFile;
if (expandedPreset->Execution->TestLoad) {
auto testLoad = *expandedPreset->Execution->TestLoad;
@@ -2600,25 +2600,17 @@ int cmCTest::Run(std::vector<std::string> const& args)
dashFC },
CommandArgument{ "--resource-spec-file", CommandArgument::Values::One,
[this](std::string const& file) -> bool {
this->Impl->TestHandler.SetPersistentOption(
"ResourceSpecFile", file);
this->Impl->MemCheckHandler.SetPersistentOption(
"ResourceSpecFile", file);
this->Impl->TestOptions.ResourceSpecFile = file;
return true;
} },
CommandArgument{ "--tests-from-file", CommandArgument::Values::One,
[this](std::string const& file) -> bool {
this->Impl->TestOptions.TestListFile = file;
return true;
} },
CommandArgument{
"--tests-from-file", CommandArgument::Values::One,
[this](std::string const& file) -> bool {
this->Impl->TestHandler.SetPersistentOption("TestListFile", file);
this->Impl->MemCheckHandler.SetPersistentOption("TestListFile", file);
return true;
} },
CommandArgument{ "--exclude-from-file", CommandArgument::Values::One,
[this](std::string const& file) -> bool {
this->Impl->TestHandler.SetPersistentOption(
"ExcludeTestListFile", file);
this->Impl->MemCheckHandler.SetPersistentOption(
"ExcludeTestListFile", file);
this->Impl->TestOptions.ExcludeTestListFile = file;
return true;
} },
CommandArgument{ "--schedule-random", CommandArgument::Values::Zero,
@@ -3511,7 +3503,7 @@ void cmCTest::SetOutputLogFileName(const std::string& name)
void cmCTest::SetOutputJUnitFileName(const std::string& name)
{
this->Impl->TestHandler.SetJUnitXMLFileName(name);
this->Impl->TestOptions.JUnitXMLFileName = name;
// Turn test output compression off.
// This makes it easier to include test output in the resulting
// JUnit XML report.