Skip to content

Commit 9f76a04

Browse files
committed
Always normalize cppcheck trailing newlines
Previous conditional approach wasn't catching all cases. Now we always normalize both actual and expected output for cppcheck to have exactly one trailing newline (when non-empty), which should handle Windows platform differences consistently.
1 parent cd6bded commit 9f76a04

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

tests/test_hooks.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,14 @@ def run_shell_cmd(cmd_name, files, args, _, target_output, target_retcode):
458458
# Newer cppcheck versions include a checkers report info line
459459
if cmd_name == "cppcheck":
460460
actual = re.sub(rb"\nnofile:0:0: information: Active checkers.*\n+", b"\n", actual)
461+
# Windows cppcheck adds extra trailing newlines - normalize both to have exactly one
462+
if actual and actual.strip(): # Don't normalize empty output
463+
actual = actual.rstrip(b"\n") + b"\n"
464+
if target_output and target_output.strip():
465+
target_output = target_output.rstrip(b"\n") + b"\n"
461466
# Windows clang uses return-mismatch instead of return-type
462467
if cmd_name in ["clang-tidy", "include-what-you-use"]:
463468
actual = actual.replace(b"clang-diagnostic-return-mismatch", b"clang-diagnostic-return-type")
464-
# Normalize trailing newlines for cppcheck on Windows
465-
if cmd_name == "cppcheck" and (actual.endswith(b"\n\n") or target_output.endswith(b"\n\n")):
466-
actual = actual.rstrip(b"\n") + b"\n"
467-
target_output = target_output.rstrip(b"\n") + b"\n"
468469
retcode = sp_child.returncode
469470
utils.assert_equal(target_output, actual)
470471
assert target_retcode == retcode

0 commit comments

Comments
 (0)