Skip to content

Commit

Permalink
Support --exclude-pattern command-line option
Browse files Browse the repository at this point in the history
Add support for specifying `--exclude-pattern` to exclude files matching
the specified pattern from being run. This is analogous to the
`--exclude-tags` and `--filter-out` command-line options.
  • Loading branch information
o-lim committed May 10, 2016
1 parent f344bf4 commit 52cc010
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 3 deletions.
2 changes: 2 additions & 0 deletions busted/modules/cli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ return function(options)
cli:splat('ROOT', 'test script file/folder. Folders will be traversed for any file that matches the --pattern option.', 'spec', 999, processArgList)

cli:option('-p, --pattern=PATTERN', 'only run test files matching the Lua pattern', defaultPattern, processMultiOption)
cli:option('--exclude-pattern=PATTERN', 'do not run test files matching the Lua pattern, takes precedence over --pattern', nil, processMultiOption)
end

cli:option('-e STATEMENT', 'execute statement STATEMENT', nil, processMultiOption)
Expand Down Expand Up @@ -196,6 +197,7 @@ return function(options)
cliArgs.e = makeList(cliArgs.e)
cliArgs.pattern = makeList(cliArgs.pattern)
cliArgs.p = cliArgs.pattern
cliArgs['exclude-pattern'] = makeList(cliArgs['exclude-pattern'])
cliArgs.filter = makeList(cliArgs.filter)
cliArgs['filter-out'] = makeList(cliArgs['filter-out'])

Expand Down
5 changes: 5 additions & 0 deletions busted/modules/test_file_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ return function(busted, loaders)

fileList = tablex.filter(fileList, function(filename)
local basename = path.basename(filename)
for _, patt in ipairs(options.excludes) do
if patt ~= '' and basename:find(patt) then
return nil
end
end
for _, patt in ipairs(patterns) do
if basename:find(patt) then
return true
Expand Down
1 change: 1 addition & 0 deletions busted/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ return function(options)
local patterns = cliArgs.pattern
local testFileLoader = require 'busted.modules.test_file_loader'(busted, cliArgs.loaders)
testFileLoader(rootFiles, patterns, {
excludes = cliArgs['exclude-pattern'],
verbose = cliArgs.verbose,
recursive = cliArgs['recursive'],
})
Expand Down
4 changes: 2 additions & 2 deletions completions/bash/busted.bash
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ _busted() {
# no completion available
return 0
;;
-p|--pattern)
-p|--pattern|--exclude-pattern)
# no completion available
return 0
;;
Expand Down Expand Up @@ -165,7 +165,7 @@ _busted() {
--version
-l --list
-o --output=
-p --pattern=
-p --pattern= --exclude-pattern=
-C --directory=
-f --config-file=
-t --tags= --exclude-tags=
Expand Down
1 change: 1 addition & 0 deletions completions/zsh/_busted
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ _busted_args=(
"(-m --lpath)"{-m,--lpath=}"[Optional path to be prefixed to the Lua module search path (default: ./src/?.lua;./src/?/?.lua;./src/?/init.lua)]:directory:_dirs"
"(-o --output)"{-o,--output=}"[Output library to load (default: utfTerminal)]:output handlers:->output"
"(-p --pattern)"{-p,--pattern=}"[Only run test files matching the Lua pattern (default: _spec)]: :"
"--exclude-pattern=[Do not run test files matching the Lua pattern, takes precedence over --pattern]: :"
"(-r --run)"{-r,--run=}"[Config to run from .busted file]:run configurations:->run"
"(-s --enable-sound)"{-s,--enable-sound}"[Executes 'say' command if available]"
"(-t --tags)"{-t,--tags=}"[Only run tests with these #tags]: :"
Expand Down
2 changes: 2 additions & 0 deletions spec/.hidden/.busted
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ return {
['tags'] = {'tag11','tag22','tag33'},
['exclude-tags'] = {'etag11','etag22','etag33'},
['pattern'] = '_spec%.lua$',
['exclude-pattern'] = '_exclude',
['filter'] = 'filt',
['filter-out'] = 'filt-out',
['loaders'] = 'terra,moonscript',
Expand All @@ -17,6 +18,7 @@ return {
['tags'] = 'test1,test2,test3',
['exclude-tags'] = 'etest1,etest2,etest3',
['pattern'] = {'_test1%.lua$', '_test2%.lua$'},
['exclude-pattern'] = {'_exclude1', '_exclude2'},
['filter'] = {'filt1', 'filt2'},
['filter-out'] = {'filt1-out', 'filt2-out'},
['loaders'] = {'lua','terra'},
Expand Down
20 changes: 20 additions & 0 deletions spec/cl_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ describe('Tests the busted command-line options', function()
assert.is_equal(1, errcnt)
end)

it('tests running with --exclude-pattern specified', function ()
local success, errcnt = executeBusted('--pattern="^cl_.*fail.*.lua$" --exclude-pattern="failing"')
assert.is_false(success)
assert.is_equal(4, errcnt)
end)

it('tests running with --exclude-pattern="" disables exclude-pattern', function ()
local success, errcnt = executeBusted('--pattern="cl_two_failures.lua$" --exclude-pattern ""')
assert.is_false(success)
assert.is_equal(2, errcnt)
local success, errcnt = executeBusted('--pattern="cl_success.lua$" --exclude-pattern=')
assert.is_true(success)
end)

it('tests running with the same --pattern and --exclude-pattern specified', function ()
local success, errcnt = executeBusted('--pattern="^cl_.*fail.*.lua$" --exclude-pattern="fail"')
assert.is_false(success)
assert.is_equal(1, errcnt)
end)

it('tests running with --filter specified', function ()
local success, errcnt = executeBusted('--pattern=_filter.lua$')
assert.is_false(success)
Expand Down
15 changes: 14 additions & 1 deletion spec/modules/cli_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe('Tests command-line interface', function()
assert.is_same({}, args.e)
assert.is_same({'_spec'}, args.p)
assert.is_same({'_spec'}, args.pattern)
assert.is_same({}, args['exclude-pattern'])
assert.is_same({}, args.t)
assert.is_same({}, args.tags)
assert.is_same({}, args['exclude-tags'])
Expand All @@ -66,6 +67,7 @@ describe('Tests command-line interface', function()
assert.is_nil(args.ROOT)
assert.is_same({}, args.p)
assert.is_same({}, args.pattern)
assert.is_same({}, args['exclude-pattern'])
end)

it('specify flags', function()
Expand Down Expand Up @@ -206,6 +208,13 @@ describe('Tests command-line interface', function()
assert.is_same({'match_files'}, args.pattern)
end)

it('specify ROOT arg and --exclude-pattern', function()
local cli = require 'busted.modules.cli'({ standalone = false })
local args = cli:parse({ '--exclude-pattern', 'exclude_files', 'root_is_here' })
assert.is_same({'root_is_here'}, args.ROOT)
assert.is_same({'exclude_files'}, args['exclude-pattern'])
end)

it('specify multiple root paths', function()
local cli = require 'busted.modules.cli'({ standalone = false })
local args = cli:parse({'root1_path', 'root2_path', 'root3_path'})
Expand Down Expand Up @@ -365,6 +374,7 @@ describe('Tests using .busted tasks', function()
assert.is_same({}, args.e)
assert.is_same({'_spec%.lua$'}, args.p)
assert.is_same({'_spec%.lua$'}, args.pattern)
assert.is_same({'_exclude'}, args['exclude-pattern'])
assert.is_same({'tag11', 'tag22', 'tag33'}, args.t)
assert.is_same({'tag11', 'tag22', 'tag33'}, args.tags)
assert.is_same({'etag11', 'etag22', 'etag33'}, args['exclude-tags'])
Expand Down Expand Up @@ -422,6 +432,7 @@ describe('Tests using .busted tasks', function()
assert.is_nil(args.helper)
assert.is_same({'_spec%.lua$'}, args.p)
assert.is_same({'_spec%.lua$'}, args.pattern)
assert.is_same({'_exclude'}, args['exclude-pattern'])
assert.is_same({'tag11', 'tag22', 'tag33'}, args.t)
assert.is_same({'tag11', 'tag22', 'tag33'}, args.tags)
assert.is_same({'etag11', 'etag22', 'etag33'}, args['exclude-tags'])
Expand All @@ -436,6 +447,7 @@ describe('Tests using .busted tasks', function()
local cli = require 'busted.modules.cli'({ standalone = false, defaultOutput = defaultOutput })
local args = cli:parse({ '--directory=spec/.hidden', '--run=test' })
assert.is_same({'_test1%.lua$', '_test2%.lua$'}, args.pattern)
assert.is_same({'_exclude1', '_exclude2'}, args['exclude-pattern'])
assert.is_same({'filt1', 'filt2'}, args.filter)
assert.is_same({'filt1-out', 'filt2-out'}, args['filter-out'])
assert.is_same({'tests'}, args.ROOT)
Expand All @@ -448,8 +460,9 @@ describe('Tests using .busted tasks', function()

it('load configuration options and override with command-line', function()
local cli = require 'busted.modules.cli'({ standalone = false, defaultOutput = defaultOutput })
local args = cli:parse({ '--directory=spec/.hidden', '--run=test', '-t', 'tag1', '-p', 'patt', '--filter=fin', '--filter-out=fout', '--loaders=moonscript' })
local args = cli:parse({ '--directory=spec/.hidden', '--run=test', '-t', 'tag1', '-p', 'patt', '--filter=fin', '--filter-out=fout', '--exclude-pattern', '', '--loaders=moonscript' })
assert.is_same({'patt'}, args.pattern)
assert.is_same({''}, args['exclude-pattern'])
assert.is_same({'fin'}, args.filter)
assert.is_same({'fout'}, args['filter-out'])
assert.is_same({'tag1'}, args.tags)
Expand Down

0 comments on commit 52cc010

Please sign in to comment.