Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmSetTestsPropertiesCommand.cxx
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst or https://cmake.org/licensing for details.  */
3
#include "cmSetTestsPropertiesCommand.h"
4
5
#include <algorithm>
6
#include <iterator>
7
8
#include <cmext/string_view>
9
10
#include "cmArgumentParser.h"
11
#include "cmExecutionStatus.h"
12
#include "cmGlobalGenerator.h"
13
#include "cmMakefile.h"
14
#include "cmStringAlgorithms.h"
15
#include "cmSystemTools.h"
16
#include "cmTest.h"
17
18
bool cmSetTestsPropertiesCommand(std::vector<std::string> const& args,
19
                                 cmExecutionStatus& status)
20
0
{
21
0
  if (args.empty()) {
22
0
    status.SetError("called with incorrect number of arguments");
23
0
    return false;
24
0
  }
25
26
  // first identify the properties arguments
27
0
  auto propsIter = std::find(args.begin(), args.end(), "PROPERTIES");
28
0
  if (propsIter == args.end() || propsIter + 1 == args.end()) {
29
0
    status.SetError("called with illegal arguments, maybe missing a "
30
0
                    "PROPERTIES specifier?");
31
0
    return false;
32
0
  }
33
34
0
  if (std::distance(propsIter, args.end()) % 2 != 1) {
35
0
    status.SetError("called with incorrect number of arguments.");
36
0
    return false;
37
0
  }
38
39
0
  std::vector<std::string> tests;
40
0
  std::string directory;
41
0
  cmArgumentParser<void> parser;
42
0
  parser.Bind("DIRECTORY"_s, directory);
43
0
  auto result = parser.Parse(cmStringRange{ args.begin(), propsIter }, &tests);
44
45
0
  cmMakefile* mf = &status.GetMakefile();
46
0
  if (result.MaybeReportError(*mf)) {
47
0
    return false;
48
0
  }
49
0
  if (!directory.empty()) {
50
0
    std::string absDirectory = cmSystemTools::CollapseFullPath(
51
0
      directory, mf->GetCurrentSourceDirectory());
52
0
    mf = mf->GetGlobalGenerator()->FindMakefile(absDirectory);
53
0
    if (!mf) {
54
0
      status.SetError(cmStrCat("given non-existent DIRECTORY ", directory));
55
0
      return false;
56
0
    }
57
0
  }
58
59
  // loop over all the tests
60
0
  for (std::string const& tname : tests) {
61
0
    if (cmTest* test = mf->GetTest(tname)) {
62
      // loop through all the props and set them
63
0
      for (auto k = propsIter + 1; k != args.end(); k += 2) {
64
0
        if (!k->empty()) {
65
0
          test->SetProperty(*k, *(k + 1));
66
0
        }
67
0
      }
68
0
    } else {
69
0
      status.SetError(
70
0
        cmStrCat("Can not find test to add properties to: ", tname));
71
0
      return false;
72
0
    }
73
0
  }
74
0
  return true;
75
0
}