# 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 == ''