From 011a491b16a71747d811803a3f2ca1de6b367c0f Mon Sep 17 00:00:00 2001 From: Tamara Dahlgren <35777542+tldahlgren@users.noreply.github.com> Date: Thu, 5 May 2022 09:04:16 -0700 Subject: package audit: ensure stand-alone test method not include in build-phase testing (#30352) --- lib/spack/spack/audit.py | 18 ++++++++++++++++++ lib/spack/spack/test/audit.py | 2 ++ 2 files changed, 20 insertions(+) (limited to 'lib') diff --git a/lib/spack/spack/audit.py b/lib/spack/spack/audit.py index 893c7f6aa3..1075822de7 100644 --- a/lib/spack/spack/audit.py +++ b/lib/spack/spack/audit.py @@ -276,6 +276,24 @@ package_https_directives = AuditClass( ) +@package_directives +def _check_build_test_callbacks(pkgs, error_cls): + """Ensure stand-alone test method is not included in build-time callbacks""" + errors = [] + for pkg_name in pkgs: + pkg = spack.repo.get(pkg_name) + test_callbacks = pkg.build_time_test_callbacks + + if test_callbacks and 'test' in test_callbacks: + msg = ('{0} package contains "test" method in ' + 'build_time_test_callbacks') + instr = ('Remove "test" from: [{0}]' + .format(', '.join(test_callbacks))) + errors.append(error_cls(msg.format(pkg.name), [instr])) + + return errors + + @package_directives def _check_patch_urls(pkgs, error_cls): """Ensure that patches fetched from GitHub have stable sha256 hashes.""" diff --git a/lib/spack/spack/test/audit.py b/lib/spack/spack/test/audit.py index 6ad986643e..9cb36b5047 100644 --- a/lib/spack/spack/test/audit.py +++ b/lib/spack/spack/test/audit.py @@ -17,6 +17,8 @@ import spack.config (['wrong-variant-in-depends-on'], 'PKG-DIRECTIVES'), # This package has a GitHub patch URL without full_index=1 (['invalid-github-patch-url'], 'PKG-DIRECTIVES'), + # This package has a stand-alone 'test' method in build-time callbacks + (['test-build-callbacks'], 'PKG-DIRECTIVES'), # This package has no issues (['mpileaks'], None), # This package has a conflict with a trigger which cannot constrain the constraint -- cgit v1.2.3-60-g2f50