libxml2: convert to new stand-alone test process (#37694)

This commit is contained in:
Tamara Dahlgren 2023-06-24 22:02:33 -07:00 committed by GitHub
parent cb23362b7f
commit 95ca9dea89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 @@ def patch(self):
)
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")
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")
test_filename = "test.xml"
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
# 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)
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):