Skip to content

Commit 7301cd8

Browse files
committed
Normalize trailing newlines in assert_equal function
Instead of trying to normalize in each test, normalize directly in the assert_equal function where both expected and actual are available. This ensures consistent handling of trailing newlines across all platforms.
1 parent 9f76a04 commit 7301cd8

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

tests/test_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
def assert_equal(expected: bytes, actual: bytes):
2020
"""Stand in for Python's assert which is annoying to work with."""
2121
actual = actual.replace(b"\r", b"") # ignore windows file ending differences
22+
# Normalize trailing newlines to handle platform differences (especially cppcheck on Windows)
23+
if actual and actual.strip() and expected and expected.strip():
24+
if b"\n" in actual or b"\n" in expected:
25+
actual = actual.rstrip(b"\n") + b"\n"
26+
expected = expected.rstrip(b"\n") + b"\n"
2227
if expected != actual:
2328
print(f"\n\nExpected:`{expected}`")
2429
print(f"\n\nActual__:`{actual}`")

0 commit comments

Comments
 (0)