Skip to content

Commit

Permalink
Forward non-positive arg keys
Browse files Browse the repository at this point in the history
This updates the helper loader and output handler loader to forward
non-positive command-line argument keys, that are automatically inserted
by the Lua interpreter, to the helper and output handler, respectively.
  • Loading branch information
o-lim committed Aug 29, 2016
1 parent 2d92840 commit 98840f4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
6 changes: 4 additions & 2 deletions busted/modules/helper_loader.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions busted/modules/output_handler_loader.lua
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
11 changes: 11 additions & 0 deletions busted/utils.lua
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion spec/cl_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 98840f4

Please sign in to comment.