testCTestResourceSpec.cxx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include "cmCTestResourceSpec.h"
  5. struct ExpectedSpec
  6. {
  7. std::string Path;
  8. bool ParseResult;
  9. cmCTestResourceSpec Expected;
  10. };
  11. static const std::vector<ExpectedSpec> expectedResourceSpecs = {
  12. /* clang-format off */
  13. {"spec1.json", true, {{{
  14. {"gpus", {
  15. {"2", 4},
  16. {"e", 1},
  17. }},
  18. {"threads", {
  19. }},
  20. }}}},
  21. {"spec2.json", true, {{{
  22. }}}},
  23. {"spec3.json", false, {{{}}}},
  24. {"spec4.json", false, {{{}}}},
  25. {"spec5.json", false, {{{}}}},
  26. {"spec6.json", false, {{{}}}},
  27. {"spec7.json", false, {{{}}}},
  28. {"spec8.json", false, {{{}}}},
  29. {"spec9.json", false, {{{}}}},
  30. {"spec10.json", false, {{{}}}},
  31. {"spec11.json", false, {{{}}}},
  32. {"spec12.json", false, {{{}}}},
  33. {"spec13.json", false, {{{}}}},
  34. {"spec14.json", true, {{{}}}},
  35. {"spec15.json", true, {{{}}}},
  36. {"spec16.json", true, {{{}}}},
  37. {"spec17.json", false, {{{}}}},
  38. {"spec18.json", false, {{{}}}},
  39. {"spec19.json", false, {{{}}}},
  40. {"spec20.json", true, {{{}}}},
  41. {"spec21.json", false, {{{}}}},
  42. {"spec22.json", false, {{{}}}},
  43. {"spec23.json", false, {{{}}}},
  44. {"spec24.json", false, {{{}}}},
  45. {"spec25.json", false, {{{}}}},
  46. {"spec26.json", false, {{{}}}},
  47. {"spec27.json", false, {{{}}}},
  48. {"spec28.json", false, {{{}}}},
  49. {"spec29.json", false, {{{}}}},
  50. {"spec30.json", false, {{{}}}},
  51. {"spec31.json", false, {{{}}}},
  52. {"spec32.json", false, {{{}}}},
  53. {"spec33.json", false, {{{}}}},
  54. {"spec34.json", false, {{{}}}},
  55. {"spec35.json", false, {{{}}}},
  56. {"noexist.json", false, {{{}}}},
  57. /* clang-format on */
  58. };
  59. static bool testSpec(const std::string& path, bool expectedResult,
  60. const cmCTestResourceSpec& expected)
  61. {
  62. cmCTestResourceSpec actual;
  63. bool result = actual.ReadFromJSONFile(path);
  64. if (result != expectedResult) {
  65. std::cout << "ReadFromJSONFile(\"" << path << "\") returned " << result
  66. << ", should be " << expectedResult << std::endl;
  67. return false;
  68. }
  69. if (result && actual != expected) {
  70. std::cout << "ReadFromJSONFile(\"" << path
  71. << "\") did not give expected spec" << std::endl;
  72. return false;
  73. }
  74. return true;
  75. }
  76. int testCTestResourceSpec(int argc, char** const argv)
  77. {
  78. if (argc < 2) {
  79. std::cout << "Invalid arguments.\n";
  80. return -1;
  81. }
  82. int retval = 0;
  83. for (auto const& spec : expectedResourceSpecs) {
  84. std::string path = argv[1];
  85. path += "/testCTestResourceSpec_data/";
  86. path += spec.Path;
  87. if (!testSpec(path, spec.ParseResult, spec.Expected)) {
  88. retval = -1;
  89. }
  90. }
  91. return retval;
  92. }