From beb90d3d39d83aa60da4ab3cf7fccf10ba2bda33 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Wed, 14 Apr 2021 20:55:55 -0700 Subject: [PATCH] =?utf8?q?support=20passing=20extra=20args=20to=20the=20te?= =?utf8?q?st=20suite=E2=80=99s=20C=20compiler=20interface?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- rtest/gvtest.py | 14 +++++++------- rtest/test_examples.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) 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: -- 2.40.0