2018-03-26 01:25:33 +00:00
|
|
|
# Helper code for running tests
|
|
|
|
|
|
|
|
(var num-tests-passed 0)
|
|
|
|
(var num-tests-run 0)
|
|
|
|
(var suite-num 0)
|
2019-12-15 02:39:14 +00:00
|
|
|
(var start-time 0)
|
2018-03-26 01:25:33 +00:00
|
|
|
|
2021-11-06 16:01:21 +00:00
|
|
|
(def is-verbose (os/getenv "VERBOSE"))
|
|
|
|
|
2020-01-16 04:38:06 +00:00
|
|
|
(defn assert
|
|
|
|
"Override's the default assert with some nice error handling."
|
2020-04-03 20:23:29 +00:00
|
|
|
[x &opt e]
|
|
|
|
(default e "assert error")
|
2019-12-15 02:39:14 +00:00
|
|
|
(++ num-tests-run)
|
|
|
|
(when x (++ num-tests-passed))
|
2020-09-27 17:18:12 +00:00
|
|
|
(def str (string e))
|
2019-12-15 02:39:14 +00:00
|
|
|
(if x
|
2021-11-13 02:04:34 +00:00
|
|
|
(when is-verbose (eprintf "\e[32m✔\e[0m %s: %v" (describe e) x))
|
|
|
|
(eprintf "\n\e[31m✘\e[0m %s: %v" (describe e) x))
|
2019-12-15 02:39:14 +00:00
|
|
|
x)
|
2018-03-26 01:25:33 +00:00
|
|
|
|
2019-01-08 17:21:11 +00:00
|
|
|
(defmacro assert-error
|
|
|
|
[msg & forms]
|
|
|
|
(def errsym (keyword (gensym)))
|
|
|
|
~(assert (= ,errsym (try (do ,;forms) ([_] ,errsym))) ,msg))
|
|
|
|
|
2019-02-22 00:19:47 +00:00
|
|
|
(defmacro assert-no-error
|
|
|
|
[msg & forms]
|
|
|
|
(def errsym (keyword (gensym)))
|
|
|
|
~(assert (not= ,errsym (try (do ,;forms) ([_] ,errsym))) ,msg))
|
|
|
|
|
2018-03-26 01:25:33 +00:00
|
|
|
(defn start-suite [x]
|
2019-12-15 02:39:14 +00:00
|
|
|
(set suite-num x)
|
|
|
|
(set start-time (os/clock))
|
2021-11-06 16:20:09 +00:00
|
|
|
(eprint "Starting suite " x "..."))
|
2018-03-26 01:25:33 +00:00
|
|
|
|
|
|
|
(defn end-suite []
|
2019-12-15 02:39:14 +00:00
|
|
|
(def delta (- (os/clock) start-time))
|
2021-11-06 16:20:09 +00:00
|
|
|
(eprinf "Finished suite %d in %.3f seconds - " suite-num delta)
|
2021-11-06 16:01:21 +00:00
|
|
|
(eprint num-tests-passed " of " num-tests-run " tests passed.")
|
2019-12-15 02:39:14 +00:00
|
|
|
(if (not= num-tests-passed num-tests-run) (os/exit 1)))
|