From: Matthew Fernandez Date: Thu, 15 Apr 2021 03:55:55 +0000 (-0700) Subject: support passing extra args to the test suite’s C compiler interface X-Git-Tag: 2.47.2~58^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=beb90d3d39d83aa60da4ab3cf7fccf10ba2bda33;p=graphviz support passing extra args to the test suite’s C compiler interface --- diff --git a/rtest/gvtest.py b/rtest/gvtest.py index 391aca17c..fd41c38a2 100644 --- a/rtest/gvtest.py +++ b/rtest/gvtest.py @@ -7,8 +7,8 @@ import subprocess import tempfile from typing import List, Optional, Tuple -def compile_c(src: Path, link: List[str] = [], dst: Optional[Path] = None) \ - -> Path: +def compile_c(src: Path, cflags: List[str] = [], link: List[str] = [], + dst: Optional[Path] = None) -> Path: ''' compile a C program ''' @@ -22,14 +22,14 @@ def compile_c(src: Path, link: List[str] = [], dst: Optional[Path] = None) \ rtflag = '-MDd' if os.environ.get('configuration') == 'Debug' else '-MD' # construct an invocation of MSVC - args = ['cl', src, '-Fe:', dst, '-nologo', rtflag] + args = ['cl', src, '-Fe:', dst, '-nologo', rtflag] + cflags if len(link) > 0: args += ['-link'] + [f'{l}.lib' for l in link] else: # construct an invocation of the default C compiler cc = os.environ.get('CC', 'cc') - args = [cc, '-std=c99', src, '-o', dst] + args = [cc, '-std=c99', src, '-o', dst] + cflags if len(link) > 0: args += [f'-l{l}' for l in link] @@ -42,8 +42,8 @@ def compile_c(src: Path, link: List[str] = [], dst: Optional[Path] = None) \ return dst -def run_c(src: Path, args: [str] = [], input: str = '', link: List[str] = []) \ - -> Tuple[int, str, str]: +def run_c(src: Path, args: [str] = [], input: str = '', cflags: List[str] = [], + link: List[str] = []) -> Tuple[int, str, str]: ''' compile and run a C program ''' @@ -55,7 +55,7 @@ def run_c(src: Path, args: [str] = [], input: str = '', link: List[str] = []) \ exe = Path(tmp) / 'a.exe' # compile the program - compile_c(src, link, exe) + compile_c(src, cflags, link, exe) # run it p = subprocess.run([exe] + args, input=input, stdout=subprocess.PIPE, diff --git a/rtest/test_examples.py b/rtest/test_examples.py index 5aaa2cf73..642f5084e 100644 --- a/rtest/test_examples.py +++ b/rtest/test_examples.py @@ -35,7 +35,7 @@ def test_compile_example(src): # run the example args = ['-Kneato'] if src in ['demo.c', 'dot.c'] else []; - ret, _, _ = run_c(filepath, args, 'graph {a -- b}', libs) + ret, out, err = run_c(filepath, args, 'graph {a -- b}', link=libs) print(f'returncode: {ret} = 0x{ret:08x}') if ret != 0: