lunarmodules / busted

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

Remove use of global variable #620

Closed piotrp closed 4 years ago

piotrp commented 4 years ago

Remove write to global variable

Without this running busted under OpenResty 1.15+ results in this warning printed to stdout:

root@e9980e927ece:/etc/nginx/spec# ./lua-tests.sh -o junit
2019/11/25 22:35:32 [warn] 732#732: *2 [lua] _G write guard:12: __newindex(): writing a global lua variable ('output_file_name') which may lead to race conditions between concurrent requests, so prefer the use
of 'local' variables
stack traceback:
        ...sty/luajit/share/lua/5.1/busted/outputHandlers/junit.lua:21: in function 'handler'
        ...t/share/lua/5.1/busted/modules/output_handler_loader.lua:33: in function 'outputHandlerLoader'
        /usr/lib/openresty/luajit/share/lua/5.1/busted/runner.lua:130: in function </usr/lib/openresty/luajit/share/lua/5.1/busted/runner.lua:11>
        /usr/bin/busted:36: in function 'file_gen'
        init_worker_by_lua:61: in function <init_worker_by_lua:59>
        [C]: in function 'xpcall'
        init_worker_by_lua:68: in function <init_worker_by_lua:66>, context: ngx.timer
Tieske commented 4 years ago

lgtm