cmSetTestsPropertiesCommand.cxx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmSetTestsPropertiesCommand.h"
  4. #include <algorithm>
  5. #include <iterator>
  6. #include "cmExecutionStatus.h"
  7. #include "cmMakefile.h"
  8. #include "cmStringAlgorithms.h"
  9. #include "cmTest.h"
  10. bool cmSetTestsPropertiesCommand(std::vector<std::string> const& args,
  11. cmExecutionStatus& status)
  12. {
  13. if (args.empty()) {
  14. status.SetError("called with incorrect number of arguments");
  15. return false;
  16. }
  17. // first identify the properties arguments
  18. auto propsIter = std::find(args.begin(), args.end(), "PROPERTIES");
  19. if (propsIter == args.end() || propsIter + 1 == args.end()) {
  20. status.SetError("called with illegal arguments, maybe missing a "
  21. "PROPERTIES specifier?");
  22. return false;
  23. }
  24. if (std::distance(propsIter, args.end()) % 2 != 1) {
  25. status.SetError("called with incorrect number of arguments.");
  26. return false;
  27. }
  28. // loop over all the tests
  29. for (const std::string& tname : cmStringRange{ args.begin(), propsIter }) {
  30. if (cmTest* test = status.GetMakefile().GetTest(tname)) {
  31. // loop through all the props and set them
  32. for (auto k = propsIter + 1; k != args.end(); k += 2) {
  33. if (!k->empty()) {
  34. test->SetProperty(*k, *(k + 1));
  35. }
  36. }
  37. } else {
  38. status.SetError(
  39. cmStrCat("Can not find test to add properties to: ", tname));
  40. return false;
  41. }
  42. }
  43. return true;
  44. }