From 3317c146e3a2eaec192c378a4e04389cf34246f1 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 6 Apr 2021 21:16:26 +0300 Subject: ctest-driver.py: fix --new-window --- tools/ctest-driver.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'tools') diff --git a/tools/ctest-driver.py b/tools/ctest-driver.py index a3fa3e3..e467bd1 100755 --- a/tools/ctest-driver.py +++ b/tools/ctest-driver.py @@ -34,11 +34,11 @@ def read_file(path): return fd.read() -def run(cmd_line, **kwargs): +def run(cmd_line): try: result = subprocess.run(cmd_line, check=True, universal_newlines=True, stderr=subprocess.STDOUT, - stdout=subprocess.PIPE, **kwargs) + stdout=subprocess.PIPE) assert result.returncode == 0 return result.stdout except subprocess.CalledProcessError as e: @@ -46,6 +46,16 @@ def run(cmd_line, **kwargs): sys.exit(e.returncode) +def run_new_window(cmd_line): + try: + result = subprocess.run(cmd_line, check=True, + creationflags=subprocess.CREATE_NEW_CONSOLE) + assert result.returncode == 0 + return None + except subprocess.CalledProcessError as e: + sys.exit(e.returncode) + + def match_any(s, regexes): if not regexes: return True @@ -65,12 +75,16 @@ def match_pass_regexes(output, regexes): def run_actual_test_driver(args): - creationflags = 0 - if args.new_window and hasattr(subprocess, 'CREATE_NEW_CONSOLE'): - creationflags = subprocess.CREATE_NEW_CONSOLE - output = run([args.exe_path] + args.exe_args, creationflags=creationflags) - sys.stdout.write(output) - match_pass_regexes(output, args.pass_regexes) + cmd_line = [args.exe_path] + args.exe_args + run_func = run + if args.new_window: + run_func = run_new_window + output = run_func(cmd_line) + if args.new_window and args.pass_regexes: + err("Cannot launch child process in a new window and capture its output") + if output is not None: + sys.stdout.write(output) + match_pass_regexes(output, args.pass_regexes) def grep_file(args): -- cgit v1.2.3