mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
cmCTest: Factor out environment variable handling
This commit is contained in:
+44
-35
@@ -369,6 +369,48 @@ void cmCTest::SetParallelLevel(cm::optional<size_t> level)
|
|||||||
this->Impl->ParallelLevel = level;
|
this->Impl->ParallelLevel = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cmCTest::UpdateStateFromEnvironment()
|
||||||
|
{
|
||||||
|
// handle CTEST_PARALLEL_LEVEL environment variable
|
||||||
|
if (!this->Impl->ParallelLevelSetInCli) {
|
||||||
|
if (cm::optional<std::string> parallelEnv =
|
||||||
|
cmSystemTools::GetEnvVar("CTEST_PARALLEL_LEVEL")) {
|
||||||
|
if (parallelEnv->empty() ||
|
||||||
|
parallelEnv->find_first_not_of(" \t") == std::string::npos) {
|
||||||
|
// An empty value tells ctest to choose a default.
|
||||||
|
this->SetParallelLevel(cm::nullopt);
|
||||||
|
} else {
|
||||||
|
// A non-empty value must be a non-negative integer.
|
||||||
|
// Otherwise, ignore it.
|
||||||
|
unsigned long plevel = 0;
|
||||||
|
if (cmStrToULong(*parallelEnv, &plevel)) {
|
||||||
|
this->SetParallelLevel(plevel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle CTEST_NO_TESTS_ACTION environment variable
|
||||||
|
if (!this->Impl->NoTestsModeSetInCli) {
|
||||||
|
std::string action;
|
||||||
|
if (cmSystemTools::GetEnv("CTEST_NO_TESTS_ACTION", action) &&
|
||||||
|
!action.empty()) {
|
||||||
|
if (action == "error"_s) {
|
||||||
|
this->Impl->NoTestsMode = cmCTest::NoTests::Error;
|
||||||
|
} else if (action == "ignore"_s) {
|
||||||
|
this->Impl->NoTestsMode = cmCTest::NoTests::Ignore;
|
||||||
|
} else {
|
||||||
|
cmCTestLog(this, ERROR_MESSAGE,
|
||||||
|
"Unknown value for CTEST_NO_TESTS_ACTION: '" << action
|
||||||
|
<< '\'');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned long cmCTest::GetTestLoad() const
|
unsigned long cmCTest::GetTestLoad() const
|
||||||
{
|
{
|
||||||
return this->Impl->TestLoad;
|
return this->Impl->TestLoad;
|
||||||
@@ -2596,41 +2638,8 @@ int cmCTest::Run(std::vector<std::string> const& args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle CTEST_PARALLEL_LEVEL environment variable
|
if (!this->UpdateStateFromEnvironment()) {
|
||||||
if (!this->Impl->ParallelLevelSetInCli) {
|
return 1;
|
||||||
if (cm::optional<std::string> parallelEnv =
|
|
||||||
cmSystemTools::GetEnvVar("CTEST_PARALLEL_LEVEL")) {
|
|
||||||
if (parallelEnv->empty() ||
|
|
||||||
parallelEnv->find_first_not_of(" \t") == std::string::npos) {
|
|
||||||
// An empty value tells ctest to choose a default.
|
|
||||||
this->SetParallelLevel(cm::nullopt);
|
|
||||||
} else {
|
|
||||||
// A non-empty value must be a non-negative integer.
|
|
||||||
// Otherwise, ignore it.
|
|
||||||
unsigned long plevel = 0;
|
|
||||||
if (cmStrToULong(*parallelEnv, &plevel)) {
|
|
||||||
this->SetParallelLevel(plevel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle CTEST_NO_TESTS_ACTION environment variable
|
|
||||||
if (!this->Impl->NoTestsModeSetInCli) {
|
|
||||||
std::string action;
|
|
||||||
if (cmSystemTools::GetEnv("CTEST_NO_TESTS_ACTION", action) &&
|
|
||||||
!action.empty()) {
|
|
||||||
if (action == "error"_s) {
|
|
||||||
this->Impl->NoTestsMode = cmCTest::NoTests::Error;
|
|
||||||
} else if (action == "ignore"_s) {
|
|
||||||
this->Impl->NoTestsMode = cmCTest::NoTests::Ignore;
|
|
||||||
} else {
|
|
||||||
cmCTestLog(this, ERROR_MESSAGE,
|
|
||||||
"Unknown value for CTEST_NO_TESTS_ACTION: '" << action
|
|
||||||
<< '\'');
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Passthrough arguments (after --) are only supported in direct test
|
// Passthrough arguments (after --) are only supported in direct test
|
||||||
|
|||||||
@@ -101,6 +101,13 @@ public:
|
|||||||
cm::optional<size_t> GetParallelLevel() const;
|
cm::optional<size_t> GetParallelLevel() const;
|
||||||
void SetParallelLevel(cm::optional<size_t> level);
|
void SetParallelLevel(cm::optional<size_t> level);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check environment variables controlling CTest's behavior and update state
|
||||||
|
* accordingly, when the corresponding command-line toggles are unset.
|
||||||
|
* Returns false if there are errors during parsing.
|
||||||
|
*/
|
||||||
|
bool UpdateStateFromEnvironment();
|
||||||
|
|
||||||
unsigned long GetTestLoad() const;
|
unsigned long GetTestLoad() const;
|
||||||
void SetTestLoad(unsigned long);
|
void SetTestLoad(unsigned long);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user