浏览代码

Tests: Refactor RunCMake.FileAPI check script to support more arguments

Brad King 1 月之前
父节点
当前提交
bb704d0390

+ 4 - 2
Tests/RunCMake/FileAPI/RunCMakeTest.cmake

@@ -108,8 +108,10 @@ function(check_python case prefix)
   endif()
   endif()
   file(GLOB index ${RunCMake_TEST_BINARY_DIR}/.cmake/api/v1/reply/${prefix}-*.json)
   file(GLOB index ${RunCMake_TEST_BINARY_DIR}/.cmake/api/v1/reply/${prefix}-*.json)
   execute_process(
   execute_process(
-    COMMAND ${Python_EXECUTABLE} "${RunCMake_SOURCE_DIR}/${case}-check.py" "${index}" "${CMAKE_CXX_COMPILER_ID}"
-      "${RunCMake_TEST_BINARY_DIR}"
+    COMMAND ${Python_EXECUTABLE} "${RunCMake_SOURCE_DIR}/${case}-check.py"
+      --build-dir "${RunCMake_TEST_BINARY_DIR}"
+      --reply-index "${index}"
+      --cxx-compiler-id "${CMAKE_CXX_COMPILER_ID}"
     RESULT_VARIABLE result
     RESULT_VARIABLE result
     OUTPUT_VARIABLE output
     OUTPUT_VARIABLE output
     ERROR_VARIABLE output
     ERROR_VARIABLE output

+ 9 - 3
Tests/RunCMake/FileAPI/check_index.py

@@ -2,6 +2,7 @@ import sys
 import os
 import os
 import json
 import json
 import re
 import re
+import argparse
 
 
 if sys.version_info[0] >= 3:
 if sys.version_info[0] >= 3:
     unicode = str
     unicode = str
@@ -158,8 +159,13 @@ def check_error_re(value, error):
     assert is_string(value["error"])
     assert is_string(value["error"])
     assert re.search(error, value["error"])
     assert re.search(error, value["error"])
 
 
-reply_index = sys.argv[1]
-reply_dir = os.path.dirname(reply_index)
+parser = argparse.ArgumentParser()
+parser.add_argument("--build-dir")
+parser.add_argument("--reply-index")
+parser.add_argument("--cxx-compiler-id")
+args = parser.parse_args()
 
 
-with open(reply_index) as f:
+reply_dir = os.path.dirname(args.reply_index)
+
+with open(args.reply_index) as f:
     index = json.load(f)
     index = json.load(f)

+ 1 - 2
Tests/RunCMake/FileAPI/codemodel-v2-check.py

@@ -900,7 +900,7 @@ def gen_check_targets(c, g, inSource):
                 e["compileGroups"] = apple_exe_framework["compileGroups"]
                 e["compileGroups"] = apple_exe_framework["compileGroups"]
                 e["link"] = apple_exe_framework["link"]
                 e["link"] = apple_exe_framework["link"]
 
 
-    if cxx_compiler_id in ['Clang', 'AppleClang', 'LCC', 'GNU', 'Intel', 'IntelLLVM', 'MSVC', 'Embarcadero', 'CrayClang', 'IBMClang'] and g["name"] != "Xcode":
+    if args.cxx_compiler_id in ['Clang', 'AppleClang', 'LCC', 'GNU', 'Intel', 'IntelLLVM', 'MSVC', 'Embarcadero', 'CrayClang', 'IBMClang'] and g["name"] != "Xcode":
         for e in expected:
         for e in expected:
             if e["name"] == "cxx_exe":
             if e["name"] == "cxx_exe":
                 if matches(g["name"], "^(Visual Studio |Ninja Multi-Config)"):
                 if matches(g["name"], "^(Visual Studio |Ninja Multi-Config)"):
@@ -1087,7 +1087,6 @@ def check_object_codemodel(g, major, minor):
             check_object_codemodel_configuration(c, g, major, minor, inSource)
             check_object_codemodel_configuration(c, g, major, minor, inSource)
     return _check
     return _check
 
 
-cxx_compiler_id = sys.argv[2]
 assert is_dict(index)
 assert is_dict(index)
 assert sorted(index.keys()) == ["cmake", "objects", "reply"]
 assert sorted(index.keys()) == ["cmake", "objects", "reply"]
 check_objects(index["objects"], index["cmake"]["generator"])
 check_objects(index["objects"], index["cmake"]["generator"])

+ 1 - 1
Tests/RunCMake/FileAPI/toolchains-v1-check.py

@@ -77,7 +77,7 @@ def check_object_toolchain(o, expected):
         else:
         else:
             assert False
             assert False
 
 
-with open(os.path.join(sys.argv[3], "toolchain_variables.json")) as f:
+with open(os.path.join(args.build_dir, "toolchain_variables.json")) as f:
     variables = json.load(f)
     variables = json.load(f)
 
 
 assert is_dict(variables)
 assert is_dict(variables)