cmCTestTestHandler: Consolidate simple options into cmCTestTestOptions

This commit is contained in:
Daniel Pfeifer
2024-10-24 22:18:02 +02:00
parent b43d3dcfba
commit 70dfb24957
4 changed files with 28 additions and 47 deletions

View File

@@ -103,16 +103,16 @@ cmCTestGenericHandler* cmCTestTestCommand::InitializeHandler()
this->ExcludeFixtureCleanup;
}
if (this->StopOnFailure) {
handler->SetOption("StopOnFailure", "ON");
handler->TestOptions.StopOnFailure = true;
}
if (this->ParallelLevel) {
handler->SetOption("ParallelLevel", *this->ParallelLevel);
handler->ParallelLevel = *this->ParallelLevel;
}
if (!this->Repeat.empty()) {
handler->SetOption("Repeat", this->Repeat);
handler->Repeat = this->Repeat;
}
if (!this->ScheduleRandom.empty()) {
handler->SetOption("ScheduleRandom", this->ScheduleRandom);
handler->TestOptions.ScheduleRandom = cmValue(this->ScheduleRandom).IsOn();
}
if (!this->ResourceSpecFile.empty()) {
handler->TestOptions.ResourceSpecFile = this->ResourceSpecFile;

View File

@@ -276,8 +276,6 @@ inline int GetNextRealNumber(std::string const& in, double& val,
cmCTestTestHandler::cmCTestTestHandler()
{
this->UseUnion = false;
this->UseIncludeRegExpFlag = false;
this->UseExcludeRegExpFlag = false;
this->UseExcludeRegExpFirst = false;
@@ -333,7 +331,6 @@ void cmCTestTestHandler::Initialize(cmCTest* ctest)
this->TestsToExcludeByName.reset();
this->TestsToRunString.clear();
this->UseUnion = false;
this->TestList.clear();
}
@@ -514,11 +511,10 @@ bool cmCTestTestHandler::ProcessOptions()
{
// Update internal data structure from generic one
this->SetTestsToRunInformation(this->TestOptions.TestsToRunInformation);
this->SetUseUnion(this->GetOption("UseUnion").IsOn());
if (this->GetOption("ScheduleRandom").IsOn()) {
if (this->TestOptions.ScheduleRandom) {
this->CTest->SetScheduleType("Random");
}
if (cmValue repeat = this->GetOption("Repeat")) {
if (auto repeat = this->Repeat) {
cmsys::RegularExpression repeatRegex(
"^(UNTIL_FAIL|UNTIL_PASS|AFTER_TIMEOUT):([0-9]+)$");
if (repeatRegex.find(*repeat)) {
@@ -542,8 +538,8 @@ bool cmCTestTestHandler::ProcessOptions()
return false;
}
}
if (cmValue parallelLevel = this->GetOption("ParallelLevel")) {
if (parallelLevel.IsEmpty()) {
if (auto parallelLevel = this->ParallelLevel) {
if (parallelLevel->empty()) {
// An empty value tells ctest to choose a default.
this->CTest->SetParallelLevel(cm::nullopt);
} else {
@@ -559,7 +555,7 @@ bool cmCTestTestHandler::ProcessOptions()
}
}
if (this->GetOption("StopOnFailure")) {
if (this->TestOptions.StopOnFailure) {
this->CTest->SetStopOnFailure(true);
}
@@ -573,8 +569,6 @@ bool cmCTestTestHandler::ProcessOptions()
if (!this->TestOptions.ExcludeRegularExpression.empty()) {
this->UseExcludeRegExp();
}
this->SetRerunFailed(this->GetOption("RerunFailed").IsOn());
return true;
}
@@ -886,7 +880,7 @@ bool cmCTestTestHandler::ComputeTestList()
return false;
}
if (this->RerunFailed) {
if (this->TestOptions.RerunFailed) {
return this->ComputeTestListForRerunFailed();
}
@@ -900,7 +894,7 @@ bool cmCTestTestHandler::ComputeTestList()
}
}
// expand the test list based on the union flag
if (this->UseUnion) {
if (this->TestOptions.UseUnion) {
this->ExpandTestsToRunInformation(static_cast<int>(tmsize));
} else {
this->ExpandTestsToRunInformation(inREcnt);
@@ -915,7 +909,7 @@ bool cmCTestTestHandler::ComputeTestList()
inREcnt++;
}
if (this->UseUnion) {
if (this->TestOptions.UseUnion) {
// if it is not in the list and not in the regexp then skip
if ((!this->TestsToRun.empty() &&
!cm::contains(this->TestsToRun, cnt)) &&

View File

@@ -30,6 +30,11 @@ class cmXMLWriter;
struct cmCTestTestOptions
{
bool RerunFailed = false;
bool ScheduleRandom = false;
bool StopOnFailure = false;
bool UseUnion = false;
int OutputSizePassed = 1 * 1024;
int OutputSizeFailed = 300 * 1024;
cmCTestTypes::TruncationMode OutputTruncation =
@@ -70,19 +75,6 @@ public:
*/
int ProcessHandler() override;
/**
* When both -R and -I are used should the resulting test list be the
* intersection or the union of the lists. By default it is the
* intersection.
*/
void SetUseUnion(bool val) { this->UseUnion = val; }
/**
* Set whether or not CTest should only execute the tests that failed
* on the previous run. By default this is false.
*/
void SetRerunFailed(bool val) { this->RerunFailed = val; }
/**
* This method is called when reading CTest custom file
*/
@@ -372,6 +364,8 @@ private:
cmsys::RegularExpression ExcludeTestsRegularExpression;
cm::optional<std::set<std::string>> TestsToRunByName;
cm::optional<std::set<std::string>> TestsToExcludeByName;
cm::optional<std::string> ParallelLevel;
cm::optional<std::string> Repeat;
void RecordCustomTestMeasurements(cmXMLWriter& xml, std::string content);
void CheckLabelFilter(cmCTestTestProperties& it);
@@ -379,7 +373,6 @@ private:
void CheckLabelFilterInclude(cmCTestTestProperties& it);
std::string TestsToRunString;
bool UseUnion;
ListOfTests TestList;
size_t TotalNumberOfTests;
cmsys::RegularExpression AllTestMeasurementsRegex;
@@ -391,7 +384,6 @@ private:
cmCTest::Repeat RepeatMode = cmCTest::Repeat::Never;
int RepeatCount = 1;
bool RerunFailed;
friend class cmCTestTestCommand;
};

View File

@@ -1819,10 +1819,8 @@ bool cmCTest::SetArgsFromPreset(const std::string& presetName,
}
}
if (expandedPreset->Filter->Include->UseUnion.value_or(false)) {
this->GetTestHandler()->SetPersistentOption("UseUnion", "true");
this->GetMemCheckHandler()->SetPersistentOption("UseUnion", "true");
}
this->Impl->TestOptions.UseUnion =
expandedPreset->Filter->Include->UseUnion.value_or(false);
}
if (expandedPreset->Filter->Exclude) {
@@ -2132,8 +2130,7 @@ int cmCTest::Run(std::vector<std::string> const& args)
return true;
};
auto const dashU = [this](std::string const&) -> bool {
this->Impl->TestHandler.SetPersistentOption("UseUnion", "true");
this->Impl->MemCheckHandler.SetPersistentOption("UseUnion", "true");
this->Impl->TestOptions.UseUnion = true;
return true;
};
auto const dashR = [this](std::string const& expr) -> bool {
@@ -2615,16 +2612,14 @@ int cmCTest::Run(std::vector<std::string> const& args)
} },
CommandArgument{ "--schedule-random", CommandArgument::Values::Zero,
[this](std::string const&) -> bool {
this->Impl->ScheduleType = "Random";
this->Impl->TestOptions.ScheduleRandom = true;
return true;
} },
CommandArgument{ "--rerun-failed", CommandArgument::Values::Zero,
[this](std::string const&) -> bool {
this->Impl->TestOptions.RerunFailed = true;
return true;
} },
CommandArgument{
"--rerun-failed", CommandArgument::Values::Zero,
[this](std::string const&) -> bool {
this->Impl->TestHandler.SetPersistentOption("RerunFailed", "true");
this->Impl->MemCheckHandler.SetPersistentOption("RerunFailed", "true");
return true;
} },
};
// process the command line arguments