cmakeFiles-v1-check.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. from check_index import *
  2. def check_objects(o):
  3. assert is_list(o)
  4. assert len(o) == 1
  5. check_index_object(o[0], "cmakeFiles", 1, 1, check_object_cmakeFiles)
  6. def check_input(actual, expected):
  7. assert is_dict(actual)
  8. expected_keys = ["path"]
  9. if expected["isGenerated"] is not None:
  10. expected_keys.append("isGenerated")
  11. assert is_bool(actual["isGenerated"], expected["isGenerated"])
  12. if expected["isExternal"] is not None:
  13. expected_keys.append("isExternal")
  14. assert is_bool(actual["isExternal"], expected["isExternal"])
  15. if expected["isCMake"] is not None:
  16. expected_keys.append("isCMake")
  17. assert is_bool(actual["isCMake"], expected["isCMake"])
  18. assert sorted(actual.keys()) == sorted(expected_keys)
  19. def check_glob_dependent(actual, expected):
  20. assert is_dict(actual)
  21. if "followSymlinks" in expected:
  22. assert is_bool(actual["followSymlinks"], expected["followSymlinks"])
  23. if "listDirectories" in expected:
  24. assert is_bool(actual["listDirectories"], expected["listDirectories"])
  25. if "recurse" in expected:
  26. assert is_bool(actual["recurse"], expected["recurse"])
  27. if "relative" in expected:
  28. assert matches(actual["relative"], expected["relative"])
  29. check_list_match(lambda a, e: matches(a, e), actual["paths"], expected["paths"], allow_extra=True)
  30. assert sorted(actual.keys()) == sorted(expected.keys())
  31. def check_object_cmakeFiles(o):
  32. assert sorted(o.keys()) == ["globsDependent", "inputs", "kind", "paths", "version"]
  33. # The "kind" and "version" members are handled by check_index_object.
  34. assert is_dict(o["paths"])
  35. assert sorted(o["paths"].keys()) == ["build", "source"]
  36. assert matches(o["paths"]["build"], "^.*/Tests/RunCMake/FileAPI/cmakeFiles-v1-build$")
  37. assert matches(o["paths"]["source"], "^.*/Tests/RunCMake/FileAPI$")
  38. expected = [
  39. {
  40. "path": "^CMakeLists\\.txt$",
  41. "isGenerated": None,
  42. "isExternal": None,
  43. "isCMake": None,
  44. },
  45. {
  46. "path": "^cmakeFiles-v1\\.cmake$",
  47. "isGenerated": None,
  48. "isExternal": None,
  49. "isCMake": None,
  50. },
  51. {
  52. "path": "^dir/CMakeLists\\.txt$",
  53. "isGenerated": None,
  54. "isExternal": None,
  55. "isCMake": None,
  56. },
  57. {
  58. "path": "^dir/dir/CMakeLists\\.txt$",
  59. "isGenerated": None,
  60. "isExternal": None,
  61. "isCMake": None,
  62. },
  63. {
  64. "path": "^dir/dirtest\\.cmake$",
  65. "isGenerated": None,
  66. "isExternal": None,
  67. "isCMake": None,
  68. },
  69. {
  70. "path": "^.*/Tests/RunCMake/FileAPIDummyFile\\.cmake$",
  71. "isGenerated": None,
  72. "isExternal": True,
  73. "isCMake": None,
  74. },
  75. {
  76. "path": "^.*/Tests/RunCMake/FileAPI/cmakeFiles-v1-build/generated\\.cmake",
  77. "isGenerated": True,
  78. "isExternal": None,
  79. "isCMake": None,
  80. },
  81. {
  82. "path": "^.*/Modules/CMakeParseArguments\\.cmake$",
  83. "isGenerated": None,
  84. "isExternal": True,
  85. "isCMake": True,
  86. },
  87. ]
  88. expected_globs = [
  89. {
  90. "expression": "^.*/Tests/RunCMake/FileAPI/dir/\\*$",
  91. "paths": [
  92. "^.*/Tests/RunCMake/FileAPI/dir/dir$",
  93. "^.*/Tests/RunCMake/FileAPI/dir/dirtest\\.cmake$"
  94. ],
  95. "listDirectories": True,
  96. },
  97. {
  98. "expression": "^.*/Tests/RunCMake/FileAPI/dir/\\*\\.cmake$",
  99. "paths": [
  100. "^dir/dirtest\\.cmake$"
  101. ],
  102. "followSymlinks": True,
  103. "recurse": True,
  104. "relative": "^.*/Tests/RunCMake/FileAPI$"
  105. }
  106. ]
  107. inSource = os.path.dirname(o["paths"]["build"]) == o["paths"]["source"]
  108. if inSource:
  109. for e in expected:
  110. e["path"] = e["path"].replace("^.*/Tests/RunCMake/FileAPI/", "^", 1)
  111. check_list_match(lambda a, e: matches(a["path"], e["path"]), o["inputs"], expected, check=check_input, allow_extra=True)
  112. check_list_match(lambda a, e: matches(a["expression"], e["expression"]), o["globsDependent"], expected_globs, check=check_glob_dependent, allow_extra=True)
  113. assert is_dict(index)
  114. assert sorted(index.keys()) == ["cmake", "objects", "reply"]
  115. check_objects(index["objects"])