lean4-htt/tests/lean/run/structure.lean
Kim Morrison 3a457e6ad6
chore: use #guard_msgs in run tests (#4175)
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.)
2024-05-16 00:38:31 +00:00

59 lines
1.4 KiB
Text

import Lean
open Lean
structure S1 :=
(x y : Nat)
structure S2 extends S1 :=
(z : Nat)
structure S3 :=
(w : Nat)
structure S4 extends S2, S3 :=
(s : Nat)
def check (b : Bool) : CoreM Unit :=
unless b do throwError "check failed"
class S5 :=
(x y : Nat)
inductive D
| mk (x y z : Nat) : D
def tst : CoreM Unit :=
do let env ← getEnv
IO.println (getStructureFields env `Lean.Environment)
check $ getStructureFields env `S4 == #[`toS2, `toS3, `s]
check $ getStructureFields env `S1 == #[`x, `y]
check $ isSubobjectField? env `S4 `toS2 == some `S2
check $ getParentStructures env `S4 == #[`S2, `S3]
check $ findField? env `S4 `x == some `S1
check $ findField? env `S4 `x1 == none
check $ isStructure env `S1
check $ isStructure env `S2
check $ isStructure env `S3
check $ isStructure env `S4
check $ isStructure env `S5
check $ !isStructure env `Nat
check $ !isStructure env `D
IO.println (getStructureFieldsFlattened env `S4)
IO.println (getStructureFields env `D)
IO.println (getPathToBaseStructure? env `S1 `S4)
IO.println (getParentStructures env `S4)
IO.println (getAllParentStructures env `S4)
check $ getPathToBaseStructure? env `S1 `S4 == some [`S4.toS2, `S2.toS1]
pure ()
/--
info: #[const2ModIdx, constants, extensions, extraConstNames, header]
#[toS2, toS1, x, y, z, toS3, w, s]
#[]
(some [S4.toS2, S2.toS1])
#[S2, S3]
#[S2, S1, S3]
-/
#guard_msgs in
#eval tst