MCPcopy Index your code
hub / github.com/Kitware/CMake / cmAddTestCommand

Function cmAddTestCommand

Source/cmAddTestCommand.cxx:21–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19 std::vector<std::string> const& args, cmExecutionStatus& status);
20
21bool cmAddTestCommand(std::vector<std::string> const& args,
22 cmExecutionStatus& status)
23{
24 if (!args.empty() && args[0] == "NAME") {
25 return cmAddTestCommandHandleNameMode(args, status);
26 }
27
28 // First argument is the name of the test Second argument is the name of
29 // the executable to run (a target or external program) Remaining arguments
30 // are the arguments to pass to the executable
31 if (args.size() < 2) {
32 status.SetError("called with incorrect number of arguments");
33 return false;
34 }
35
36 cmMakefile& mf = status.GetMakefile();
37 cmPolicies::PolicyStatus cmp0178;
38
39 // If the __CMP0178 keyword is present, it is always at the end
40 auto endOfCommandIter =
41 std::find(args.begin() + 2, args.end(), keywordCMP0178);
42 if (endOfCommandIter != args.end()) {
43 auto cmp0178Iter = endOfCommandIter + 1;
44 if (cmp0178Iter == args.end()) {
45 status.SetError(cmStrCat(keywordCMP0178, " keyword missing value"));
46 return false;
47 }
48 if (*cmp0178Iter == "NEW") {
49 cmp0178 = cmPolicies::PolicyStatus::NEW;
50 } else if (*cmp0178Iter == "OLD") {
51 cmp0178 = cmPolicies::PolicyStatus::OLD;
52 } else {
53 cmp0178 = cmPolicies::PolicyStatus::WARN;
54 }
55 } else {
56 cmp0178 = mf.GetPolicyStatus(cmPolicies::CMP0178);
57 }
58
59 // Collect the command with arguments.
60 std::vector<std::string> command(args.begin() + 1, endOfCommandIter);
61
62 // Create the test but add a generator only the first time it is
63 // seen. This preserves behavior from before test generators.
64 cmTest* test = mf.GetTest(args[0]);
65 if (test) {
66 // If the test was already added by a new-style signature do not
67 // allow it to be duplicated.
68 if (!test->GetOldStyle()) {
69 status.SetError(cmStrCat(" given test name \"", args[0],
70 "\" which already exists in this directory."));
71 return false;
72 }
73 } else {
74 test = mf.CreateTest(args[0]);
75 test->SetOldStyle(true);
76 test->SetCMP0178(cmp0178);
77 mf.AddTestGenerator(cm::make_unique<cmTestGenerator>(test));
78 }

Callers

nothing calls this directly

Calls 15

GetOldStyleMethod · 0.80
CreateTestMethod · 0.80
SetOldStyleMethod · 0.80
SetCMP0178Method · 0.80
AddTestGeneratorMethod · 0.80
cmStrCatFunction · 0.70
findFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
SetErrorMethod · 0.45
GetMakefileMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…