busted icon indicating copy to clipboard operation
busted copied to clipboard

Implement loader for Fennel

Open HiPhish opened this issue 3 months ago • 3 comments

Closes #738

Tests can be written in Fennel if fennel is among the loaders. Currently the traceback is wrong for failures and pending tests, but it is wrong for tests written in Moonscript as well, so this seems to be a general problem with busted.

It would have been cool if we could make it, describe and so on into macros to not have to manually wrap the test body inside a thunk every time.

;; With macro
(it "Adds two numbers"
  (assert.are.equal 5 (+ 2 3)))

;; Without macro
(it "Adds two numbers"
  (fn []
    (assert.are.equal 5 (+ 2 3))))

This macro can accomplish it when added to the beginning of a test:

(macro it [description & body]
  `(let [fenv# (or (and getfenv (getfenv)) _ENV)]
     ((. fenv# :it) ,description
                (fn [] ,(unpack body)))))

However, the source map produces rather weird mappings from Lua to Fennel (it maps the assertion to the body of the macro definition), so for now I won't pursue this.

HiPhish avatar Mar 09 '24 19:03 HiPhish