Skip to content

Commit cd6bded

Browse files
committed
Fix Windows cppcheck trailing newline normalization
Previous fix wasn't working because we need to normalize both actual and expected output, not just actual. Now we normalize both when either has multiple trailing newlines.
1 parent 5658670 commit cd6bded

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

tests/test_hooks.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,11 +458,13 @@ 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 newline
462-
actual = actual.rstrip(b"\n") + b"\n" if actual.endswith(b"\n") else actual
463461
# Windows clang uses return-mismatch instead of return-type
464462
if cmd_name in ["clang-tidy", "include-what-you-use"]:
465463
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"
466468
retcode = sp_child.returncode
467469
utils.assert_equal(target_output, actual)
468470
assert target_retcode == retcode

0 commit comments

Comments
 (0)