Debian Codegraph @

test-suite/output/ltac2_print_exn.v

raw
1 Require Import Ltac2.Ltac2.
2 Import Printf.
3
4 (** basic test, we also check that the backtrace isn't forgotten when
5 using the custom printer *)
6
7 Set Ltac2 Backtrace.
8
9 Ltac2 foo () := Control.zero (Tactic_failure (Some (Message.of_string "hello"))).
10
11 Fail Ltac2 Eval foo ().
12
13 Unset Ltac2 Backtrace.
14
15 (** Test printing constr even though we have a bad evar map *)
16
17 Ltac2 Type exn ::= [ WithTerm (constr) ].
18
19 Ltac2 bar () :=
20 let c := open_constr:(_ :> nat) in
21 Control.zero (WithTerm c).
22
23 (* default printer doesn't have the evar map but doesn't fail *)
24 Fail Ltac2 Eval bar ().
25
26 Ltac2 Set Control.print_exn := fun e =>
27 match e with
28 | WithTerm c => Some (fprintf "test %t" c)
29 | _ => None
30 end.
31
32 (* custom printer also doesn't have the evar map but doesn't fail *)
33 Fail Ltac2 Eval bar ().
34
35 (** Test custom printer producing an error *)
36 Ltac2 Set Control.print_exn := fun _ => Control.throw Assertion_failure.
37
38 Fail Ltac2 Eval foo ().