Skip to content

Commit

Permalink
feat(*): add --name option to single out individual test(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanshuebner committed Nov 6, 2023
1 parent 11170b0 commit e4bc2f4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions busted/modules/cli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ return function(options)
cli:option('-t, --tags=TAGS', 'only run tests with these #tags', {}, processList)
cli:option('--exclude-tags=TAGS', 'do not run tests with these #tags, takes precedence over --tags', {}, processList)
cli:option('--filter=PATTERN', 'only run test names matching the Lua pattern', {}, processMultiOption)
cli:option('--name=NAME', 'run test with the given full name', {}, processMultiOption)
cli:option('--filter-out=PATTERN', 'do not run test names matching the Lua pattern, takes precedence over --filter', {}, processMultiOption)
cli:option('--exclude-names-file=FILE', 'do not run the tests with names listed in the given file, takes precedence over --filter', nil, processOption)
cli:option('--log-success=FILE', 'append the name of each successful test to the given file', nil, processOption)
Expand Down
12 changes: 11 additions & 1 deletion busted/modules/filter_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ return function()
return nil, true
end

local name = function(name)
for _, candidate in pairs(options.name) do
if string.find(candidate, getFullName(name), 1, true) then
return nil, true
end
end
return nil, (#options.name == 0)
end

local filterNames = function(name)
for _, filter in pairs(options.filter) do
if getFullName(name):find(filter) ~= nil then
Expand Down Expand Up @@ -139,8 +148,9 @@ return function()

-- The following filters are applied in reverse order
applyFilter({ 'it', 'pending' } , 'filter' , filterNames )
applyFilter({ 'describe', 'it', 'pending' }, 'name' , name )
applyFilter({ 'describe', 'it', 'pending' }, 'filterOut' , filterOutNames )
applyFilter({ 'describe', 'it', 'pending' }, 'excludeNamesFile', excludeNamesFile)
applyFilter({ 'describe', 'it', 'pending' }, 'excludeNamesFile', excludeNamesFile )
applyFilter({ 'it', 'pending' } , 'tags' , filterTags )
applyFilter({ 'describe', 'it', 'pending' }, 'excludeTags' , filterExcludeTags )
end
Expand Down
1 change: 1 addition & 0 deletions busted/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ return function(options)
tags = cliArgs.tags,
excludeTags = cliArgs['exclude-tags'],
filter = cliArgs.filter,
name = cliArgs.name,
filterOut = cliArgs['filter-out'],
excludeNamesFile = cliArgs['exclude-names-file'],
list = cliArgs.list,
Expand Down
3 changes: 2 additions & 1 deletion completions/bash/busted.bash
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ _busted() {
# no completion available
return 0
;;
--filter|--filter-out)
--filter|--filter-out|--name)
# no completion available
return 0
;;
Expand Down Expand Up @@ -179,6 +179,7 @@ _busted() {
--lua=
--ignore-lua
--filter= --filter-out=
--name=
--exclude-names-file=
--repeat=
--seed=
Expand Down
1 change: 1 addition & 0 deletions completions/zsh/_busted
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ _busted_args=(
"--filter=[Only run test names matching the Lua pattern]: :"
"--filter-out=[Do not run test names matching the Lua pattern, takes precedence over --filter]: :"
"--exclude-names-file=[Do not run the tests with names listed in the given file, takes precedence over --filter]:files:_files"
"--name=[Run test with the given full name]:files:_files"
"--log-success=[Append the name of each successful test to the given file]:file:_files"
"-e[Execute Lua statement]: :"
"(-v --verbose --no-verbose)"{-v,--verbose}"[Verbose output of errors]"
Expand Down
4 changes: 2 additions & 2 deletions spec/cl_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ describe('Tests the busted command-line options', function()

it('tests running with --log-success and --exclude-names-file specified', function ()
local logfile = os.tmpname()
local success, errcnt, out, err = executeBusted('--pattern=_filter.lua$ --log-success=' .. logfile .. ' --exclude-names-file=' .. logfile)
local success, errcnt, out = executeBusted('--pattern=_filter.lua$ --log-success=' .. logfile .. ' --exclude-names-file=' .. logfile)
assert.is_false(success)
assert.equals(8, errcnt)
assert.equals(2, count_successes(out))
-- re-run tests with previously successful tests skipped
success, errcnt, out, err = executeBusted('--pattern=_filter.lua$ --log-success=' .. logfile .. ' --exclude-names-file=' .. logfile)
success, errcnt, out = executeBusted('--pattern=_filter.lua$ --log-success=' .. logfile .. ' --exclude-names-file=' .. logfile)
assert.is_false(success)
assert.equals(8, errcnt)
assert.equals(0, count_successes(out))
Expand Down

0 comments on commit e4bc2f4

Please sign in to comment.