12 clang-doc test generator 13 ========================== 15 Generates tests for clang-doc given a certain set of flags, a prefix for the 16 test file, and a given clang-doc binary. Please check emitted tests for 17 accuracy before using. 19 To generate all current tests: 20 - Generate mapper tests: 21 gen_tests.py -flag='--dump-mapper' -flag='--doxygen' -prefix mapper 23 - Generate reducer tests: 24 gen_tests.py -flag='--dump-intermediate' -flag='--doxygen' -prefix bc 26 - Generate yaml tests: 27 gen_tests.py -flag='--format=yaml' -flag='--doxygen' -prefix yaml 29 This script was written on/for Linux, and has not been tested on any other 30 platform and so it may not work. 41 // RUN: clang-doc {0} -p %t %t/test.cpp -output=%t/docs 44 // RUN: {0} %t/{1} | FileCheck %s --check-prefix CHECK-{2} 47 CHECK =
'// CHECK-{0}: ' 49 CHECK_NEXT =
'// CHECK-{0}-NEXT: ' 53 if os.path.isdir(tests_path):
54 for root, dirs, files
in os.walk(tests_path):
55 for filename
in files:
56 if filename.startswith(prefix):
57 os.remove(os.path.join(root, filename))
62 test_file = os.path.join(test_cases_path,
'test.cpp')
63 shutil.copyfile(test_case_path, test_file)
69 current_cmd = [args.clangdoc]
70 current_cmd.extend(args.flags)
71 current_cmd.append(
'--output=' + out_dir)
72 current_cmd.append(test_file)
73 print(
'Running ' +
' '.
join(current_cmd))
74 return_code = subprocess.call(current_cmd)
83 with open(test_case_path,
'r') as code_file: 84 code = code_file.read() 86 code += RUN_CLANG_DOC.format(flags) 90 def get_output(root, out_file, case_out_path, flags, checkname, bcanalyzer):
93 if '--dump-mapper' in flags
or '--dump-intermediate' in flags:
95 output = subprocess.check_output(
96 [bcanalyzer,
'--dump',
97 os.path.join(root, out_file)])
98 output = output[:output.find(
'Summary of ')].rstrip()
99 run_cmd = RUN.format(
'llvm-bcanalyzer --dump',
100 os.path.join(
'docs',
'bc', out_file), checkname)
103 output = subprocess.check_output([
'cat', os.path.join(root, out_file)])
104 run_cmd = RUN.format(
106 os.path.join(
'docs', os.path.relpath(root, case_out_path),
107 out_file), checkname)
110 output = output.replace(
'blob data = \'test\'',
'blob data = \'{{.*}}\'')
111 output = CHECK.format(checkname) + output.rstrip()
112 output = run_cmd + output.replace(
'\n',
113 '\n' + CHECK_NEXT.format(checkname))
119 parser = argparse.ArgumentParser(description=
'Generate clang-doc tests.')
125 help=
'Flags to pass to clang-doc.')
131 help=
'Prefix for this test group.')
137 help=
'path to clang-doc binary')
139 '-llvm-bcanalyzer-binary',
142 default=
'llvm-bcanalyzer',
143 help=
'path to llvm-bcanalyzer binary')
144 args = parser.parse_args()
146 flags =
' '.
join(args.flags)
148 clang_doc_path = os.path.dirname(__file__)
149 tests_path = os.path.join(clang_doc_path,
'..',
'test',
'clang-doc')
150 test_cases_path = os.path.join(tests_path,
'test_cases')
154 for test_case_path
in glob.glob(os.path.join(test_cases_path,
'*')):
155 if test_case_path.endswith(
156 'compile_flags.txt')
or test_case_path.endswith(
157 'compile_commands.json'):
161 case_name = os.path.basename(test_case_path).split(
'.')[0]
164 out_dir = os.path.join(test_cases_path, case_name)
172 for root, dirs, files
in os.walk(out_dir):
173 for out_file
in files:
176 usr = os.path.basename(out_file).split(
'.')
180 all_output +=
get_output(root, out_file, out_dir, args.flags,
181 num_outputs, args.bcanalyzer)
186 flags) +
'\n' + all_output
189 test_out_path = os.path.join(
190 tests_path, args.prefix +
'-' + os.path.basename(test_case_path))
191 with open(test_out_path,
'w+')
as o:
195 shutil.rmtree(out_dir)
199 if __name__ ==
'__main__':
def clear_test_prefix_files(prefix, tests_path)
def copy_to_test_file(test_case_path, test_cases_path)
def get_output(root, out_file, case_out_path, flags, checkname, bcanalyzer)
def run_clang_doc(args, out_dir, test_file)
static std::string join(ArrayRef< SpecialMemberFunctionsCheck::SpecialMemberFunctionKind > SMFS, llvm::StringRef AndOr)
def get_test_case_code(test_case_path, flags)