Skip to content

Commit

Permalink
Compile time error diffs: make expected and generated lowercase
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinMeimar committed Nov 13, 2024
1 parent f564e5b commit 9664193
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions dragon_runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ def run(self, test: TestFile, exe: Executable) -> Optional[TestResult]:
tr.did_pass = True
else:
tr.did_pass = False

return tr;

elif last_step:
Expand Down Expand Up @@ -265,7 +264,7 @@ def replace_magic_args(command: Command, params: MagicParams) -> Command:
resolved.append(arg)
return Command(resolved)

def diff_bytes(s1: bytes, s2: bytes):
def diff_bytes(s1: bytes, s2: bytes) -> str:
"""
The difflib library appears to have an infinite recursion bug.
It is simple to write our own.
Expand Down Expand Up @@ -301,18 +300,23 @@ def lenient_diff(produced: bytes, expected: bytes, pattern: str) -> str:
"""
Perform a lenient diff on error messages, using the pattern as a mask/filter.
Unfortunately we have to convert from and back to bytes in order to apply regex.
"""
produced_str = bytes_to_str(produced).strip()
expected_str = bytes_to_str(expected).strip()
Bytes must be UTF-8 decodable.
"""
produced_str = p.strip() if (p := bytes_to_str(produced)) else None
expected_str = e.strip() if (e := bytes_to_str(expected)) else None

if not produced_str or not expected_str:
return "Failed to decode error bytes"

# Apply the mask/filter to both strings
produced_masked = re.sub(pattern, r'\1', produced_str, flags=re.IGNORECASE | re.DOTALL)
expected_masked = re.sub(pattern, r'\1', expected_str, flags=re.IGNORECASE | re.DOTALL)

# If the masked strings are identical, return an empty string (no diff)
if produced_masked == expected_masked:
if produced_masked.lower() == expected_masked.lower():
return ""
return diff_bytes(str_to_bytes(produced_str), str_to_bytes(expected_str))

return diff_bytes(produced, expected)

def color_diff(diff_lines: list) -> str:
"""
Expand Down

0 comments on commit 9664193

Please sign in to comment.