Skip to content

Commit

Permalink
Use #guard_msgs in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusrossel committed Apr 24, 2024
1 parent 7b1943b commit 17af42f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 39 deletions.
6 changes: 4 additions & 2 deletions Lean/Egg/Tests/Ambient MVar.lean
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Egg
import Lean

example (h : ∀ x : Prop, True = x) : True = True := by
variable (h : ∀ x : Prop, True = x)

example : True = True := by
apply Eq.trans
· egg [h]
· rfl -- This assigns the mvar resulting from `Eq.trans`.
Expand All @@ -13,7 +15,7 @@ h : ∀ (x : Prop), True = x
⊢ Prop
-/
#guard_msgs in
example (h : ∀ x : Prop, True = x) : True = True := by
example : True = True := by
apply Eq.trans
· egg [h]
· egg [h]
23 changes: 14 additions & 9 deletions Lean/Egg/Tests/Basic.lean
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import Egg

example : True := by
fail_if_success have : true = false := by egg
constructor
/-- error: egg failed to prove goal -/
#guard_msgs in
example : true = false := by
egg

/--
error: expected goal to be of type '=' or '↔', but found:
True
-/
#guard_msgs in
example : True := by
fail_if_success have : True := by egg
constructor
egg

example : True := by
fail_if_success have : true = true := by egg [true]
constructor
/-- error: egg requires arguments to be theorems or definitions -/
#guard_msgs in
example : true = true := by
egg [true]

set_option trace.egg true in
example : 0 = 0 := by
egg

Expand Down
17 changes: 8 additions & 9 deletions Lean/Egg/Tests/BlockInvalidMatches.lean
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@ example : False := by
contradiction

-- This test covers Condition (2) of valid matches.
/-- error: egg failed to prove goal -/
#guard_msgs in
set_option egg.blockInvalidMatches true in
example : True := by
fail_if_success -- This fails because egg could not find a proof.
have : (fun x => (fun a => (fun a => a) a) 0) = (fun x => x) := by
egg (config := { exitPoint := some .beforeProof }) [thm]
constructor
example : (fun x => (fun a => (fun a => a) a) 0) = (fun x => x) := by
egg (config := { exitPoint := some .beforeProof }) [thm₁]

-- This theorem is only applicable in the backward direction.
theorem thm₂ : ∀ x y : Nat, x = (fun _ => x) y :=
fun _ _ => rfl

-- This test covers Condition (1) of valid matches.
set_option egg.blockInvalidMatches true in
example : True := by
fail_if_success -- This fails because egg could not find a proof.
have : (fun x => x) = (fun _ : Nat => (fun x => x) 1) := by egg [thm₂]
constructor
/-- error: egg failed to prove goal -/
#guard_msgs in
example : (fun x => x) = (fun _ : Nat => (fun x => x) 1) := by
egg [thm₂]
10 changes: 6 additions & 4 deletions Lean/Egg/Tests/Eta.lean
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ set_option egg.genEtaRw true
set_option egg.genBetaRw false

set_option egg.genEtaRw false in
/-- error: egg failed to prove goal -/
#guard_msgs in
example : (fun x => Nat.succ x) = Nat.succ := by
fail_if_success egg
rfl
egg

example : (fun x => Nat.succ x) = Nat.succ := by
egg
Expand Down Expand Up @@ -44,9 +45,10 @@ example : (eta 10 Nat.succ Nat) = Nat.succ := by
egg

set_option egg.genEtaRw false in
/-- error: egg failed to prove goal -/
#guard_msgs in
example (a : Nat) (h : ∀ b : Nat, b.succ.add a = 0) : (10 |> fun x => Nat.succ x).add a = 0 := by
fail_if_success egg [h]
apply h
egg [h]

example (a : Nat) (h : ∀ b : Nat, b.succ.add a = 0) : (10 |> fun x => Nat.succ x).add a = 0 := by
egg [h]
Expand Down
5 changes: 3 additions & 2 deletions Lean/Egg/Tests/NatLit.lean
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ example : 12345 % 0 = 12345 := by
egg

set_option egg.natReduceRws false in
/-- error: egg failed to prove goal -/
#guard_msgs in
example (h : ∀ f : Nat → Nat, f (1 + 1) = x) : id 2 = x := by
fail_if_success egg [h]
apply h
egg [h]

example (h : ∀ f : Nat → Nat, f (1 + 1) = x) : id 2 = x := by
egg [h]
Expand Down
8 changes: 4 additions & 4 deletions Lean/Egg/Tests/ShiftCapturedBVars.lean
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ example : False := by
contradiction

set_option egg.shiftCapturedBVars true in
example : True := by
fail_if_success -- This fails because egg could not find a proof.
have : (fun x => (x, 5).fst) = (fun _ : Nat => (fun x => x) 1) := by egg [thm₁]
constructor
/-- error: egg failed to prove goal -/
#guard_msgs in
example : (fun x => (x, 5).fst) = (fun _ : Nat => (fun x => x) 1) := by
egg [thm₁]
22 changes: 13 additions & 9 deletions Lean/Egg/Tests/Star.lean
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@ import Egg

-- Tests for the `*` argument.

example : True := by
fail_if_success have : true = false := by egg [*]
constructor
/-- error: egg failed to prove goal -/
#guard_msgs in
example : true = false := by
egg [*]

/-- error: egg failed to prove goal -/
#guard_msgs in
example (_ : true = true) : [true] ++ [] = [true] := by
fail_if_success egg [*]
rfl
egg [*]

/-- error: duplicate '*' in arguments to egg -/
#guard_msgs in
example : 0 = 0 := by
fail_if_success egg [*, *]
rfl
egg [*, *]

/-- error: duplicate '*' in arguments to egg -/
#guard_msgs in
example (h : 0 = 0) : 0 = 0 := by
fail_if_success egg [*, h, *]
rfl
egg [*, h, *]

example : 0 = 0 := by
egg [*]
Expand Down

0 comments on commit 17af42f

Please sign in to comment.