| 16 | #include "cmTest.h" |
| 17 | |
| 18 | bool cmSetTestsPropertiesCommand(std::vector<std::string> const& args, |
| 19 | cmExecutionStatus& status) |
| 20 | { |
| 21 | if (args.empty()) { |
| 22 | status.SetError("called with incorrect number of arguments"); |
| 23 | return false; |
| 24 | } |
| 25 | |
| 26 | // first identify the properties arguments |
| 27 | auto propsIter = std::find(args.begin(), args.end(), "PROPERTIES"); |
| 28 | if (propsIter == args.end() || propsIter + 1 == args.end()) { |
| 29 | status.SetError("called with illegal arguments, maybe missing a " |
| 30 | "PROPERTIES specifier?"); |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | if (std::distance(propsIter, args.end()) % 2 != 1) { |
| 35 | status.SetError("called with incorrect number of arguments."); |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | std::vector<std::string> tests; |
| 40 | std::string directory; |
| 41 | cmArgumentParser<void> parser; |
| 42 | parser.Bind("DIRECTORY"_s, directory); |
| 43 | auto result = parser.Parse(cmStringRange{ args.begin(), propsIter }, &tests); |
| 44 | |
| 45 | cmMakefile* mf = &status.GetMakefile(); |
| 46 | if (result.MaybeReportError(*mf)) { |
| 47 | return false; |
| 48 | } |
| 49 | if (!directory.empty()) { |
| 50 | std::string absDirectory = cmSystemTools::CollapseFullPath( |
| 51 | directory, mf->GetCurrentSourceDirectory()); |
| 52 | mf = mf->GetGlobalGenerator()->FindMakefile(absDirectory); |
| 53 | if (!mf) { |
| 54 | status.SetError(cmStrCat("given non-existent DIRECTORY ", directory)); |
| 55 | return false; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // loop over all the tests |
| 60 | for (std::string const& tname : tests) { |
| 61 | if (cmTest* test = mf->GetTest(tname)) { |
| 62 | // loop through all the props and set them |
| 63 | for (auto k = propsIter + 1; k != args.end(); k += 2) { |
| 64 | if (!k->empty()) { |
| 65 | test->SetProperty(*k, *(k + 1)); |
| 66 | } |
| 67 | } |
| 68 | } else { |
| 69 | status.SetError( |
| 70 | cmStrCat("Can not find test to add properties to: ", tname)); |
| 71 | return false; |
| 72 | } |
| 73 | } |
| 74 | return true; |
| 75 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…