diff options
| author | Andy Hayden <andyhayden1@gmail.com> | 2019-06-08 04:46:57 -0700 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2019-06-08 07:46:57 -0400 |
| commit | 5960e398ecab914effec821cc6da5f3a091fdb50 (patch) | |
| tree | bb12c155ef59b725dcc0d7a32b757e47718cdaa1 /tools/util.py | |
| parent | 4ea2df6759abf3a99e07fe720987805075c8a18b (diff) | |
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.
Diffstat (limited to 'tools/util.py')
| -rw-r--r-- | tools/util.py | 31 |
1 files changed, 29 insertions, 2 deletions
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): |
