lean4-htt/tests/lean/run/getline_crash.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

163 lines
3.5 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

def tstGetLine (str : String) : IO Unit := do
let path := "tmp_file";
IO.FS.withFile path IO.FS.Mode.write $ λ (h : IO.FS.Handle) =>
h.putStrLn str;
IO.FS.withFile path IO.FS.Mode.read $ λ (h : IO.FS.Handle) => do
let str' ← h.getLine;
IO.println str.length;
IO.println str'.length;
IO.print str';
unless (str'.length == str.length + 1) do
throw (IO.userError ("unexpected length: " ++ toString str'.trim.length));
unless (str'.trim == str) do
throw (IO.userError ("unexpected result: " ++ str'))
def tstGetLine2 (str1 str2 : String) : IO Unit := do
let path := "tmp_file";
IO.FS.withFile path IO.FS.Mode.write $ λ (h : IO.FS.Handle) => do {
h.putStrLn str1; h.putStr str2
};
IO.FS.withFile path IO.FS.Mode.read $ λ (h : IO.FS.Handle) => do
let str1' ← h.getLine;
let str2' ← h.getLine;
unless (str1'.length == str1.length + 1) do
throw (IO.userError ("unexpected length: " ++ toString str1'.trim.length));
unless (str1'.trim == str1) do
throw (IO.userError ("unexpected result: " ++ str1'));
unless (str2'.length == str2.length) do
throw (IO.userError ("unexpected length: " ++ toString str2'.trim.length));
unless (str2'.trim == str2) do
throw (IO.userError ("unexpected result: " ++ str2'))
def tstGetLine3 (str : String) : IO Unit := do
let path := "tmp_file";
IO.FS.withFile path IO.FS.Mode.write $ λ (h : IO.FS.Handle) => do {
h.putStrLn str
};
IO.FS.withFile path IO.FS.Mode.read $ λ (h : IO.FS.Handle) => do
(h.getLine >>= IO.println);
(h.getLine >>= IO.println);
(h.getLine >>= IO.println);
IO.print "done";
pure ()
/--
info: abc
done
-/
#guard_msgs in
#eval tstGetLine3 "abc"
/--
info: 40
41
αααααααααααααααααααααααααααααααααααααααα
-/
#guard_msgs in
#eval tstGetLine ("".pushn 'α' 40)
/--
info: 1
2
a
-/
#guard_msgs in
#eval tstGetLine "a"
/--
info: 0
1
-/
#guard_msgs in
#eval tstGetLine ""
/--
info: 20
21
αααααααααααααααααααα
-/
#guard_msgs in
#eval tstGetLine ("".pushn 'α' 20)
/--
info: 61
62
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-/
#guard_msgs in
#eval tstGetLine ("".pushn 'a' 61)
/--
info: 61
62
ααααααααααααααααααααααααααααααααααααααααααααααααααααααααααααα
-/
#guard_msgs in
#eval tstGetLine ("".pushn 'α' 61)
/--
info: 62
63
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-/
#guard_msgs in
#eval tstGetLine ("".pushn 'a' 62)
/--
info: 63
64
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-/
#guard_msgs in
#eval tstGetLine ("".pushn 'a' 63)
/--
info: 64
65
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-/
#guard_msgs in
#eval tstGetLine ("".pushn 'a' 64)
/--
info: 65
66
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-/
#guard_msgs in
#eval tstGetLine ("".pushn 'a' 65)
/--
info: 66
67
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-/
#guard_msgs in
#eval tstGetLine ("".pushn 'a' 66)
/--
info: 128
129
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-/
#guard_msgs in
#eval tstGetLine ("".pushn 'a' 128)
/-- info: -/
#guard_msgs in
#eval tstGetLine2 ("".pushn 'α' 20) ("".pushn 'β' 20)
/-- info: -/
#guard_msgs in
#eval tstGetLine2 ("".pushn 'α' 40) ("".pushn 'β' 40)
/-- info: -/
#guard_msgs in
#eval tstGetLine2 ("".pushn 'a' 61) ("".pushn 'b' 61)
/-- info: -/
#guard_msgs in
#eval tstGetLine2 ("".pushn 'a' 61) ("".pushn 'b' 62)