Skip to content

Commit 2c3bb1d

Browse files
committed
fix(tests): keep snapshots for -fail and -unsupported
1 parent 91fa4f3 commit 2c3bb1d

9 files changed

Lines changed: 94 additions & 22 deletions

kmir/src/kmir/cargo.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ def cargo_get_smir_json(
182182
cwd = cwd or Path.cwd()
183183
smir_json_result = cwd / rs_file.with_suffix('.smir.json').name
184184
run_process_2(command, cwd=cwd)
185+
resolved_smir_json_result = cwd / rs_file.resolve().with_suffix('.smir.json').name
186+
if not smir_json_result.is_file() and resolved_smir_json_result.is_file():
187+
resolved_smir_json_result.rename(smir_json_result)
185188
json_smir = json.loads(smir_json_result.read_text())
186189
_LOGGER.info(f'Loaded: {smir_json_result}')
187190
if save_smir:

kmir/src/kmir/testing/fixtures.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,26 @@ def _normalize_symbol_hashes(text: str) -> str:
3131
return text
3232

3333

34+
def _normalize_show_output(text: str) -> str:
35+
text = _normalize_symbol_hashes(text)
36+
text = re.sub(r'(?m)^(\s*(?:[│┃┊]\s*)?span: )\d+$', r'\1<span>', text)
37+
text = re.sub(r'(?m)^\s*>> message: .*\n?', '', text)
38+
return text.rstrip('\r\n')
39+
40+
3441
def assert_or_update_show_output(
3542
actual_text: str, expected_file: Path, *, update: bool, path_replacements: dict[str, str] | None = None
3643
) -> None:
3744
if path_replacements:
3845
for old, new in path_replacements.items():
3946
actual_text = actual_text.replace(old, new)
40-
# Normalize rustc symbol hash suffixes that can drift across builds/environments.
41-
actual_text = _normalize_symbol_hashes(actual_text)
47+
actual_text = _normalize_show_output(actual_text)
4248
if update:
4349
expected_file.write_text(actual_text)
4450
else:
4551
assert expected_file.is_file()
4652
expected_text = expected_file.read_text()
47-
expected_text = _normalize_symbol_hashes(expected_text)
53+
expected_text = _normalize_show_output(expected_text)
4854
if actual_text != expected_text:
4955
diff = '\n'.join(
5056
unified_diff(
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
┌─ 1 (root, init)
3+
│ #execTerminator ( terminator ( ... kind: terminatorKindCall ( ... func: operandC
4+
│ span: 0
5+
6+
│ (8 steps)
7+
└─ 3 (stuck, leaf)
8+
#setUpCalleeData ( monoItemFn ( ... name: symbol ( "_ZN4core9panicking5panic17h<hash>
9+
span: 32
10+
11+
12+
┌─ 2 (root, leaf, target, terminal)
13+
│ #EndProgram ~> .K
14+
15+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
┌─ 1 (root, init)
3+
│ #execTerminator ( terminator ( ... kind: terminatorKindCall ( ... func: operandC
4+
│ span: 0
5+
6+
│ (10 steps)
7+
├─ 3
8+
│ #decodeConstant ( constantKindAllocated ( allocation ( ... bytes: b"\x00\x00\x00
9+
│ function: main
10+
│ span: 118
11+
12+
│ (1 step)
13+
└─ 4 (leaf, terminal)
14+
thunk ( #decodeConstant ( constantKindAllocated ( allocation ( ... bytes: b"\x00
15+
function: main
16+
span: 118
17+
18+
19+
┌─ 2 (root, leaf, target, terminal)
20+
│ #EndProgram ~> .K
21+
22+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
┌─ 1 (root, init)
3+
│ #execTerminator ( terminator ( ... kind: terminatorKindCall ( ... func: operandC
4+
│ span: 0
5+
6+
│ (1450 steps)
7+
└─ 3 (stuck, leaf)
8+
#setUpCalleeData ( monoItemFn ( ... name: symbol ( "_ZN4core9panicking5panic17h<hash>
9+
span: 32
10+
11+
12+
┌─ 2 (root, leaf, target, terminal)
13+
│ #EndProgram ~> .K
14+
15+

kmir/src/tests/integration/data/prove-rs/show/offset-u8-unsupported.main.expected

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
│ #execTerminator ( terminator ( ... kind: terminatorKindCall ( ... func: operandC
44
│ span: 0
55
6-
│ (35 steps)
7-
└─ 3 (stuck, leaf)
8-
#traverseProjection ( toAlloc ( allocId ( 0 ) ) , StringVal ( "123" ) , .Project
9-
span: 48
6+
│ (16 steps)
7+
├─ 3
8+
│ #decodeConstant ( constantKindAllocated ( allocation ( ... bytes: b"\x00\x00\x00
9+
│ span: 63
10+
11+
│ (1 step)
12+
└─ 4 (leaf, terminal)
13+
thunk ( #decodeConstant ( constantKindAllocated ( allocation ( ... bytes: b"\x00
14+
span: 63
1015

1116

1217
┌─ 2 (root, leaf, target, terminal)

kmir/src/tests/integration/data/prove-rs/show/volatile_load_static-unsupported.main.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
├─ 3
88
│ #decodeConstant ( constantKindAllocated ( allocation ( ... bytes: b"\x00\x00\x00
99
│ function: main
10-
│ span: 56
10+
│ span: 53
1111
1212
│ (1 step)
1313
└─ 4 (leaf, terminal)
1414
thunk ( #decodeConstant ( constantKindAllocated ( allocation ( ... bytes: b"\x00
1515
function: main
16-
span: 56
16+
span: 53
1717

1818

1919
┌─ 2 (root, leaf, target, terminal)

kmir/src/tests/integration/data/prove-rs/show/volatile_store_static-unsupported.main.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
├─ 3
88
│ #decodeConstant ( constantKindAllocated ( allocation ( ... bytes: b"\x00\x00\x00
99
│ function: main
10-
│ span: 57
10+
│ span: 54
1111
1212
│ (1 step)
1313
└─ 4 (leaf, terminal)
1414
thunk ( #decodeConstant ( constantKindAllocated ( allocation ( ... bytes: b"\x00
1515
function: main
16-
span: 57
16+
span: 54
1717

1818

1919
┌─ 2 (root, leaf, target, terminal)

kmir/src/tests/integration/test_integration.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,37 +49,43 @@
4949
ids=[spec.stem for spec in PROVE_FILES],
5050
)
5151
def test_prove(rs_file: Path, kmir: KMIR, update_expected_output: bool) -> None:
52-
should_fail = rs_file.stem.endswith('fail') or rs_file.stem.endswith('unsupported')
52+
should_fail = rs_file.stem.endswith('fail')
53+
should_show = should_fail or rs_file.stem.endswith('unsupported')
5354
is_smir = rs_file.suffix == '.json'
5455

55-
if update_expected_output and not should_fail:
56+
start_symbols = ['main']
57+
if rs_file.stem in PROVE_START_SYMBOLS:
58+
start_symbols = PROVE_START_SYMBOLS[rs_file.stem]
59+
60+
if update_expected_output and not should_show:
61+
for start_symbol in start_symbols:
62+
expected_file = PROVE_DIR / f'show/{rs_file.stem}.{start_symbol}.expected'
63+
assert not expected_file.is_file()
5664
pytest.skip()
5765

5866
prove_opts = ProveOpts(rs_file, smir=is_smir, terminate_on_thunk=True)
5967
printer = PrettyPrinter(kmir.definition)
6068
cterm_show = CTermShow(printer.print)
6169

62-
start_symbols = ['main']
63-
if rs_file.stem in PROVE_START_SYMBOLS:
64-
start_symbols = PROVE_START_SYMBOLS[rs_file.stem]
65-
6670
for start_symbol in start_symbols:
6771
prove_opts.start_symbol = start_symbol
6872
apr_proof = kmir.prove_program(prove_opts)
73+
expected_file = PROVE_DIR / f'show/{rs_file.stem}.{start_symbol}.expected'
6974

70-
if should_fail:
71-
assert apr_proof.failed
75+
if should_show:
7276
display_opts = ShowOpts(
7377
rs_file.parent, apr_proof.id, full_printer=False, smir_info=None, omit_current_body=False
7478
)
7579
shower = APRProofShow(kmir.definition, node_printer=KMIRAPRNodePrinter(cterm_show, apr_proof, display_opts))
7680
show_res = '\n'.join(shower.show(apr_proof))
77-
assert_or_update_show_output(
78-
show_res, PROVE_DIR / f'show/{rs_file.stem}.{start_symbol}.expected', update=update_expected_output
79-
)
81+
assert_or_update_show_output(show_res, expected_file, update=update_expected_output)
8082
else:
83+
assert not expected_file.is_file()
8184
assert apr_proof.passed
8285

86+
if should_fail:
87+
assert apr_proof.failed
88+
8389

8490
VERIFY_RUST_STD_DIR = (Path(__file__).parent / 'data' / 'verify-rust-std').resolve(strict=True)
8591
VERIFY_RUST_STD_FILES = list(VERIFY_RUST_STD_DIR.glob('**/*.rs'))

0 commit comments

Comments
 (0)