lunarmodules / busted

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

[Question] Can I run busted for LÖVE-based project? #673

Closed lua-rocks closed 2 years ago

lua-rocks commented 2 years ago

Is it possible to provide access in tests to table from external application which use lua, such as love or tic80? Can I use these applications as lua interpreter for tests?

if answer == "yes" then
  how()
elseif answer == "no" then
  why()
elseif answer == nil then
  cry()
end

return thankyou()
Tieske commented 2 years ago

there's a commandline flag to set a different Lua engine. Here's an example that does the same for OpenResty: https://github.com/Olivine-Labs/busted/issues/414#issuecomment-792614808

If you get it to work, would you mind posting your solution here?

Tieske commented 2 years ago

maybe just using the --lua option is good enough?

  --lua=LUA                 The path to the lua interpreter busted
                            should run under
lua-rocks commented 2 years ago

The problem is that even though these programs use lua, they are not lua interpreters. I.e., busted should somehow be run inside them.

alerque commented 2 years ago

If LÖVE cannot be called as a Lua interpreter then you'll have to write a small wrapper to fire off the tests yourself. You can write a script and use busted.runner to run tests, but you'll want to set some environment variables first to simulate the input the runner would have gotten from the CLI.

There is some information along those lines in #482. I'm going to close this as a duplicate of that issue, but I'd be happy to re-open and discuss further if there is something I'm not understanding about LÖVE and this suggestion doesn't work out. That other issue is open to track improvements to make it easier to run in that kind of embedded mode in an already running Lua environment as a library rather than the top level tool that calls Lua.