diff --git a/busted/modules/helper_loader.lua b/busted/modules/helper_loader.lua index 693b903d..56ae6673 100644 --- a/busted/modules/helper_loader.lua +++ b/busted/modules/helper_loader.lua @@ -1,11 +1,13 @@ local path = require 'pl.path' local hasMoon, moonscript = pcall(require, 'moonscript') +local utils = require 'busted.utils' return function() local loadHelper = function(busted, helper, options) - local old_arg = arg + local old_arg = _G.arg local success, err = pcall(function() - arg = options.arguments + utils.copy_interpreter_args(options.arguments) + _G.arg = options.arguments if helper:match('%.lua$') then dofile(path.normpath(helper)) elseif hasMoon and helper:match('%.moon$') then diff --git a/busted/modules/output_handler_loader.lua b/busted/modules/output_handler_loader.lua index 41c45d4e..ab93e4c6 100644 --- a/busted/modules/output_handler_loader.lua +++ b/busted/modules/output_handler_loader.lua @@ -1,10 +1,12 @@ local path = require 'pl.path' local hasMoon, moonscript = pcall(require, 'moonscript') +local utils = require 'busted.utils' return function() local loadOutputHandler = function(busted, output, options) local handler + utils.copy_interpreter_args(options.arguments) local success, err = pcall(function() if output:match('%.lua$') then handler = dofile(path.normpath(output)) diff --git a/busted/utils.lua b/busted/utils.lua index 75f4b5d9..bf771487 100644 --- a/busted/utils.lua +++ b/busted/utils.lua @@ -1,4 +1,15 @@ return { + copy_interpreter_args = function(arguments) + -- copy non-positive command-line args auto-inserted by Lua interpreter + if arguments and _G.arg then + local i = 0 + while _G.arg[i] do + arguments[i] = _G.arg[i] + i = i - 1 + end + end + end, + split = require 'pl.utils'.split, shuffle = function(t, seed) diff --git a/spec/cl_spec.lua b/spec/cl_spec.lua index 36c15ecd..46441421 100644 --- a/spec/cl_spec.lua +++ b/spec/cl_spec.lua @@ -301,7 +301,7 @@ describe('Test busted running standalone', function() assert.is_false(success) end) - it('tests running with via stdin', function() + it('tests running via stdin', function() local success, errcnt = executeLua('< spec/cl_standalone.lua') assert.is_false(success) assert.is_equal(3, errcnt)