]> granicus.if.org Git - graphviz/commitdiff
add a test of PACKAGE_VERSION
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 31 Jan 2021 17:48:06 +0000 (09:48 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 6 Feb 2021 18:53:34 +0000 (10:53 -0800)
Related to !1706.

rtest/check-package-version.c [new file with mode: 0644]
rtest/test_regression.py

diff --git a/rtest/check-package-version.c b/rtest/check-package-version.c
new file mode 100644 (file)
index 0000000..ce44c9b
--- /dev/null
@@ -0,0 +1,21 @@
+// test that the Graphviz version header has a non-empty PACKAGE_VERSION
+
+// force assertions on
+#ifdef NDEBUG
+  #undef NDEBUG
+#endif
+
+#include <assert.h>
+#include <graphviz/graphviz_version.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifndef PACKAGE_VERSION
+#error PACKAGE_VERSION missing from graphviz_version.h
+#endif
+
+int main(void) {
+  assert(strcmp(PACKAGE_VERSION, "") != 0 &&
+    "invalid PACKAGE_VERSION (" PACKAGE_VERSION ") in graphviz_version.h");
+  return EXIT_SUCCESS;
+}
index 8f920259a6d1c6fc59964f01f663af401c896ae6..15f691f11f54a4bc437fb35d63c8dcb027e55664 100644 (file)
@@ -749,3 +749,40 @@ def test_1931():
     assert 'line 1\nline 2\n' in xdot
     assert 'line 3\nline 4' in xdot
     assert 'line 5\nline 6' in xdot
+
+def test_package_version():
+    '''
+    The graphviz_version.h header should define a non-empty PACKAGE_VERSION
+    '''
+
+    # FIXME: Remove skip when
+    # https://gitlab.com/graphviz/graphviz/-/issues/1777 is fixed
+    if os.getenv('build_system') == 'msbuild':
+      pytest.skip('Windows MSBuild release does not contain any header files (#1777)')
+
+    # find co-located test source
+    c_src = (Path(__file__).parent / 'check-package-version.c').resolve()
+    assert c_src.exists(), 'missing test case'
+
+    # create some scratch space to work in
+    with tempfile.TemporaryDirectory() as tmp:
+
+      # compile our test code
+      exe = Path(tmp) / 'a.exe'
+      rt_lib_option = '-MDd' if os.environ.get('configuration') == 'Debug' else '-MD'
+
+      if platform.system() == 'Windows':
+          subprocess.check_call(['cl', c_src, '-Fe:', exe, '-nologo',
+            rt_lib_option])
+      else:
+          cc = os.environ.get('CC', 'cc')
+          subprocess.check_call([cc, '-std=c99', c_src, '-o', exe])
+
+      # run the test
+      ret = subprocess.call([exe])
+
+    # FIXME: this is currently broken in the CMake build
+    if os.getenv('build_system') == 'cmake':
+      assert ret != 0
+    else:
+      assert ret == 0