From 5960e398ecab914effec821cc6da5f3a091fdb50 Mon Sep 17 00:00:00 2001 From: Andy Hayden Date: Sat, 8 Jun 2019 04:46:57 -0700 Subject: make tests quieter (#2468) Don't mix every http request in with the tests output. Don't print that the file servers are starting unless -vv flag is passed. Capture the output of run with run_output which returns stdout, stderr and exit_code. Test against this rather than relying on sys.exit. --- tools/util.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'tools/util.py') diff --git a/tools/util.py b/tools/util.py index 1ca4752a8..2b8adcfb7 100644 --- a/tools/util.py +++ b/tools/util.py @@ -1,4 +1,5 @@ # Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +import collections import os import re import shutil @@ -59,7 +60,15 @@ def run(args, quiet=False, cwd=None, env=None, merge_env=None): sys.exit(rc) -def run_output(args, quiet=False, cwd=None, env=None, merge_env=None): +CmdResult = collections.namedtuple('CmdResult', ['out', 'err', 'code']) + + +def run_output(args, + quiet=False, + cwd=None, + env=None, + merge_env=None, + exit_on_fail=False): if merge_env is None: merge_env = {} args[0] = os.path.normpath(args[0]) @@ -67,7 +76,25 @@ def run_output(args, quiet=False, cwd=None, env=None, merge_env=None): print " ".join(args) env = make_env(env=env, merge_env=merge_env) shell = os.name == "nt" # Run through shell to make .bat/.cmd files work. - return subprocess.check_output(args, cwd=cwd, env=env, shell=shell) + p = subprocess.Popen( + args, + cwd=cwd, + env=env, + shell=shell, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + try: + out, err = p.communicate() + except subprocess.CalledProcessError as e: + p.kill() + p.wait() + raise e + retcode = p.poll() + if retcode and exit_on_fail: + sys.exit(retcode) + # Ignore Windows CRLF (\r\n). + return CmdResult( + out.replace('\r\n', '\n'), err.replace('\r\n', '\n'), retcode) def shell_quote_win(arg): -- cgit v1.2.3