Add tag filters to spack test list (#26842)

This commit is contained in:
Tamara Dahlgren 2021-11-02 02:00:21 -07:00 committed by GitHub
parent 94e0bf0112
commit 9d3d7c68fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 6 deletions

View file

@ -89,6 +89,12 @@ def setup_parser(subparser):
"-a", "--all", action="store_true", dest="list_all",
help="list all packages with tests (not just installed)")
list_parser.add_argument(
'tag',
nargs='*',
help="limit packages to those with all listed tags"
)
# Find
find_parser = sp.add_parser('find', description=test_find.__doc__,
help=first_line(test_find.__doc__))
@ -214,15 +220,25 @@ def has_test_method(pkg):
def test_list(args):
"""List installed packages with available tests."""
tagged = set(spack.repo.path.packages_with_tags(*args.tag)) if args.tag \
else set()
def has_test_and_tags(pkg_class):
return has_test_method(pkg_class) and \
(not args.tag or pkg_class.name in tagged)
if args.list_all:
all_packages_with_tests = [
report_packages = [
pkg_class.name
for pkg_class in spack.repo.path.all_package_classes()
if has_test_method(pkg_class)
if has_test_and_tags(pkg_class)
]
if sys.stdout.isatty():
tty.msg("%d packages with tests." % len(all_packages_with_tests))
colify.colify(all_packages_with_tests)
filtered = ' tagged' if args.tag else ''
tty.msg("{0}{1} packages with tests.".
format(len(report_packages), filtered))
colify.colify(report_packages)
return
# TODO: This can be extended to have all of the output formatting options
@ -231,7 +247,7 @@ def test_list(args):
hashes = env.all_hashes() if env else None
specs = spack.store.db.query(hashes=hashes)
specs = list(filter(lambda s: has_test_method(s.package_class), specs))
specs = list(filter(lambda s: has_test_and_tags(s.package_class), specs))
spack.cmd.display_specs(specs, long=True)

View file

@ -1696,7 +1696,12 @@ _spack_test_run() {
}
_spack_test_list() {
SPACK_COMPREPLY="-h --help -a --all"
if $list_options
then
SPACK_COMPREPLY="-h --help -a --all"
else
SPACK_COMPREPLY=""
fi
}
_spack_test_find() {