lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hi, a summary of questions:
1. Does Lunit work under strict?
2. How do I use strictness file scoped?
3. Does loadfile follow the Lua path?

And the long story:
I'm trying to use Lunit 0.4 for work. Since I'm in Windows I replaced the Bash script doing the testing with a bit of Lua code which runs in the app in which Lua Plus is integrated. However, when I run the app running lunit, and the code being tested, both of which require strict, strict complains about LUnit internals.

How can I use Lunit and still write code under strict? Seems to me that as long as my code running LUnit has anything included that includes strict, I'm in trouble. I've read the strict source and often for global assignments saying:

__STRICT = false

temporarily, does get rid of the problem. HOwever, not in this case. Or else I'm just not thinking clearly at the moment. Can strict be made a truely file scoped pragma as in Perl?

I also have a final question. I'd like to respect the app's path in which Lua (Plus) is integrated, which require happily does. HOwever, lunit seems to load its code via loadfile, in stead, and not pass my modules their name as the first variable arg, I guess - among other things. Does loadfile respect the luapath? I thought it would not.

Finally, some sample code of how I'm running Lunit follows:

function Run(...)
  require "lunit" -- The framework doing the hard work.
  local old_out = io.output() -- Save away our stdout before logging.
  for k, basename in ipairs({ ... }) do
     local filename, logname = basename .. ".lua", basename .. ".log"
     local out, message =, "w")
     if not out then error(message) end
     -- Lunit does all the work here.
     rawset(_G, 'myerror', error) -- For custom Lunit errors.
     lunit.main{filename} -- The testing happens here.
     rawset(_G, 'myerror', nil)
     -- Work done.
     io.output(old_out) -- errors on loading next file get to stdout.

With kind regards Veli-Pekka Tätilä
Accessibility, Apps and Coding plus Synths and Music: