]> granicus.if.org Git - graphviz/commitdiff
add compilation of the C examples to the test suite
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 4 Jul 2020 17:28:35 +0000 (10:28 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 7 Jul 2020 00:11:25 +0000 (17:11 -0700)
rtest/test_examples.py [new file with mode: 0644]

diff --git a/rtest/test_examples.py b/rtest/test_examples.py
new file mode 100644 (file)
index 0000000..21c9fa2
--- /dev/null
@@ -0,0 +1,32 @@
+# tests that examples provided with Graphviz compile correctly
+
+import os
+import platform
+import pytest
+import subprocess
+
+def c_compiler():
+    '''find the system's C compiler'''
+    return os.environ.get('CC', 'cc')
+
+@pytest.mark.parametrize('src', ['demo.c', 'dot.c', 'example.c', 'neatopack.c',
+  'simple.c'])
+def test_compile_example(src):
+    '''try to compile the example'''
+
+    # FIXME: if you know how to call the C compiler on Windows, please implement
+    # this functionality
+    if platform.system() == 'Windows':
+        pytest.skip('not implemented for Windows')
+
+    # construct an absolute path to the example
+    filepath = os.path.join(os.path.abspath(os.path.dirname(__file__)),
+      '../dot.demo', src)
+
+    cc = c_compiler()
+
+    libs = ('cgraph', 'gvc')
+
+    # ensure the C compiler can build this without error
+    subprocess.check_call([cc, '-o', os.devnull, filepath]
+      + ['-l{}'.format(l) for l in libs])