[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Syntax error with lunitx and luajit
- From: Alexey Melnichuk <alexeymelnichuck@...>
- Date: Thu, 12 May 2016 12:20:05 +0300
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