diff options
author | Phil Ruffwind <rf@rufflewind.com> | 2016-12-09 15:42:36 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-12-09 16:38:45 -0500 |
commit | ca593c7d55f0e120f322faf74c39fd4d978a6c1d (patch) | |
tree | f24449753bf19cca53cbe97b85cf49cb1299f766 /testsuite/driver/testlib.py | |
parent | 2823492e88889d823a871c193af041ae91784524 (diff) | |
download | haskell-ca593c7d55f0e120f322faf74c39fd4d978a6c1d.tar.gz |
testsuite: make tests respond to SIGINT properly
The `std*_buffer` need to be bytes to avoid breaking Python 3.
Also, using a blanket `except` in Python without specifying the
exception types will catch special exceptions such as
`KeyboardInterrupt`, which can prevent the program from being
interrupted properly.
Test Plan: validate
Reviewers: thomie, austin, bgamari
Reviewed By: bgamari
Differential Revision: https://phabricator.haskell.org/D2805
Diffstat (limited to 'testsuite/driver/testlib.py')
-rw-r--r-- | testsuite/driver/testlib.py | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/testsuite/driver/testlib.py b/testsuite/driver/testlib.py index 7e7d994fa3..5b582e1adf 100644 --- a/testsuite/driver/testlib.py +++ b/testsuite/driver/testlib.py @@ -24,11 +24,6 @@ from testglobals import * from testutil import * from extra_files import extra_src_files -try: - basestring -except: # Python 3 - basestring = (str,bytes) - if config.use_threads: import threading try: @@ -554,7 +549,8 @@ def join_normalisers(*a): Taken from http://stackoverflow.com/a/2158532/946226 """ for el in l: - if isinstance(el, collections.Iterable) and not isinstance(el, basestring): + if (isinstance(el, collections.Iterable) + and not isinstance(el, (bytes, str))): for sub in flatten(el): yield sub else: @@ -833,7 +829,7 @@ def do_test(name, way, func, args, files): try: result = func(*[name,way] + args) - except: + except Exception: pass if opts.expect not in ['pass', 'fail', 'missing-lib']: @@ -841,7 +837,7 @@ def do_test(name, way, func, args, files): try: passFail = result['passFail'] - except: + except (KeyError, TypeError): passFail = 'No passFail found' directory = re.sub('^\\.[/\\\\]', '', opts.testdir) @@ -882,7 +878,7 @@ def badResult(result): if result['passFail'] == 'pass': return False return True - except: + except (KeyError, TypeError): return True def passed(): @@ -1403,7 +1399,7 @@ def read_no_crs(file): # See Note [Universal newlines]. with io.open(file, 'r', encoding='utf8', errors='replace', newline=None) as h: str = h.read() - except: + except Exception: # On Windows, if the program fails very early, it seems the # files stdout/stderr are redirected to may not get created pass @@ -1724,7 +1720,7 @@ def if_verbose_dump( n, f ): try: with io.open(f) as file: print(file.read()) - except: + except Exception: print('') def runCmd(cmd, stdin=None, stdout=None, stderr=None, timeout_multiplier=1.0): @@ -1747,8 +1743,8 @@ def runCmd(cmd, stdin=None, stdout=None, stderr=None, timeout_multiplier=1.0): with io.open(stdin, 'rb') as f: stdin_buffer = f.read() - stdout_buffer = '' - stderr_buffer = '' + stdout_buffer = b'' + stderr_buffer = b'' hStdErr = subprocess.PIPE if stderr is subprocess.STDOUT: |