Many of our tests in `tests/lean/run/` produce output from `#eval` (or `#check`) statements, that is then ignored. This PR tries to capture all the useful output using `#guard_msgs`. I've only done a cursory check that the output is still sane --- there is a chance that some "unchecked" tests have already accumulated regressions and this just cements them! In the other direction, I did identify two rotten tests: * a minor one in `setStructInstNotation.lean`, where a comment says `Set Nat`, but `#check` actually prints `?_`. Weird? * `CompilerProbe.lean` is generating empty output, apparently indicating that something is broken, but I don't know the signficance of this file. In any case, I'll ask about these elsewhere. (This started by noticing that a recent `grind` test file had an untested `trace_state`, and then got carried away.)
103 lines
1.6 KiB
Text
103 lines
1.6 KiB
Text
abbrev M := StateRefT Nat IO
|
||
|
||
def testM {α} [ToString α] [BEq α] (init : Nat) (expected : α) (x : M α): IO Unit := do
|
||
let v ← x.run' init
|
||
IO.println ("result " ++ toString v)
|
||
unless v == expected do
|
||
throw $ IO.userError "unexpected"
|
||
|
||
def dec (x : Nat) : M Unit := do
|
||
if (← get) == 0 then
|
||
throw $ IO.userError "value is zero"
|
||
modify (· - x)
|
||
|
||
def f1 (x : Nat) : M Nat := do
|
||
let v ←
|
||
try
|
||
dec x
|
||
return x
|
||
catch _ =>
|
||
return 1
|
||
|
||
def f2 (xs : List Nat) : M Nat := do
|
||
let mut sum := 0
|
||
for x in xs do
|
||
try
|
||
dec x
|
||
sum := sum + x
|
||
if sum > 100 then
|
||
break
|
||
continue
|
||
catch _ =>
|
||
break
|
||
return sum
|
||
|
||
/-- info: result 6 -/
|
||
#guard_msgs in
|
||
#eval testM 100 6 $ f2 [1, 2, 3]
|
||
|
||
/-- info: result 101 -/
|
||
#guard_msgs in
|
||
#eval testM 200 101 $ f2 [1, 100, 200, 300]
|
||
|
||
/-- info: result 1 -/
|
||
#guard_msgs in
|
||
#eval testM 1 1 $ f2 [1, 100, 200, 300]
|
||
|
||
def f3 (xs : List Nat) : M Nat := do
|
||
let mut sum := 0
|
||
for x in xs do
|
||
try
|
||
dec x
|
||
sum := sum + x
|
||
if sum > 100 then
|
||
return sum
|
||
continue
|
||
catch _ =>
|
||
return sum
|
||
return sum
|
||
|
||
/-- info: result 6 -/
|
||
#guard_msgs in
|
||
#eval testM 100 6 $ f3 [1, 2, 3]
|
||
|
||
/-- info: result 101 -/
|
||
#guard_msgs in
|
||
#eval testM 200 101 $ f3 [1, 100, 200, 300]
|
||
|
||
/-- info: result 1 -/
|
||
#guard_msgs in
|
||
#eval testM 1 1 $ f3 [1, 100, 200, 300]
|
||
|
||
def f4 (xs : Array Nat) : IO Nat := do
|
||
let mut sum := 0
|
||
for x in xs do
|
||
sum := sum + x
|
||
IO.println x
|
||
return sum
|
||
|
||
/--
|
||
info: 1
|
||
2
|
||
3
|
||
6
|
||
-/
|
||
#guard_msgs in
|
||
#eval f4 #[1, 2, 3]
|
||
|
||
def f5 (xs : Array Nat) : IO Nat := do
|
||
let mut sum := 0
|
||
for x in xs[1 : xs.size - 1] do
|
||
sum := sum + x
|
||
IO.println x
|
||
return sum
|
||
|
||
/--
|
||
info: 2
|
||
3
|
||
4
|
||
5
|
||
14
|
||
-/
|
||
#guard_msgs in
|
||
#eval f5 #[1, 2, 3, 4, 5, 6]
|