summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamara Dahlgren <35777542+tldahlgren@users.noreply.github.com>2023-06-24 22:02:33 -0700
committerGitHub <noreply@github.com>2023-06-25 01:02:33 -0400
commit95ca9dea898af0cc755808ae8577bda2e0ced8d6 (patch)
treeaad0635e223fe0fd0aa9e9f0ab7d11f0c0fe1ee3
parentcb23362b7f4b428b29002dac72f2a8b7d437c9d9 (diff)
downloadspack-95ca9dea898af0cc755808ae8577bda2e0ced8d6.tar.gz
spack-95ca9dea898af0cc755808ae8577bda2e0ced8d6.tar.bz2
spack-95ca9dea898af0cc755808ae8577bda2e0ced8d6.tar.xz
spack-95ca9dea898af0cc755808ae8577bda2e0ced8d6.zip
libxml2: convert to new stand-alone test process (#37694)
-rw-r--r--var/spack/repos/builtin/packages/libxml2/package.py117
1 files changed, 82 insertions, 35 deletions
diff --git a/var/spack/repos/builtin/packages/libxml2/package.py b/var/spack/repos/builtin/packages/libxml2/package.py
index 640988d617..bde03c534d 100644
--- a/var/spack/repos/builtin/packages/libxml2/package.py
+++ b/var/spack/repos/builtin/packages/libxml2/package.py
@@ -4,9 +4,6 @@
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import os
-import llnl.util.filesystem as fs
-import llnl.util.tty as tty
-
from spack.build_systems import autotools, nmake
from spack.package import *
@@ -101,41 +98,91 @@ class Libxml2(AutotoolsPackage, NMakePackage):
)
filter_file("-Wno-long-long -Wno-format-extra-args", "", "configure")
- def test(self):
- """Perform smoke tests on the installed package"""
- # Start with what we already have post-install
- tty.msg("test: Performing simple import test")
- self.builder.import_module_test()
+ def test_import(self):
+ """import module test"""
+ if "+python" not in self.spec:
+ raise SkipTest("Package must be built with +python")
- data_dir = self.test_suite.current_test_data_dir
+ with working_dir("spack-test", create=True):
+ python("-c", "import libxml2")
+
+ def test_xmlcatalog(self):
+ """check minimal creation output"""
+ path = self.prefix.bin.xmlcatalog
+ if not os.path.exists(path):
+ raise SkipTest("xmlcatalog is not installed")
+
+ xmlcatalog = which(path)
+ out = xmlcatalog("--create", output=str.split, error=str.split)
+
+ expected = [r"<catalog xmlns", r'catalog"/>']
+ check_outputs(expected, out)
+
+ def test_xml2_config(self):
+ """check version output"""
+ path = join_path(self.prefix.bin, "xml2-config")
+ if not os.path.exists(path):
+ raise SkipTest("xml2-config is not installed")
+
+ xml2_config = which(path)
+ out = xml2_config("--version", output=str.split, error=str.split)
+ assert str(self.spec.version) in out
+
+ def test_xmllint(self):
+ """run xmllint generation and validation checks"""
+ path = self.prefix.bin.xmllint
+ if not os.path.exists(path):
+ raise SkipTest("xmllint is not installed")
- # Now run defined tests based on expected executables
- dtd_path = data_dir.join("info.dtd")
test_filename = "test.xml"
- exec_checks = {
- "xml2-config": [("--version", [str(self.spec.version)], 0)],
- "xmllint": [
- (["--auto", "-o", test_filename], [], 0),
- (
- ["--postvalid", test_filename],
- ["validity error", "no DTD found", "does not validate"],
- 3,
- ),
- (
- ["--dtdvalid", dtd_path, test_filename],
- ["validity error", "does not follow the DTD"],
- 3,
- ),
- (["--dtdvalid", dtd_path, data_dir.join("info.xml")], [], 0),
- ],
- "xmlcatalog": [("--create", ["<catalog xmlns", 'catalog"/>'], 0)],
- }
- for exe in exec_checks:
- for options, expected, status in exec_checks[exe]:
- self.run_test(exe, options, expected, status)
-
- # Perform some cleanup
- fs.force_remove(test_filename)
+ xmllint = which(path)
+
+ with test_part(self, "test_xmllint_auto", purpose="generate {0}".format(test_filename)):
+ xmllint("--auto", "-o", test_filename)
+
+ with test_part(
+ self,
+ "test_xmllint_validate_no_dtd",
+ purpose="validate {0} without a DTD".format(test_filename),
+ ):
+ out = xmllint(
+ "--postvalid",
+ test_filename,
+ output=str.split,
+ error=str.split,
+ fail_on_error=False,
+ )
+
+ expected = [r"validity error", r"no DTD found", r"does not validate"]
+ check_outputs(expected, out)
+
+ data_dir = self.test_suite.current_test_data_dir
+ dtd_path = data_dir.join("info.dtd")
+
+ with test_part(
+ self,
+ "test_xmllint_validate_with_dtd",
+ purpose="validate {0} with a DTD".format(test_filename),
+ ):
+ out = xmllint(
+ "--dtdvalid",
+ dtd_path,
+ test_filename,
+ output=str.split,
+ error=str.split,
+ fail_on_error=False,
+ )
+
+ expected = [r"validity error", r"does not follow the DTD"]
+ check_outputs(expected, out)
+
+ test_filename = data_dir.join("info.xml")
+ with test_part(
+ self,
+ "test_xmllint_validate_works",
+ purpose="validate {0} with a DTD".format(test_filename),
+ ):
+ xmllint("--dtdvalid", dtd_path, data_dir.join("info.xml"))
class RunAfter(object):