diff --git a/docs/manpage.rst b/docs/manpage.rst index dd79334634..0564c4d3f0 100644 --- a/docs/manpage.rst +++ b/docs/manpage.rst @@ -166,6 +166,14 @@ An action must always be specified. List selected tests providing detailed information per test. +.. option:: --list-tags + + List the unique tags of the selected tests. + The tags are printed in alphabetical order. + + .. versionadded:: 3.6.0 + + .. option:: -r, --run Execute the selected tests. diff --git a/reframe/frontend/cli.py b/reframe/frontend/cli.py index c0240af974..21f2f23ae8 100644 --- a/reframe/frontend/cli.py +++ b/reframe/frontend/cli.py @@ -123,6 +123,14 @@ def list_checks(testcases, printer, detailed=False): printer.info(f'Found {len(checks)} check(s)\n') +def list_tags(testcases, printer): + printer.info('[List of unique tags]') + tags = set() + tags = tags.union(*(t.check.tags for t in testcases)) + printer.info(', '.join(f'{t!r}' for t in sorted(tags))) + printer.info(f'Found {len(tags)} tag(s)\n') + + def logfiles_message(): log_files = logging.log_files() msg = 'Log file(s) saved in: ' @@ -269,6 +277,10 @@ def main(): '-L', '--list-detailed', action='store_true', help='List the selected checks providing details for each test' ) + action_options.add_argument( + '--list-tags', action='store_true', + help='List the unique tags found in the selected tests and exit' + ) action_options.add_argument( '-r', '--run', action='store_true', help='Run the selected checks' @@ -810,6 +822,10 @@ def _case_failed(t): list_checks(testcases, printer, options.list_detailed) sys.exit(0) + if options.list_tags: + list_tags(testcases, printer) + sys.exit(0) + if options.ci_generate: list_checks(testcases, printer) printer.info('[Generate CI]') @@ -826,6 +842,7 @@ def _case_failed(t): printer.error("No action option specified. Available options:\n" " - `-l'/`-L' for listing\n" " - `-r' for running\n" + " - `--list-tags' for listing unique test tags\n" " - `--ci-generate' for generating a CI pipeline\n" f"Try `{argparser.prog} -h' for more options.") sys.exit(1) diff --git a/unittests/test_cli.py b/unittests/test_cli.py index 7818eded1c..b11605dead 100644 --- a/unittests/test_cli.py +++ b/unittests/test_cli.py @@ -89,6 +89,8 @@ def _run_reframe(system='generic:default', argv += ['-l'] elif action == 'list_detailed': argv += ['-L'] + elif action == 'list_tags': + argv += ['--list-tags'] elif action == 'help': argv += ['-h'] @@ -540,6 +542,19 @@ def test_list_with_details(run_reframe): assert returncode == 0 +def test_list_tags(run_reframe): + returncode, stdout, stderr = run_reframe( + checkpath=['unittests/resources/checks/hellocheck.py', + 'unittests/resources/checks/hellocheck_make.py'], + action='list_tags' + ) + assert 'Traceback' not in stdout + assert 'Traceback' not in stderr + assert 'Found 2 tag(s)' in stdout + assert "'bar', 'foo'" in stdout + assert returncode == 0 + + def test_filtering_multiple_criteria(run_reframe): returncode, stdout, stderr = run_reframe( checkpath=['unittests/resources/checks'],