lua-users home
lua-l archive

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


Add the "local print = print" does fix help.

And thanks for pointing to some good example code.  That helps a lot.

Dan


On Thu, May 12, 2016 at 2:20 AM, Alexey Melnichuk
<alexeymelnichuck@gmail.com> wrote:
> Hello.
>
>> I'm running into an odd syntax error when running lunitx under luajit 2.0.
>
>> $ luajit test_libcrypt.lua --help
>> luajit: /usr/local/share/lua/5.1/lunit.lua:737: attempt to call global
>> 'print' (a nil value)
>> stack traceback:
>>         /usr/local/share/lua/5.1/lunit.lua:737: in function 'main'
>>         test_libcrypt.lua:44: in main chunk
>
> To solve this one you can do `local print = print`
>
>> #!/usr/bin/env luajit
>> require('lunit')
>> if _VERSION >= 'Lua 5.2' then
>>     _ENV = lunit.module('test_libcrypt','seeall')
>> else
>>     module("test_libcrypt", lunit.testcase, package.seeall) -- mark this as a test case
>> end
>
> lunitx  has  `TEST_CASE` function to so you do not need use this `if`.
> Just use this one
>
>> local lunit = require('lunit')
>> local _ENV = lunit.TEST_CASE'test_libcrypt'
>
>
>> if arg[0]:match("[._%w]*$") == 'test_libcrypt.lua' then
>>    lunit.main(arg)
>> end
>
> I  prefer  check  global  `lunit`  variable before `require` to detect
> ether this script was run as standalone or from `lunitx.sh` or as part
> of other module. I use this function
>
>> local lunit = lunit
>> local RUN = lunit and function()end or function ()
>>   local res = lunit.run()
>>   if res.errors + res.failed > 0 then os.exit(-1) end
>>   return os.exit(0)
>> end
>> lunit = require "lunit"
>> ...
>> RUN()
>
>
> PS. You can checkout my tests e.g. https://github.com/moteus/lua-gntp/blob/master/test/test.lua
>
>
>
>
>
> ---
> Это сообщение проверено на вирусы антивирусом Avast.
> https://www.avast.com/antivirus
>
>