Skip to content

Commit d12672a

Browse files
committed
add test demonstrating problems with formatting
this test looks right, and if you run with `UPDATE_EXPECT=1` it is not changed, but if you run without it, you get an error
1 parent 29cb1c8 commit d12672a

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use anyhow::Context;
2+
use formality_core::{judgment_fn, term, test, test_util::ResultTestExt, Fallible};
3+
4+
#[term]
5+
enum Ty {
6+
Class { name: ClassName },
7+
}
8+
9+
formality_core::id!(ClassName);
10+
11+
judgment_fn! {
12+
fn sub(
13+
a: Ty,
14+
b: Ty,
15+
) => () {
16+
debug(a, b)
17+
18+
(
19+
(if name_a == name_b)
20+
---------------------- ("same class")
21+
(sub(Ty::Class { name: name_a }, Ty::Class { name: name_b }) => ())
22+
)
23+
}
24+
}
25+
26+
fn check_sub(a: Ty, b: Ty) -> Fallible<()> {
27+
Ok(sub(a, b)
28+
.check_proven()
29+
.with_context(|| format!("check_sub"))?)
30+
}
31+
32+
#[test]
33+
fn test() {
34+
let foo = Ty::Class {
35+
name: ClassName::new("Foo"),
36+
};
37+
let bar = Ty::Class {
38+
name: ClassName::new("Bar"),
39+
};
40+
// Demonstrates a multi-line error rendered by anyhow.
41+
check_sub(foo, bar).assert_err(expect_test::expect![[r#"
42+
check_sub
43+
44+
Caused by:
45+
judgment `sub { a: class(Foo), b: class(Bar) }` failed at the following rule(s):
46+
the rule "same class" failed at step #0 (src/file.rs:LL:CC) because
47+
condition evaluted to false: `name_a == name_b`
48+
"#]]);
49+
}

tests/judgment-error-reporting/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ formality_core::declare_language! {
2020
use jer::FormalityLang;
2121

2222
mod cyclic_judgment;
23+
mod fallible;
2324
mod grammar;
2425

2526
fn main() -> Fallible<()> {

0 commit comments

Comments
 (0)