Skip to content

Commit ecc9fc8

Browse files
committed
Filter iwyu implementation headers in integration tests on macOS
Apply same implementation header filtering to integration tests that run through pre-commit. Replace Failed output with Passed when all add suggestions are for implementation headers.
1 parent 6576467 commit ecc9fc8

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

tests/test_hooks.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,32 @@ def run_integration_test(cmd_name, files, args, test_dir, target_output, target_
422422
# Filter out "X warnings generated." from clang-tidy (macOS with SDK configured)
423423
if cmd_name == "clang-tidy":
424424
output_actual = re.sub(rb"\d+ warnings? generated\.\n", b"", output_actual)
425-
# Windows clang uses return-mismatch instead of return-type
425+
# Windows/macOS clang uses return-mismatch instead of return-type
426426
if cmd_name in ["clang-tidy", "include-what-you-use"]:
427427
output_actual = output_actual.replace(b"clang-diagnostic-return-mismatch", b"clang-diagnostic-return-type")
428+
output_actual = output_actual.replace(b"-Wreturn-mismatch", b"-Wreturn-type")
429+
# Filter iwyu implementation header suggestions on macOS
430+
if cmd_name == "include-what-you-use" and sys.platform == "darwin":
431+
lines = output_actual.split(b"\n")
432+
in_add_section = False
433+
add_section_headers = []
434+
for line in lines:
435+
if b"should add these lines:" in line:
436+
in_add_section = True
437+
elif b"should remove these lines:" in line or b"The full include-list" in line:
438+
in_add_section = False
439+
elif in_add_section and line.strip().startswith(b"#include"):
440+
add_section_headers.append(line)
441+
# If all "add" suggestions are for implementation headers, normalize to "Passed"
442+
if add_section_headers and all(b"<__" in h for h in add_section_headers):
443+
# Replace the Failed output with Passed
444+
output_actual = re.sub(
445+
rb"include-what-you-use\.+Failed.*?---\n",
446+
b"include-what-you-use.....................................................Passed\n",
447+
output_actual,
448+
flags=re.DOTALL
449+
)
450+
actual_returncode = 0
428451

429452
utils.assert_equal(target_output, output_actual)
430453
assert target_retcode == actual_returncode

0 commit comments

Comments
 (0)