From b17880d8ecfb1296de3ddd52aefdbdd4fbd77c8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans=20H=C3=BCbner?= Date: Mon, 15 May 2023 16:17:22 +0200 Subject: [PATCH] feat(*): add --name option to single out individual test(s) --- busted/modules/cli.lua | 1 + busted/modules/filter_loader.lua | 12 +++++++++++- busted/runner.lua | 1 + completions/bash/busted.bash | 3 ++- completions/zsh/_busted | 1 + spec/cl_spec.lua | 4 ++-- 6 files changed, 18 insertions(+), 4 deletions(-) diff --git a/busted/modules/cli.lua b/busted/modules/cli.lua index 753205c8..0cca3e2b 100644 --- a/busted/modules/cli.lua +++ b/busted/modules/cli.lua @@ -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) diff --git a/busted/modules/filter_loader.lua b/busted/modules/filter_loader.lua index 9210f721..e5c15182 100644 --- a/busted/modules/filter_loader.lua +++ b/busted/modules/filter_loader.lua @@ -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 @@ -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 diff --git a/busted/runner.lua b/busted/runner.lua index 91ac1bcf..ce4a4830 100644 --- a/busted/runner.lua +++ b/busted/runner.lua @@ -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, diff --git a/completions/bash/busted.bash b/completions/bash/busted.bash index 46f63bc2..30a761d6 100644 --- a/completions/bash/busted.bash +++ b/completions/bash/busted.bash @@ -136,7 +136,7 @@ _busted() { # no completion available return 0 ;; - --filter|--filter-out) + --filter|--filter-out|--name) # no completion available return 0 ;; @@ -179,6 +179,7 @@ _busted() { --lua= --ignore-lua --filter= --filter-out= + --name= --exclude-names-file= --repeat= --seed= diff --git a/completions/zsh/_busted b/completions/zsh/_busted index 66d03a0b..d74d7794 100644 --- a/completions/zsh/_busted +++ b/completions/zsh/_busted @@ -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]" diff --git a/spec/cl_spec.lua b/spec/cl_spec.lua index 5d2817da..c631e09d 100644 --- a/spec/cl_spec.lua +++ b/spec/cl_spec.lua @@ -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))