Skip to content

Commit 9404990

Browse files
committed
test(fixtures): normalize truncated panic symbol hashes
1 parent 7966a30 commit 9404990

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

kmir/src/kmir/testing/fixtures.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,26 @@ def pytest_configure(config) -> None:
2323
def assert_or_update_show_output(
2424
actual_text: str, expected_file: Path, *, update: bool, path_replacements: dict[str, str] | None = None
2525
) -> None:
26+
def _normalize_panic_symbol_hashes(text: str) -> str:
27+
# Full panic symbol in mangled form.
28+
text = re.sub(r'_ZN4core9panicking5panic17h[0-9a-f]+E', '_ZN4core9panicking5panic17h<hash>E', text)
29+
# Truncated panic symbol shown by `kmir show --statistics --leaves`.
30+
text = re.sub(r'_ZN4core9panicking5panic17h[0-9a-f]+', '_ZN4core9panicking5panic17h<hash>', text)
31+
# Demangled panic symbol.
32+
text = re.sub(r'core::panicking::panic::h[0-9a-f]+', 'core::panicking::panic::h<hash>', text)
33+
return text
34+
2635
if path_replacements:
2736
for old, new in path_replacements.items():
2837
actual_text = actual_text.replace(old, new)
2938
# Normalize rustc panic symbol hash suffixes that can drift across builds/environments.
30-
actual_text = re.sub(r'_ZN4core9panicking5panic17h[0-9a-f]+E', '_ZN4core9panicking5panic17h<hash>E', actual_text)
31-
actual_text = re.sub(r'core::panicking::panic::h[0-9a-f]+', 'core::panicking::panic::h<hash>', actual_text)
39+
actual_text = _normalize_panic_symbol_hashes(actual_text)
3240
if update:
3341
expected_file.write_text(actual_text)
3442
else:
3543
assert expected_file.is_file()
3644
expected_text = expected_file.read_text()
37-
expected_text = re.sub(
38-
r'_ZN4core9panicking5panic17h[0-9a-f]+E', '_ZN4core9panicking5panic17h<hash>E', expected_text
39-
)
40-
expected_text = re.sub(r'core::panicking::panic::h[0-9a-f]+', 'core::panicking::panic::h<hash>', expected_text)
45+
expected_text = _normalize_panic_symbol_hashes(expected_text)
4146
if actual_text != expected_text:
4247
diff = '\n'.join(
4348
unified_diff(

0 commit comments

Comments
 (0)