-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathEqualUpToIds.lean
77 lines (67 loc) · 2.26 KB
/
EqualUpToIds.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/-
Copyright (c) 2023 Jannis Limperg. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jannis Limperg
-/
import Aesop.Util.Basic
import Aesop.Util.EqualUpToIds
import Aesop.Tree.RunMetaM
-- Some simple test cases for the EqualUpToIds module. The module is mostly
-- tested by using it in script validation, which is run on almost all Aesop
-- calls in the test suite.
open Aesop Lean Lean.Elab.Tactic
def assertEqualTactics (t₁ t₂ : TacticM Unit) : TacticM Unit := do
let commonMCtx ← getMCtx
let preState ← show MetaM _ from saveState
let preGoals ← getGoals
let (state₁, goals₁) ← runTacticMCapturingPostState t₁ preState preGoals
let (state₂, goals₂) ← runTacticMCapturingPostState t₂ preState preGoals
let eq ←
tacticStatesEqualUpToIds commonMCtx state₁.meta.mctx state₂.meta.mctx
goals₁.toArray goals₂.toArray
if ! eq then
throwError "Tactics produced different tactic states.\nTactic 1:{indentD $ ← ppTacticState state₁ goals₁}\nTactic 2:{indentD $ ← ppTacticState state₂ goals₂}\n"
where
ppTacticState (state : Meta.SavedState) (goals : List MVarId) :
MetaM MessageData :=
state.runMetaM' do
addMessageContext $ .joinSep (goals.map toMessageData) "\n"
open Lean.Elab.Tactic in
elab &"assert_equal_tactics "
" { " ts₁:tacticSeq " } " " { " ts₂:tacticSeq " } " : tactic => do
assertEqualTactics (evalTactic ts₁) (evalTactic ts₂)
example : True := by
assert_equal_tactics { trivial } { trivial }
trivial
example : True := by
assert_equal_tactics { open Classical in trivial } { trivial }
trivial
/--
error: Tactics produced different tactic states.
Tactic 1:
case zero
m : Nat
⊢ True
case succ
m n✝ : Nat
⊢ True
Tactic 2:
case zero
n : Nat
⊢ True
case succ
n n✝ : Nat
⊢ True
-/
#guard_msgs in
example (n m : Nat) : True := by
assert_equal_tactics { cases n } { cases m }
trivial
example : 0 < 3 := by
apply Nat.lt_trans
assert_equal_tactics { exact Nat.lt_succ_self 0 } { exact Nat.lt_succ_self 0 }
(case m => exact 1); all_goals decide
example : 0 < 3 := by
apply Nat.lt_trans
assert_equal_tactics { apply Nat.lt_trans } { apply Nat.lt_trans }
(case m => exact 1); all_goals decide