describe macro supports tests inline in code

convert existing asserts to use it
This commit is contained in:
2024-09-10 22:41:28 +01:00
parent 8ed87c7d53
commit ee4a8d28b6
6 changed files with 55 additions and 12 deletions
+22 -2
View File
@@ -1,7 +1,27 @@
(fn trace [x]
`(do
(print :trace ,(view x) (view ,x))
,x))
{ : trace }
(fn expect [assertion]
(let [msg (.. "expectation failed: " (view assertion))]
`(when (not ,assertion)
(assert false ,msg))))
(fn expect= [actual expected]
`(let [view# (. (require :fennel) :view)
ve# (view# ,expected)
va# (view# ,actual)]
(when (not (= ve# va#))
(assert false
(.. "\nexpected " ve# "\ngot " va#)
))))
(fn describe [thing & body]
(when _G.RUNNING_TESTS
`(do (print "# " ,(view thing))
,(unpack body))))
{ : trace : expect : expect= : describe }
;; NO-TESTING