cmake/Source/cmSetTestsPropertiesCommand.cxx

51 lines
1.5 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmSetTestsPropertiesCommand.h"
2020-08-30 11:54:41 +02:00
#include <algorithm>
2017-04-14 19:02:05 +02:00
#include <iterator>
2020-02-01 23:06:01 +01:00
#include "cmExecutionStatus.h"
2017-04-14 19:02:05 +02:00
#include "cmMakefile.h"
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
#include "cmTest.h"
2017-04-14 19:02:05 +02:00
2020-02-01 23:06:01 +01:00
bool cmSetTestsPropertiesCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
2016-10-30 18:24:19 +01:00
if (args.empty()) {
2020-02-01 23:06:01 +01:00
status.SetError("called with incorrect number of arguments");
return false;
2016-07-09 11:21:54 +02:00
}
2020-08-30 11:54:41 +02:00
// first identify the properties arguments
auto propsIter = std::find(args.begin(), args.end(), "PROPERTIES");
if (propsIter == args.end() || propsIter + 1 == args.end()) {
status.SetError("called with illegal arguments, maybe missing a "
"PROPERTIES specifier?");
return false;
2016-07-09 11:21:54 +02:00
}
2020-08-30 11:54:41 +02:00
if (std::distance(propsIter, args.end()) % 2 != 1) {
status.SetError("called with incorrect number of arguments.");
return false;
2016-07-09 11:21:54 +02:00
}
2020-08-30 11:54:41 +02:00
// loop over all the tests
for (const std::string& tname : cmStringRange{ args.begin(), propsIter }) {
if (cmTest* test = status.GetMakefile().GetTest(tname)) {
// loop through all the props and set them
for (auto k = propsIter + 1; k != args.end(); k += 2) {
if (!k->empty()) {
2021-11-20 13:41:27 +01:00
test->SetProperty(*k, *(k + 1));
2020-08-30 11:54:41 +02:00
}
}
2020-08-30 11:54:41 +02:00
} else {
status.SetError(
cmStrCat("Can not find test to add properties to: ", tname));
return false;
}
2016-07-09 11:21:54 +02:00
}
return true;
}