liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

assert.fnl (643B)


      1 ;; these are macros; this module should be imported
      2 ;; using import-macros
      3 
      4 ;; e.g. (import-macros { : expect= } :anoia.assert)
      5 
      6 (fn expect [assertion]
      7   (let [msg (.. "expectation failed: " (view assertion))]
      8     `(when (not ,assertion)
      9        (assert false ,msg))))
     10 
     11 (fn expect= [actual expected]
     12   `(let [view# (. (require :fennel) :view)
     13          ve# (view# ,expected)
     14          va# (view# ,actual)]
     15      (when (not (= ve# va#))
     16        (assert false
     17                (.. "\nexpected " ve# "\ngot " va#)
     18                ))))
     19 
     20 (fn define-tests [& body]
     21   (when _G.RUNNING_TESTS
     22     `(do ,(unpack body))))
     23 
     24 { : define-tests : expect : expect=  }