anoia: add assert macro module
contains expect and expect=
This commit is contained in:
21
pkgs/anoia/assert.fnl
Normal file
21
pkgs/anoia/assert.fnl
Normal file
@@ -0,0 +1,21 @@
|
||||
;; these are macros; this module should be imported
|
||||
;; using import-macros
|
||||
|
||||
;; e.g. (import-macros { : expect= } :anoia.assert)
|
||||
|
||||
|
||||
(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#)
|
||||
))))
|
||||
|
||||
{ : expect : expect= }
|
Reference in New Issue
Block a user