[commit: ghc] master: testsuite/driver: More Unicode awareness (7d2df32)

git at git.haskell.org git at git.haskell.org
Mon Oct 17 19:02:28 UTC 2016


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

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

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

commit 7d2df32091dfe94f4da34868a64bea56ca74843e
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Sun Oct 16 20:49:36 2016 -0400

    testsuite/driver: More Unicode awareness
    
    Explicitly specify utf8 encoding in a few spots which were failing on
    Windows with Python 3.
    
    Test Plan: Validate
    
    Reviewers: austin, thomie
    
    Differential Revision: https://phabricator.haskell.org/D2602
    
    GHC Trac Issues: #9184


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

7d2df32091dfe94f4da34868a64bea56ca74843e
 testsuite/driver/runtests.py |  9 +++++++--
 testsuite/driver/testlib.py  | 18 +++++++++---------
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/testsuite/driver/runtests.py b/testsuite/driver/runtests.py
index 8a11f44..abbf3c8 100644
--- a/testsuite/driver/runtests.py
+++ b/testsuite/driver/runtests.py
@@ -208,7 +208,7 @@ from testlib import *
 # On Windows we need to set $PATH to include the paths to all the DLLs
 # in order for the dynamic library tests to work.
 if windows or darwin:
-    pkginfo = getStdout([config.ghc_pkg, 'dump'])
+    pkginfo = str(getStdout([config.ghc_pkg, 'dump']))
     topdir = config.libdir
     if windows:
         mingw = os.path.join(topdir, '../mingw/bin')
@@ -303,7 +303,12 @@ for file in t_files:
     if_verbose(2, '====> Scanning %s' % file)
     newTestDir(tempdir, os.path.dirname(file))
     try:
-        exec(open(file).read())
+        if PYTHON3:
+            src = io.open(file, encoding='utf8').read()
+        else:
+            src = open(file).read()
+
+        exec(src)
     except Exception as e:
         traceback.print_exc()
         framework_fail(file, '', str(e))
diff --git a/testsuite/driver/testlib.py b/testsuite/driver/testlib.py
index f2098d2..55d209e 100644
--- a/testsuite/driver/testlib.py
+++ b/testsuite/driver/testlib.py
@@ -826,9 +826,9 @@ def do_test(name, way, func, args, files):
         src_makefile = in_srcdir('Makefile')
         dst_makefile = in_testdir('Makefile')
         if os.path.exists(src_makefile):
-            with open(src_makefile, 'r') as src:
+            with io.open(src_makefile, 'r', encoding='utf8') as src:
                 makefile = re.sub('TOP=.*', 'TOP=' + config.top, src.read(), 1)
-                with open(dst_makefile, 'w') as dst:
+                with io.open(dst_makefile, 'w', encoding='utf8') as dst:
                     dst.write(makefile)
 
     if config.use_threads:
@@ -1289,20 +1289,20 @@ def interpreter_run(name, way, extra_hc_opts, top_mod):
 
     delimiter = '===== program output begins here\n'
 
-    with open(script, 'w') as f:
+    with io.open(script, 'w', encoding='utf8') as f:
         # set the prog name and command-line args to match the compiled
         # environment.
-        f.write(':set prog ' + name + '\n')
-        f.write(':set args ' + opts.extra_run_opts + '\n')
+        f.write(u':set prog ' + name + u'\n')
+        f.write(u':set args ' + opts.extra_run_opts + u'\n')
         # Add marker lines to the stdout and stderr output files, so we
         # can separate GHCi's output from the program's.
-        f.write(':! echo ' + delimiter)
-        f.write(':! echo 1>&2 ' + delimiter)
+        f.write(u':! echo ' + delimiter)
+        f.write(u':! echo 1>&2 ' + delimiter)
         # Set stdout to be line-buffered to match the compiled environment.
-        f.write('System.IO.hSetBuffering System.IO.stdout System.IO.LineBuffering\n')
+        f.write(u'System.IO.hSetBuffering System.IO.stdout System.IO.LineBuffering\n')
         # wrapping in GHC.TopHandler.runIO ensures we get the same output
         # in the event of an exception as for the compiled program.
-        f.write('GHC.TopHandler.runIOFastExit Main.main Prelude.>> Prelude.return ()\n')
+        f.write(u'GHC.TopHandler.runIOFastExit Main.main Prelude.>> Prelude.return ()\n')
 
     stdin = in_testdir(opts.stdin if opts.stdin else add_suffix(name, 'stdin'))
     if os.path.exists(stdin):



More information about the ghc-commits mailing list