improve failed test reporting

This commit is contained in:
Daniel Barlow 2024-04-20 21:46:37 +01:00
parent 712c9b266f
commit e34135c41a

View file

@ -31,8 +31,14 @@
(tset db e.path e))) (tset db e.path e)))
})) }))
(var failed false)
(fn fail [d msg] (set failed true) (print :FAIL d (.. "\n" msg)))
(macro example [description & body] (macro example [description & body]
`(do ,body)) `(let [(ok?# err#) (xpcall (fn [] ,body) debug.traceback)]
(if ok?#
(print :PASS ,description)
(fail ,description err#))))
(example (example
"given an empty database, searching it finds no entries" "given an empty database, searching it finds no entries"
@ -74,5 +80,4 @@ SEQNUM=1527")
(if failed (os.exit 1) (print "OK"))
(print "OK")