Skip to content

Commit dc8ebc8

Browse files
committed
Fix iwyu filtering to only check 'add' section for implementation headers
Check only the 'should add these lines' section for implementation detail headers, not the entire output which may include regular headers in the 'full include-list' section.
1 parent 71af6d9 commit dc8ebc8

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

tests/test_hooks.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -558,12 +558,19 @@ def run_shell_cmd(cmd_name, files, args, _, target_output, target_retcode):
558558
actual = actual.replace(b"clang-diagnostic-return-mismatch", b"clang-diagnostic-return-type")
559559
# Filter iwyu suggestions for implementation detail headers on macOS
560560
if cmd_name == "include-what-you-use" and sys.platform == "darwin":
561-
# Remove entire iwyu output if it only suggests implementation detail headers (starting with __)
561+
# Check if output only suggests adding implementation detail headers (starting with __)
562562
lines = actual.split(b"\n")
563-
# Check if all suggested headers are implementation details
564-
suggested_headers = [l for l in lines if l.strip().startswith(b"#include <__")]
565-
if suggested_headers and all(b"<__" in l for l in lines if b"#include <" in l and l.strip().startswith(b"#include")):
566-
# All suggestions are for implementation headers - filter entire output
563+
in_add_section = False
564+
add_section_headers = []
565+
for line in lines:
566+
if b"should add these lines:" in line:
567+
in_add_section = True
568+
elif b"should remove these lines:" in line or b"The full include-list" in line:
569+
in_add_section = False
570+
elif in_add_section and line.strip().startswith(b"#include"):
571+
add_section_headers.append(line)
572+
# If all "add" suggestions are for implementation headers, filter entire output
573+
if add_section_headers and all(b"<__" in h for h in add_section_headers):
567574
actual = b""
568575
retcode = sp_child.returncode
569576
utils.assert_equal(target_output, actual)

0 commit comments

Comments
 (0)