from pathlib import Path
import platform
import subprocess
+import sys
import sysconfig
import tempfile
from typing import List, Optional, Tuple, Union
def run_c(src: Path, args: List[str] = None, input: str = "",
cflags: List[str] = None, link: List[str] = None
- ) -> Tuple[int, str, str]:
+ ) -> Tuple[str, str]:
"""compile and run a C program"""
if args is None:
p = subprocess.run([exe] + args, input=input, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, universal_newlines=True)
- return p.returncode, p.stdout, p.stderr
+ # check it succeeded
+ if p.returncode != 0:
+ sys.stdout.write(p.stdout)
+ sys.stderr.write(p.stderr)
+ p.check_returncode()
+
+ return p.stdout, p.stderr
else:
cflags = None
- ret, out, err = run_c(filepath, args, "graph {a -- b}", cflags=cflags, link=libs)
-
- print(f"returncode: {ret} = 0x{ret:08x}")
- if ret != 0:
- print(out)
- print(err)
- assert ret == 0
+ _, _ = run_c(filepath, args, "graph {a -- b}", cflags=cflags, link=libs)
@pytest.mark.parametrize("src", ["addrings", "attr", "bbox", "bipart",
"chkedges", "clustg", "collapse", "cycle", "deghist", "delmulti", "depath",
src = (Path(__file__).parent / "1767.dot").resolve()
assert src.exists(), "missing test case"
- ret, _, _ = run_c(c_src, [src], link=["cgraph", "gvc"])
- assert ret == 0
+ _, _ = run_c(c_src, [src], link=["cgraph", "gvc"])
# FIXME: uncomment this when #1767 is fixed
# assert stdout == "Loaded graph:clusters\n" \
assert c_src.exists(), "missing test case"
# run the test
- ret, _, _ = run_c(c_src, link=["cgraph", "gvc"])
- assert ret == 0
+ _, _ = run_c(c_src, link=["cgraph", "gvc"])
def test_1913():
"""
assert c_src.exists(), "missing test case"
# run the test
- ret, _, _ = run_c(c_src, link=["gvc"])
- assert ret == 0
+ _, _ = run_c(c_src, link=["gvc"])
def test_2078():
"""
assert c_src.exists(), "missing test case"
# run it
- ret, stdout, stderr = run_c(c_src, link=["cgraph"])
- sys.stdout.write(stdout)
- sys.stderr.write(stderr)
- assert ret == 0
+ _, _ = run_c(c_src, link=["cgraph"])
@pytest.mark.skipif(os.environ.get("build_system") == "msbuild" and
os.environ.get("configuration") == "Debug",
assert c_src.exists(), "missing test case"
# run the test
- ret, _, _ = run_c(c_src)
- assert ret == 0
+ _, _ = run_c(c_src)
def test_user_shapes():
"""
# ask our C helper to process this
try:
- ret, output, err = run_c(c_src, input=input, link=["xdot"])
+ output, err = run_c(c_src, input=input, link=["xdot"])
except subprocess.CalledProcessError:
# FIXME: Remove this try-catch when
# https://gitlab.com/graphviz/graphviz/-/issues/1777 is fixed
pytest.skip("Windows MSBuild release does not contain any header "
"files (#1777)")
raise
- assert ret == 0
assert err == ""
if os.getenv("build_system") == "msbuild":