From d739989ec8014efa88270537b81915de81ab6646 Mon Sep 17 00:00:00 2001 From: Tamara Dahlgren <35777542+tldahlgren@users.noreply.github.com> Date: Mon, 22 May 2023 09:39:30 -0700 Subject: [PATCH] swig: convert to new stand-alone test process (#37786) --- .../repos/builtin/packages/swig/package.py | 58 +++++++++---------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/var/spack/repos/builtin/packages/swig/package.py b/var/spack/repos/builtin/packages/swig/package.py index 9c24304a8e..bd1ae02c51 100644 --- a/var/spack/repos/builtin/packages/swig/package.py +++ b/var/spack/repos/builtin/packages/swig/package.py @@ -102,47 +102,41 @@ def determine_version(cls, exe): return match.group(1) if match else None @property - def _installed_exe(self): - return join_path(self.prefix, "bin", "swig") + def _swig(self): + return Executable(join_path(self.prefix, "bin", "swig")) - def _test_version(self): + @property + def _swiglib(self): + return self._swig("-swiglib", output=str).strip() + + def test_version(self): + """check swig version""" version = str(self.version) if version.endswith("-fortran"): - version = version.replace("-", r"\+") + version = version.replace("-", r"+") elif version in ("fortran", "master"): - version = r".*" + version = "" - self.run_test( - self._installed_exe, - "-version", - expected=[r"SWIG Version {0}".format(version)], - purpose="test: version", - ) + out = self._swig("-version", output=str.split, error=str.split) + expected = f"SWIG Version {version}" + assert expected in out, f"Expected '{expected}' in output" - def _test_swiglib(self): - # Get SWIG's alleged path to library files - swig = Executable(self._installed_exe) - swiglib = swig("-swiglib", output=str).strip() + def test_swiglib(self): + """check that the lib dir exists""" + assert os.path.isdir(self._swiglib), f"SWIG library does not exist at '{swiglib}'" - # Check that the lib dir exists - if not os.path.isdir(swiglib): - msg = "SWIG library does not exist at '{0}'".format(swiglib) - self.test_failures.append([None, msg]) + def test_swig_swg(self): + """check that swig.swg exists""" + swigfile = join_path(self._swiglib, "swig.swg") + assert os.path.exists(swigfile), f"SWIG runtime does not exist at '{swigfile}'" - # Check for existence of other critical SWIG library files - swigfile = join_path(swiglib, "swig.swg") - if not os.path.exists(swigfile): - msg = "SWIG runtime does not exist at '{0}'".format(swigfile) - self.test_failures.append([None, msg]) - if "fortran" in str(self.version): - swigfile = join_path(swiglib, "fortran", "fortran.swg") - if not os.path.exists(swigfile): - msg = "SWIG+Fortran runtime does not exist at '{0}'".format(swigfile) - self.test_failures.append([None, msg]) + def test_fortran_swg(self): + """check that fortran.swg exists""" + if "fortran" not in str(self.version): + raise SkipTest(f"Test does not work with version {self.version}") - def test(self): - self._test_version() - self._test_swiglib() + swigfile = join_path(self._swiglib, "fortran", "fortran.swg") + assert os.path.exists(swigfile), f"SWIG+Fortran runtime does not exist at '{swigfile}'" class AutotoolsBuilder(spack.build_systems.autotools.AutotoolsBuilder):