test: use multiline diagnostic fixtures

This commit is contained in:
2026-10-25 21:46:47 +01:00
parent ac7ab63b9e
commit c40d09b5cc
2 changed files with 86 additions and 24 deletions
+25 -6
View File
@@ -70,10 +70,20 @@ keeps_package_declarations_distinct_and_ir_independent test {
dependency_traps_keep_original_spans_and_remain_demand_driven test { dependency_traps_keep_original_spans_and_remain_demand_driven test {
mains [2][]u8 :: [ mains [2][]u8 :: [
"dep :: import \"../dependency\"\nmain proc() int { return dep.fail(false) }\n", `dep :: import "../dependency"
"dep :: import \"../dependency\"\nmain proc() int { return dep.fail(true) }\n", `main proc() int { return dep.fail(false) }
`
,
`dep :: import "../dependency"
`main proc() int { return dep.fail(true) }
`
,
] ]
prefix :: "\nfail proc(take bool) int {\n if take {\n return " prefix ::
`
`fail proc(take bool) int {
` if take {
`
for (mains) |main, index| { for (mains) |main, index| {
diagnostic_store := diagnostics.init(mem.c_allocator) diagnostic_store := diagnostics.init(mem.c_allocator)
defer diagnostics.deinit(&diagnostic_store) defer diagnostics.deinit(&diagnostic_store)
@@ -88,7 +98,15 @@ dependency_traps_keep_original_spans_and_remain_demand_driven test {
root_bytes := try owned_text(main) root_bytes := try owned_text(main)
defer arraylist.deinit(&root_bytes) defer arraylist.deinit(&root_bytes)
dependency_bytes := try owned_text( dependency_bytes := try owned_text(
"\nfail proc(take bool) int {\n if take {\n return missing\n }\n return 42\n}\n", `
`fail proc(take bool) int {
` if take {
` return missing
` }
` return 42
`}
`
,
) )
defer arraylist.deinit(&dependency_bytes) defer arraylist.deinit(&dependency_bytes)
root_source :: try add_source(&session, root, "app/main.hon", &root_bytes, &diagnostic_store) root_source :: try add_source(&session, root, "app/main.hon", &root_bytes, &diagnostic_store)
@@ -105,8 +123,9 @@ dependency_traps_keep_original_spans_and_remain_demand_driven test {
diagnostic :: diagnostics.get(&diagnostic_store, original)? diagnostic :: diagnostics.get(&diagnostic_store, original)?
try testing.expect_equal(diagnostics.Code.unknown_name, diagnostic.code) try testing.expect_equal(diagnostics.Code.unknown_name, diagnostic.code)
try testing.expect_equal(dependency_source, diagnostic.span.source) try testing.expect_equal(dependency_source, diagnostic.span.source)
try testing.expect_equal(u32(prefix.len), diagnostic.span.start) start :: u32(prefix.len + " return ".len)
try testing.expect_equal(u32(prefix.len + 7), diagnostic.span.end) try testing.expect_equal(start, diagnostic.span.start)
try testing.expect_equal(start + 7, diagnostic.span.end)
outcome := try interpreter.run(mem.c_allocator, &module, &diagnostic_store) outcome := try interpreter.run(mem.c_allocator, &module, &diagnostic_store)
defer interpreter.deinit(&outcome) defer interpreter.deinit(&outcome)
try testing.expect_equal(1, diagnostics.count(&diagnostic_store)) try testing.expect_equal(1, diagnostics.count(&diagnostic_store))
+61 -18
View File
@@ -440,29 +440,72 @@ def check_dependency_provenance(temporary, executable):
# A transitive call must report the leaf's location, not either importing file. # A transitive call must report the leaf's location, not either importing file.
bridge = project / "bridge" bridge = project / "bridge"
bridge.mkdir() bridge.mkdir()
(bridge / "main.hon").write_text( (bridge / "main.hon").write_text(textwrap.dedent("""
'import "../dependency"\nfail proc() int { return dependency.fail() }\n' import "../dependency"
) fail proc() int { return dependency.fail() }
""").strip() + "\n")
cases = [ cases = [
("fail proc() int {\n return `\n}\n", 4, 12, True), ("""
("fail proc() int {\n return (1\n}\n", 4, 14, True), fail proc() int {
("fail proc() int {\n text :: \"é\" return missing\n}\n", 4, 25, True), return `
("fail proc() int {\n if (1) return 0\n return 42\n}\n", 4, 9, True), }
("fail proc() int {\n return 9223372036854775808\n}\n", 4, 12, True), """, 4, 12, True),
("fail proc() int {\n return 9223372036854775807 + 1\n}\n", 4, 12, False), ("""
("fail proc() int {\n a :: [42]\n return a[1]\n}\n", 5, 12, False), fail proc() int {
("fail proc() int {\n before :: after\n after :: 42\n return before\n}\n", 4, 15, False), return (1
("a int :: b\nb int :: a\nfail proc() int { return a }\n", 4, 10, False), }
""", 4, 14, True),
("""
fail proc() int {
text :: "é" return missing
}
""", 4, 25, True),
("""
fail proc() int {
if (1) return 0
return 42
}
""", 4, 9, True),
("""
fail proc() int {
return 9223372036854775808
}
""", 4, 12, True),
("""
fail proc() int {
return 9223372036854775807 + 1
}
""", 4, 12, False),
("""
fail proc() int {
a :: [42]
return a[1]
}
""", 5, 12, False),
("""
fail proc() int {
before :: after
after :: 42
return before
}
""", 4, 15, False),
("""
a int :: b
b int :: a
fail proc() int { return a }
""", 4, 10, False),
] ]
for text, line, column, static in cases: for text, line, column, static in cases:
source.write_text("\n# utf8: é\n" + text) source.write_text("\n# utf8: é\n" + textwrap.dedent(text).strip() + "\n")
location = f"{source.resolve()}:{line}:{column}: ".encode() location = f"{source.resolve()}:{line}:{column}: ".encode()
for reached in (False, True): for reached in (False, True):
main.write_text( main.write_text(textwrap.dedent(f"""
'import "../bridge"\nmain proc() int {\n' import "../bridge"
f' if ({str(reached).lower()}) return bridge.fail()\n' main proc() int {{
' return 42\n}\n' if ({str(reached).lower()}) return bridge.fail()
) return 42
}}
""").strip() + "\n")
interpreted = run(str(HONEY), "run", str(app)) interpreted = run(str(HONEY), "run", str(app))
assert interpreted.returncode == int(static or reached), outcome(interpreted) assert interpreted.returncode == int(static or reached), outcome(interpreted)
assert interpreted.stdout == (b"" if reached else b"42\n"), outcome(interpreted) assert interpreted.stdout == (b"" if reached else b"42\n"), outcome(interpreted)