// print ""
static void test_empty_string(void) {
+// For some reason, GCC thinks this deserves a compiler warning because
+// `printf("")` is a no-op. Apparently our annotations that tell it `gv_sprint`
+// is `printf` like lead it to decide it is a little _too_ `printf` like.
+#ifdef __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-zero-length"
+#endif
char *s = gv_sprint("");
+#ifdef __GNUC__
+#pragma GCC diagnostic pop
+#endif
assert(strcmp(s, "") == 0);
free(s);
}
import os
from pathlib import Path
+import platform
import sys
+import pytest
sys.path.append(os.path.dirname(__file__))
from gvtest import run_c #pylint: disable=C0413
-def test_sprint():
- """run the sprint unit tests"""
+@pytest.mark.parametrize("utility", ("bitarray", "sprint"))
+def test_utility(utility: str):
+ """run the given utility’s unit tests"""
- # locate the sprint unit tests
- src = Path(__file__).parent.resolve() / "../lib/cgraph/test_sprint.c"
+ # locate the unit tests
+ src = Path(__file__).parent.resolve() / f"../lib/cgraph/test_{utility}.c"
assert src.exists()
# locate lib directory that needs to be in the include path
# extra C flags this compilation needs
cflags = ['-I', lib]
+ if platform.system() != "Windows":
+ cflags += ["-std=gnu99", "-Wall", "-Wextra", "-Werror"]
_, _ = run_c(src, cflags=cflags)
# pass this through gvmap
subprocess.run(["gvmap"], input=input.encode("utf-8"), check=True)
-def test_bitarray():
- """run the bitarray unit tests"""
-
- # locate the bitarray unit tests
- src = Path(__file__).parent.resolve() / "../lib/cgraph/test_bitarray.c"
- assert src.exists()
-
- # locate lib directory that needs to be in the include path
- lib = Path(__file__).parent.resolve() / "../lib"
-
- # extra C flags this compilation needs
- cflags = ["-I", lib]
- if platform.system() != "Windows":
- cflags += ["-std=gnu99", "-Wall", "-Wextra", "-Werror"]
-
- _, _ = run_c(src, cflags=cflags)
-
@pytest.mark.skipif(shutil.which("gvpr") is None, reason="gvpr not available")
def test_gvpr_usage():
"""