lean4-htt/tests/lean/run/traceFormat.lean
Joachim Breitner 0e49576fe4
feat: guard_msgs to treat trace messages separate (#8267)
This PR makes `#guard_msgs` to treat `trace` messages separate from
`info`, `warning` and `error`. It also introduce the ability to say
`#guard_msgs (pass info`, like `(drop info)` so far, and also adds
`(check info)` as the explicit form of `(info)`, for completeness.

Fixes #8266
2025-05-09 05:44:34 +00:00

62 lines
1.6 KiB
Text

import Lean.CoreM
/-!
Tests formatting of traces in various combinations, on the cmdline automatically via `#guard_msgs`
and in the info view via manual testing.
-/
open Lean
def withNode (cls : Name) (msg : MessageData) (k : CoreM Unit) (collapsed := true) (tag := "") : CoreM Unit := do
let oldTraces ← getTraces
modifyTraces fun _ => {}
k
let ref ← getRef
let mut data := { cls, collapsed, tag }
let msg := .trace data msg ((← getTraces).toArray.map (·.msg))
modifyTraces fun _ =>
oldTraces.push { ref, msg }
/--
trace: [test] top-level leaf
[test] top-level leaf
[test] node with single leaf
[test] leaf
[test] node with adjacent leafs
[test] leaf
[test] leaf
[test] nested nodes
[test] leaf
[test] node
[test] leaf
[test] leaf
[test] uncollapsed node
[test] leaf
[test] node
[test] leaf
[test] leaf
[test] node with nested newline
[test] line1
line2
-/
#guard_msgs in
#eval show CoreM Unit from do
addTrace `test "top-level leaf"
addTrace `test "top-level leaf"
withNode `test "node with single leaf" do
addTrace `test "leaf"
withNode `test "node with adjacent leafs" do
addTrace `test "leaf"
addTrace `test "leaf"
withNode `test "nested nodes" do
addTrace `test "leaf"
withNode `test "node" do
addTrace `test "leaf"
addTrace `test "leaf"
withNode `test "uncollapsed node" (collapsed := false) do
addTrace `test "leaf"
withNode `test "node" do
addTrace `test "leaf"
addTrace `test "leaf"
withNode `test "node with nested newline" do
addTrace `test "line1\nline2"