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-01-03 04:06:23 +00:00
|
|
|
(var numchecks 0)
|
2018-03-26 01:25:33 +00:00
|
|
|
|
|
|
|
(defn assert [x e]
|
|
|
|
(++ num-tests-run)
|
|
|
|
(when x (++ num-tests-passed))
|
2019-01-03 04:06:23 +00:00
|
|
|
(if x
|
|
|
|
(do
|
|
|
|
(when (= numchecks 25)
|
|
|
|
(set numchecks 0)
|
|
|
|
(print))
|
|
|
|
(++ numchecks)
|
|
|
|
(file/write stdout "\e[32m✔\e[0m"))
|
|
|
|
(do
|
2019-01-06 08:23:03 +00:00
|
|
|
(file/write stdout "\n\e[31m✘\e[0m ")
|
2019-01-03 04:06:23 +00:00
|
|
|
(set numchecks 0)
|
|
|
|
(print e)))
|
2018-03-26 01:25:33 +00:00
|
|
|
x)
|
|
|
|
|
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]
|
2018-12-17 02:57:32 +00:00
|
|
|
(set suite-num x)
|
2019-01-03 04:06:23 +00:00
|
|
|
(print "\nRunning test suite " x " tests...\n "))
|
2018-03-26 01:25:33 +00:00
|
|
|
|
|
|
|
(defn end-suite []
|
2019-01-03 04:06:23 +00:00
|
|
|
(print "\n\nTest suite " suite-num " finished.")
|
2018-03-26 01:25:33 +00:00
|
|
|
(print num-tests-passed " of " num-tests-run " tests passed.\n")
|
2018-12-01 03:49:21 +00:00
|
|
|
(if (not= num-tests-passed num-tests-run) (os/exit 1)))
|