lunarmodules / busted

Elegant Lua unit testing.
https://lunarmodules.github.io/busted/
MIT License
1.38k stars 184 forks source link

Implement loader for Fennel #740

Open HiPhish opened 4 months ago

HiPhish commented 4 months ago

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 commented 4 months ago

Thank you for your response. I have amended the commit message.

We should probably add a test.

Maybe I am missing something here, but it does not look like there are any loader tests. There is the file spec/modules/file_loader_spec.lua, but all it does is require and call a module, but it does not do anything with the results.

and maybe make it an optional test for local testing for folks that don't have Fennel setup.

That's simple enough, we can pcall(require, 'fennel') in the test; if the call errors then Fennel is not available and we can skip the Fennel loader.

I don't have any Fennel expertise

Fennel is pretty much just Lua with Lisp notation (some special forms plus a macro system), so it maps very closely to Lua.

HiPhish commented 4 months ago

I just pushed an update that does two things:

Previously the code was working under the assumption that compilation would always succeed.

HiPhish commented 4 months ago

feel free to poke again if this falls off my radar

poke @alerque

offsetcyan commented 4 days ago

poke @alerque