]> granicus.if.org Git - graphviz/commitdiff
add test cases for validating in-repo HTML files
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 23 Oct 2020 00:00:37 +0000 (17:00 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 29 Oct 2020 00:52:08 +0000 (17:52 -0700)
Related to #1861.

rtest/test_regression.py

index 7d1f96c36fbce90cc172de77bdd33e21aa09d387..c57a3d74e775650e019c39897a21538bdcdecebf 100644 (file)
@@ -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 == ''