[commit: ghc] master: testsuite: make tests respond to SIGINT properly (ca593c7)

git at git.haskell.org git at git.haskell.org
Fri Dec 9 22:04:03 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/ca593c7d55f0e120f322faf74c39fd4d978a6c1d/ghc

>---------------------------------------------------------------

commit ca593c7d55f0e120f322faf74c39fd4d978a6c1d
Author: Phil Ruffwind <rf at rufflewind.com>
Date:   Fri Dec 9 15:42:36 2016 -0500

    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


>---------------------------------------------------------------

ca593c7d55f0e120f322faf74c39fd4d978a6c1d
 testsuite/driver/testlib.py | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/testsuite/driver/testlib.py b/testsuite/driver/testlib.py
index 7e7d994..5b582e1 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:



More information about the ghc-commits mailing list