Skip to content

Commit 41946d7

Browse files
committed
Filter macOS system header errors from clang-tidy output
On macOS with SDK configured, clang-tidy may report errors from system headers when analyzing C++ files. Filter these errors and related messages to get clean test output.
1 parent fad667d commit 41946d7

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

tests/test_hooks.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,23 @@ def run_shell_cmd(cmd_name, files, args, _, target_output, target_retcode):
464464
actual = re.sub(rb"[\d,]+ warnings and ", b"", actual)
465465
# Filter out "X warnings generated." from clang-tidy (macOS with SDK configured)
466466
if cmd_name == "clang-tidy":
467+
# Filter warnings count
467468
filtered_actual = re.sub(rb"\d+ warnings? generated\.\n", b"", actual)
468-
# If we filtered warnings and got exit code 1, normalize to 0 if output matches expected
469+
# Filter errors from macOS SDK system headers
470+
filtered_actual = re.sub(
471+
rb"^.*?/Applications/Xcode[^\n]*?/MacOSX\.sdk/[^\n]*\n", b"", filtered_actual, flags=re.MULTILINE
472+
)
473+
# Filter "X errors generated." from system header errors
474+
filtered_actual = re.sub(rb"\d+ errors? generated\.\n", b"", filtered_actual)
475+
# Filter "Error while processing..." lines
476+
filtered_actual = re.sub(rb"^Error while processing [^\n]*\n", b"", filtered_actual, flags=re.MULTILINE)
477+
# Filter "error:" lines from system headers
478+
filtered_actual = re.sub(rb"^error: too many errors emitted[^\n]*\n", b"", filtered_actual, flags=re.MULTILINE)
479+
# Filter "note:" lines that follow system header errors
480+
filtered_actual = re.sub(rb"^note: [^\n]*\n", b"", filtered_actual, flags=re.MULTILINE)
481+
# If we filtered warnings/errors and got exit code 1, normalize to 0 if output matches expected
469482
if filtered_actual != actual and sp_child.returncode == 1:
470-
# clang-tidy returns 1 when warnings are generated, but if we filtered them
483+
# clang-tidy returns 1 when warnings/errors are generated, but if we filtered them
471484
# and the output is now empty or matches expected, treat as success
472485
if filtered_actual.strip() == b"" or filtered_actual.strip() == target_output.strip():
473486
sp_child = sp.CompletedProcess(

0 commit comments

Comments
 (0)