cmCTestTestHandler: Consolidate RegExp options into cmCTestTestOptions

This commit is contained in:
Daniel Pfeifer
2024-10-24 21:40:38 +02:00
parent 86225833f2
commit f7181175ad
4 changed files with 84 additions and 137 deletions

View File

@@ -6,6 +6,7 @@
#include <cstdlib>
#include <ratio>
#include <sstream>
#include <vector>
#include <cmext/string_view>
@@ -65,22 +66,21 @@ cmCTestGenericHandler* cmCTestTestCommand::InitializeHandler()
cmCTestTestHandler* handler = this->InitializeActualHandler();
if (!this->Start.empty() || !this->End.empty() || !this->Stride.empty()) {
handler->SetOption(
"TestsToRunInformation",
cmStrCat(this->Start, ',', this->End, ',', this->Stride));
handler->TestOptions.TestsToRunInformation =
cmStrCat(this->Start, ',', this->End, ',', this->Stride);
}
if (!this->Exclude.empty()) {
handler->SetOption("ExcludeRegularExpression", this->Exclude);
handler->TestOptions.ExcludeRegularExpression = this->Exclude;
}
if (!this->Include.empty()) {
handler->SetOption("IncludeRegularExpression", this->Include);
handler->TestOptions.IncludeRegularExpression = this->Include;
}
if (!this->ExcludeLabel.empty()) {
handler->AddMultiOption("ExcludeLabelRegularExpression",
this->ExcludeLabel);
handler->TestOptions.ExcludeLabelRegularExpression.push_back(
this->ExcludeLabel);
}
if (!this->IncludeLabel.empty()) {
handler->AddMultiOption("LabelRegularExpression", this->IncludeLabel);
handler->TestOptions.LabelRegularExpression.push_back(this->IncludeLabel);
}
if (!this->ExcludeTestsFromFile.empty()) {
@@ -91,16 +91,16 @@ cmCTestGenericHandler* cmCTestTestCommand::InitializeHandler()
}
if (!this->ExcludeFixture.empty()) {
handler->SetOption("ExcludeFixtureRegularExpression",
this->ExcludeFixture);
handler->TestOptions.ExcludeFixtureRegularExpression =
this->ExcludeFixture;
}
if (!this->ExcludeFixtureSetup.empty()) {
handler->SetOption("ExcludeFixtureSetupRegularExpression",
this->ExcludeFixtureSetup);
handler->TestOptions.ExcludeFixtureSetupRegularExpression =
this->ExcludeFixtureSetup;
}
if (!this->ExcludeFixtureCleanup.empty()) {
handler->SetOption("ExcludeFixtureCleanupRegularExpression",
this->ExcludeFixtureCleanup);
handler->TestOptions.ExcludeFixtureCleanupRegularExpression =
this->ExcludeFixtureCleanup;
}
if (this->StopOnFailure) {
handler->SetOption("StopOnFailure", "ON");

View File

@@ -332,11 +332,6 @@ void cmCTestTestHandler::Initialize(cmCTest* ctest)
this->UseExcludeRegExpFirst = false;
this->IncludeLabelRegularExpressions.clear();
this->ExcludeLabelRegularExpressions.clear();
this->IncludeRegExp.clear();
this->ExcludeRegExp.clear();
this->ExcludeFixtureRegExp.clear();
this->ExcludeFixtureSetupRegExp.clear();
this->ExcludeFixtureCleanupRegExp.clear();
this->TestListFile.clear();
this->ExcludeTestListFile.clear();
this->TestsToRunByName.reset();
@@ -523,7 +518,7 @@ static bool BuildLabelRE(const std::vector<std::string>& parts,
bool cmCTestTestHandler::ProcessOptions()
{
// Update internal data structure from generic one
this->SetTestsToRunInformation(this->GetOption("TestsToRunInformation"));
this->SetTestsToRunInformation(this->TestOptions.TestsToRunInformation);
this->SetUseUnion(this->GetOption("UseUnion").IsOn());
if (this->GetOption("ScheduleRandom").IsOn()) {
this->CTest->SetScheduleType("Random");
@@ -573,33 +568,17 @@ bool cmCTestTestHandler::ProcessOptions()
this->CTest->SetStopOnFailure(true);
}
BuildLabelRE(this->GetMultiOption("LabelRegularExpression"),
BuildLabelRE(this->TestOptions.LabelRegularExpression,
this->IncludeLabelRegularExpressions);
BuildLabelRE(this->GetMultiOption("ExcludeLabelRegularExpression"),
BuildLabelRE(this->TestOptions.ExcludeLabelRegularExpression,
this->ExcludeLabelRegularExpressions);
cmValue val = this->GetOption("IncludeRegularExpression");
if (val) {
if (!this->TestOptions.IncludeRegularExpression.empty()) {
this->UseIncludeRegExp();
this->SetIncludeRegExp(*val);
}
val = this->GetOption("ExcludeRegularExpression");
if (val) {
if (!this->TestOptions.ExcludeRegularExpression.empty()) {
this->UseExcludeRegExp();
this->SetExcludeRegExp(*val);
}
val = this->GetOption("ExcludeFixtureRegularExpression");
if (val) {
this->ExcludeFixtureRegExp = *val;
}
val = this->GetOption("ExcludeFixtureSetupRegularExpression");
if (val) {
this->ExcludeFixtureSetupRegExp = *val;
}
val = this->GetOption("ExcludeFixtureCleanupRegularExpression");
if (val) {
this->ExcludeFixtureCleanupRegExp = *val;
}
val = this->GetOption("ResourceSpecFile");
cmValue val = this->GetOption("ResourceSpecFile");
if (val) {
this->ResourceSpecFile = *val;
}
@@ -1036,22 +1015,24 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const
this->Quiet);
// Prepare regular expression evaluators
std::string setupRegExp(this->ExcludeFixtureRegExp);
std::string cleanupRegExp(this->ExcludeFixtureRegExp);
if (!this->ExcludeFixtureSetupRegExp.empty()) {
std::string setupRegExp(this->TestOptions.ExcludeFixtureRegularExpression);
std::string cleanupRegExp(this->TestOptions.ExcludeFixtureRegularExpression);
if (!this->TestOptions.ExcludeFixtureSetupRegularExpression.empty()) {
if (setupRegExp.empty()) {
setupRegExp = this->ExcludeFixtureSetupRegExp;
setupRegExp = this->TestOptions.ExcludeFixtureSetupRegularExpression;
} else {
setupRegExp.append("(" + setupRegExp + ")|(" +
this->ExcludeFixtureSetupRegExp + ")");
setupRegExp.append(
"(" + setupRegExp + ")|(" +
this->TestOptions.ExcludeFixtureSetupRegularExpression + ")");
}
}
if (!this->ExcludeFixtureCleanupRegExp.empty()) {
if (!this->TestOptions.ExcludeFixtureCleanupRegularExpression.empty()) {
if (cleanupRegExp.empty()) {
cleanupRegExp = this->ExcludeFixtureCleanupRegExp;
cleanupRegExp = this->TestOptions.ExcludeFixtureCleanupRegularExpression;
} else {
cleanupRegExp.append("(" + cleanupRegExp + ")|(" +
this->ExcludeFixtureCleanupRegExp + ")");
cleanupRegExp.append(
"(" + cleanupRegExp + ")|(" +
this->TestOptions.ExcludeFixtureCleanupRegularExpression + ")");
}
}
cmsys::RegularExpression excludeSetupRegex(setupRegExp);
@@ -1812,11 +1793,13 @@ bool cmCTestTestHandler::ParseResourceGroupsProperty(
bool cmCTestTestHandler::GetListOfTests()
{
if (!this->IncludeRegExp.empty()) {
this->IncludeTestsRegularExpression.compile(this->IncludeRegExp);
if (!this->TestOptions.IncludeRegularExpression.empty()) {
this->IncludeTestsRegularExpression.compile(
this->TestOptions.IncludeRegularExpression);
}
if (!this->ExcludeRegExp.empty()) {
this->ExcludeTestsRegularExpression.compile(this->ExcludeRegExp);
if (!this->TestOptions.ExcludeRegularExpression.empty()) {
this->ExcludeTestsRegularExpression.compile(
this->TestOptions.ExcludeRegularExpression);
}
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Constructing a list of tests" << std::endl, this->Quiet);
@@ -2155,27 +2138,14 @@ void cmCTestTestHandler::RecordCustomTestMeasurements(cmXMLWriter& xml,
}
}
void cmCTestTestHandler::SetIncludeRegExp(const std::string& arg)
void cmCTestTestHandler::SetTestsToRunInformation(std::string const& in)
{
this->IncludeRegExp = arg;
}
void cmCTestTestHandler::SetExcludeRegExp(const std::string& arg)
{
this->ExcludeRegExp = arg;
}
void cmCTestTestHandler::SetTestsToRunInformation(cmValue in)
{
if (!in) {
return;
}
this->TestsToRunString = *in;
this->TestsToRunString = in;
// if the argument is a file, then read it and use the contents as the
// string
if (cmSystemTools::FileExists(*in)) {
cmsys::ifstream fin(in->c_str());
unsigned long filelen = cmSystemTools::FileLength(*in);
if (cmSystemTools::FileExists(in)) {
cmsys::ifstream fin(in.c_str());
unsigned long filelen = cmSystemTools::FileLength(in);
auto buff = cm::make_unique<char[]>(filelen + 1);
fin.getline(buff.get(), filelen);
buff[fin.gcount()] = 0;

View File

@@ -24,7 +24,6 @@
#include "cmCTestTypes.h" // IWYU pragma: keep
#include "cmDuration.h"
#include "cmListFileCache.h"
#include "cmValue.h"
class cmMakefile;
class cmXMLWriter;
@@ -35,6 +34,17 @@ struct cmCTestTestOptions
int OutputSizeFailed = 300 * 1024;
cmCTestTypes::TruncationMode OutputTruncation =
cmCTestTypes::TruncationMode::Tail;
std::string TestsToRunInformation;
std::string IncludeRegularExpression;
std::string ExcludeRegularExpression;
std::vector<std::string> LabelRegularExpression;
std::vector<std::string> ExcludeLabelRegularExpression;
std::string ExcludeFixtureRegularExpression;
std::string ExcludeFixtureSetupRegularExpression;
std::string ExcludeFixtureCleanupRegularExpression;
};
/** \class cmCTestTestHandler
@@ -77,14 +87,12 @@ public:
/// them on
void UseIncludeRegExp();
void UseExcludeRegExp();
void SetIncludeRegExp(const std::string&);
void SetExcludeRegExp(const std::string&);
void SetMaxIndex(int n) { this->MaxIndex = n; }
int GetMaxIndex() { return this->MaxIndex; }
//! pass the -I argument down
void SetTestsToRunInformation(cmValue);
void SetTestsToRunInformation(std::string const& in);
cmCTestTestHandler();
@@ -353,11 +361,6 @@ private:
bool UseIncludeRegExpFlag;
bool UseExcludeRegExpFlag;
bool UseExcludeRegExpFirst;
std::string IncludeRegExp;
std::string ExcludeRegExp;
std::string ExcludeFixtureRegExp;
std::string ExcludeFixtureSetupRegExp;
std::string ExcludeFixtureCleanupRegExp;
std::vector<cmsys::RegularExpression> IncludeLabelRegularExpressions;
std::vector<cmsys::RegularExpression> ExcludeLabelRegularExpressions;
cmsys::RegularExpression IncludeTestsRegularExpression;

View File

@@ -1793,10 +1793,12 @@ bool cmCTest::SetArgsFromPreset(const std::string& presetName,
if (expandedPreset->Filter) {
if (expandedPreset->Filter->Include) {
this->SetPersistentOptionIfNotEmpty(
expandedPreset->Filter->Include->Name, "IncludeRegularExpression");
this->AddPersistentMultiOptionIfNotEmpty(
expandedPreset->Filter->Include->Label, "LabelRegularExpression");
this->Impl->TestOptions.IncludeRegularExpression =
expandedPreset->Filter->Include->Name;
if (!expandedPreset->Filter->Include->Label.empty()) {
this->Impl->TestOptions.LabelRegularExpression.push_back(
expandedPreset->Filter->Include->Label);
}
if (expandedPreset->Filter->Include->Index) {
if (expandedPreset->Filter->Include->Index->IndexFile.empty()) {
@@ -1810,12 +1812,10 @@ bool cmCTest::SetArgsFromPreset(const std::string& presetName,
indexOptions +=
cmJoin(expandedPreset->Filter->Include->Index->SpecificTests, ",");
this->SetPersistentOptionIfNotEmpty(indexOptions,
"TestsToRunInformation");
this->Impl->TestOptions.TestsToRunInformation = indexOptions;
} else {
this->SetPersistentOptionIfNotEmpty(
expandedPreset->Filter->Include->Index->IndexFile,
"TestsToRunInformation");
this->Impl->TestOptions.TestsToRunInformation =
expandedPreset->Filter->Include->Index->IndexFile;
}
}
@@ -1826,22 +1826,20 @@ bool cmCTest::SetArgsFromPreset(const std::string& presetName,
}
if (expandedPreset->Filter->Exclude) {
this->SetPersistentOptionIfNotEmpty(
expandedPreset->Filter->Exclude->Name, "ExcludeRegularExpression");
this->AddPersistentMultiOptionIfNotEmpty(
expandedPreset->Filter->Exclude->Label,
"ExcludeLabelRegularExpression");
this->Impl->TestOptions.ExcludeRegularExpression =
expandedPreset->Filter->Exclude->Name;
if (!expandedPreset->Filter->Exclude->Label.empty()) {
this->Impl->TestOptions.ExcludeLabelRegularExpression.push_back(
expandedPreset->Filter->Exclude->Label);
}
if (expandedPreset->Filter->Exclude->Fixtures) {
this->SetPersistentOptionIfNotEmpty(
expandedPreset->Filter->Exclude->Fixtures->Any,
"ExcludeFixtureRegularExpression");
this->SetPersistentOptionIfNotEmpty(
expandedPreset->Filter->Exclude->Fixtures->Setup,
"ExcludeFixtureSetupRegularExpression");
this->SetPersistentOptionIfNotEmpty(
expandedPreset->Filter->Exclude->Fixtures->Cleanup,
"ExcludeFixtureCleanupRegularExpression");
this->Impl->TestOptions.ExcludeFixtureRegularExpression =
expandedPreset->Filter->Exclude->Fixtures->Any;
this->Impl->TestOptions.ExcludeFixtureSetupRegularExpression =
expandedPreset->Filter->Exclude->Fixtures->Setup;
this->Impl->TestOptions.ExcludeFixtureCleanupRegularExpression =
expandedPreset->Filter->Exclude->Fixtures->Cleanup;
}
}
}
@@ -2130,10 +2128,7 @@ int cmCTest::Run(std::vector<std::string> const& args)
return true;
};
auto const dashI = [this](std::string const& tests) -> bool {
this->Impl->TestHandler.SetPersistentOption("TestsToRunInformation",
tests);
this->Impl->MemCheckHandler.SetPersistentOption("TestsToRunInformation",
tests);
this->Impl->TestOptions.TestsToRunInformation = tests;
return true;
};
auto const dashU = [this](std::string const&) -> bool {
@@ -2142,52 +2137,31 @@ int cmCTest::Run(std::vector<std::string> const& args)
return true;
};
auto const dashR = [this](std::string const& expr) -> bool {
this->Impl->TestHandler.SetPersistentOption("IncludeRegularExpression",
expr);
this->Impl->MemCheckHandler.SetPersistentOption("IncludeRegularExpression",
expr);
this->Impl->TestOptions.IncludeRegularExpression = expr;
return true;
};
auto const dashE = [this](std::string const& expr) -> bool {
this->Impl->TestHandler.SetPersistentOption("ExcludeRegularExpression",
expr);
this->Impl->MemCheckHandler.SetPersistentOption("ExcludeRegularExpression",
expr);
this->Impl->TestOptions.ExcludeRegularExpression = expr;
return true;
};
auto const dashL = [this](std::string const& expr) -> bool {
this->Impl->TestHandler.AddPersistentMultiOption("LabelRegularExpression",
expr);
this->Impl->MemCheckHandler.AddPersistentMultiOption(
"LabelRegularExpression", expr);
this->Impl->TestOptions.LabelRegularExpression.push_back(expr);
return true;
};
auto const dashLE = [this](std::string const& expr) -> bool {
this->Impl->TestHandler.AddPersistentMultiOption(
"ExcludeLabelRegularExpression", expr);
this->Impl->MemCheckHandler.AddPersistentMultiOption(
"ExcludeLabelRegularExpression", expr);
this->Impl->TestOptions.ExcludeLabelRegularExpression.push_back(expr);
return true;
};
auto const dashFA = [this](std::string const& expr) -> bool {
this->Impl->TestHandler.SetPersistentOption(
"ExcludeFixtureRegularExpression", expr);
this->Impl->MemCheckHandler.SetPersistentOption(
"ExcludeFixtureRegularExpression", expr);
this->Impl->TestOptions.ExcludeFixtureRegularExpression = expr;
return true;
};
auto const dashFS = [this](std::string const& expr) -> bool {
this->Impl->TestHandler.SetPersistentOption(
"ExcludeFixtureSetupRegularExpression", expr);
this->Impl->MemCheckHandler.SetPersistentOption(
"ExcludeFixtureSetupRegularExpression", expr);
this->Impl->TestOptions.ExcludeFixtureSetupRegularExpression = expr;
return true;
};
auto const dashFC = [this](std::string const& expr) -> bool {
this->Impl->TestHandler.SetPersistentOption(
"ExcludeFixtureCleanupRegularExpression", expr);
this->Impl->MemCheckHandler.SetPersistentOption(
"ExcludeFixtureCleanupRegularExpression", expr);
this->Impl->TestOptions.ExcludeFixtureCleanupRegularExpression = expr;
return true;
};