Skip to content

Commit cc1ae4e

Browse files
committed
Add compile_commands.json to git staging and fix Windows diagnostic name
Two fixes: 1. Add compile_commands.json to git staging area in integration tests so iwyu can find it when running through pre-commit 2. Normalize Windows clang diagnostic name 'return-mismatch' to 'return-type' for consistent test expectations across platforms
1 parent 1c1dfaa commit cc1ae4e

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

tests/test_hooks.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,9 @@ def run_integration_test(cmd_name, files, args, test_dir, target_output, target_
414414
# Newer cppcheck versions include a checkers report info line
415415
if cmd_name == "cppcheck":
416416
output_actual = re.sub(rb"\nnofile:0:0: information: Active checkers.*\n+", b"\n", output_actual)
417+
# Windows clang uses return-mismatch instead of return-type
418+
if cmd_name in ["clang-tidy", "include-what-you-use"]:
419+
output_actual = output_actual.replace(b"clang-diagnostic-return-mismatch", b"clang-diagnostic-return-type")
417420

418421
utils.assert_equal(target_output, output_actual)
419422
assert target_retcode == actual_returncode
@@ -455,6 +458,9 @@ def run_shell_cmd(cmd_name, files, args, _, target_output, target_retcode):
455458
# Newer cppcheck versions include a checkers report info line
456459
if cmd_name == "cppcheck":
457460
actual = re.sub(rb"\nnofile:0:0: information: Active checkers.*\n+", b"\n", actual)
461+
# Windows clang uses return-mismatch instead of return-type
462+
if cmd_name in ["clang-tidy", "include-what-you-use"]:
463+
actual = actual.replace(b"clang-diagnostic-return-mismatch", b"clang-diagnostic-return-type")
458464
retcode = sp_child.returncode
459465
utils.assert_equal(target_output, actual)
460466
assert target_retcode == retcode

tests/test_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ def integration_test(cmd_name, files, args, test_dir):
115115
fd.write(test_file_strs[test_file_base])
116116
# Create compilation database for clang-tidy and iwyu
117117
set_compilation_db(files)
118-
# Add only the files we are testing
118+
# Add the files we are testing and the compilation database
119119
run_in(["git", "reset"], test_dir)
120-
run_in(["git", "add"] + files, test_dir)
120+
compile_db = os.path.join(test_dir, "compile_commands.json")
121+
run_in(["git", "add"] + files + [compile_db], test_dir)
121122
args = list(args) # redeclare so there's no memory weirdness
122123
pre_commit_config_path = os.path.join(test_dir, ".pre-commit-config.yaml")
123124
pre_commit_config = f"""\

0 commit comments

Comments
 (0)