From: Matthew Fernandez Date: Fri, 23 Oct 2020 00:00:37 +0000 (-0700) Subject: add test cases for validating in-repo HTML files X-Git-Tag: 2.46.0~20^2^2~8^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fa30e78e1d0bf76205844ab774260e3e45b6af8a;p=graphviz add test cases for validating in-repo HTML files Related to #1861. --- diff --git a/rtest/test_regression.py b/rtest/test_regression.py index 7d1f96c36..c57a3d74e 100644 --- a/rtest/test_regression.py +++ b/rtest/test_regression.py @@ -367,3 +367,57 @@ def test_1845(): # generate a multipage PS file from this input subprocess.check_call(['dot', '-Tps', '-o', os.devnull, input]) + +# root directory of this checkout +ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) + +# find all HTML files +html = set() +for (prefix, _, files) in os.walk(ROOT): + for name in files: + if os.path.splitext(name)[-1].lower() in ('.htm', '.html'): + html.add(os.path.join(prefix, name)) + +@pytest.mark.parametrize('src', html) +@pytest.mark.skipif(shutil.which('xmllint') is None, reason='xmllint not found') +def test_html(src: str): + + # Files that we know currently fail this test. If you fix one of these files, + # remove it from this list. + # See https://gitlab.com/graphviz/graphviz/-/issues/1861 + FAILING = frozenset(os.path.join(ROOT, x) for x in ( + 'doc/FAQ.html', + 'doc/info/colors.html', + 'doc/info/output.html', + 'doc/info/shapes.html', + 'doc/internal_todo.html', + 'lib/inkpot/data/types.html', + 'macosx/graphviz.help/graphviz.html', + )) + + # ensure this test fails if one of the above files is moved/deleted, to prompt + # developers to update the list + assert all(os.path.exists(x) for x in FAILING), 'missing file in FAILING list' + + # FIXME: the macOS Autotools CI build installs to a target within the source + # tree, so we need to avoid picking up duplicating copies of the FAILING list + # that are present there + if platform.system() == 'Darwin' and \ + os.environ.get('build_system') == 'autotools' and \ + src.startswith(os.path.join(ROOT, 'build')): + pytest.skip('skipping installed copied of source file') + + # validate the file + p = subprocess.Popen(['xmllint', '--nonet', '--noout', '--html', '--valid', + src], stderr=subprocess.PIPE, universal_newlines=True) + _, stderr = p.communicate() + + # If this is expected to fail, demand that it does so. This way the test will + # fail if someone fixes the file, prompting them to update this test. + if src in FAILING: + assert p.returncode != 0 or stderr != '' + return + + # otherwise, expect it to succeed + assert p.returncode == 0 + assert stderr == ''