Skip to content

Commit

Permalink
Add --no-auto-insulate command-line flag
Browse files Browse the repository at this point in the history
This flag disables automatic test insulation at the file level. When
this flag is enabled, all test insulation must be explicit, using the
`insulate` block. The file context will still wrap itself in a `setfenv`
sandbox, but the global tables `_G` and `package.loaded` will not be
saved/restored.
  • Loading branch information
o-lim committed Mar 19, 2015
1 parent 47e0bfe commit ce5afb8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions busted/modules/cli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ return function(options)
cli:add_flag('-s, --enable-sound', 'executes `say` command if available', processOption)
cli:add_flag('-l, --list', 'list the names of all tests instead of running them', processOption)
cli:add_flag('--lazy', 'use lazy setup/teardown as the default', processOption)
cli:add_flag('--no-auto-insulate', 'disable file insulation', processOption)
cli:add_flag('--no-keep-going', 'quit after first error or failure', processOption)
cli:add_flag('--no-recursive', 'do not recurse into subdirectories', processOption)
cli:add_flag('--shuffle', 'randomize file and test order, takes precedence over --sort (--shuffle-test and --shuffle-files)', processOption)
Expand Down
5 changes: 5 additions & 0 deletions busted/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ return function(options)
luacov()
end

-- If auto-insulate is disabled, re-register file without insulation
if cliArgs['no-auto-insulate'] then
busted.register('file', 'file', {})
end

-- If lazy is enabled, make lazy setup/teardown the default
if cliArgs.lazy then
busted.register('setup', 'lazy_setup')
Expand Down
1 change: 1 addition & 0 deletions completions/bash/busted.bash
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ _busted() {
-Xoutput
-Xhelper
--lazy
--no-auto-insulate
--no-keep-going
--no-recursive
--shuffle --shuffle-tests --shuffle-files
Expand Down
1 change: 1 addition & 0 deletions completions/zsh/_busted
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ _busted_args=(
"--version[Prints the program version and exits]"
"(-l --list)"{-l,--list}"[List the names of all tests instead of running them]"
"--lazy[Use lazy setup/teardown as the default]"
"--no-auto-insulate[Disable file insulation]"
"--no-keep-going[Quit after first error or failure]"
"--no-recursive[Do not recurse into subdirectories]"
"--helper[A helper script that is run before tests]:files:_files"
Expand Down
11 changes: 11 additions & 0 deletions spec/cl_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,17 @@ describe('Tests no-recursive commandline option', function()
end)
end)

describe('Tests no-auto-insulate commandline option', function()
it('does not insulate test files', function()
local success, exitcode
error_start()
success, exitcode = execute(busted_cmd .. ' --no-auto-insulate --pattern=insulate_file.*.lua$')
assert.is_false(success)
assert.is_equal(1, exitcode)
error_end()
end)
end)

describe('Tests Xoutput commandline option', function()
it('forwards no options to output handler when no options specified', function()
local result = run(busted_cmd .. ' --output=spec/cl_output_handler.lua --pattern=cl_success.lua$')
Expand Down

0 comments on commit ce5afb8

Please sign in to comment.