describe macro supports tests inline in code
convert existing asserts to use it
This commit is contained in:
+22
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user