[pypy-svn] r59146 - in pypy/branch/cbuild-refactor/pypy/translator/platform: . test

afa at codespeak.net afa at codespeak.net
Thu Oct 16 16:19:45 CEST 2008


Author: afa
Date: Thu Oct 16 16:19:44 2008
New Revision: 59146

Modified:
   pypy/branch/cbuild-refactor/pypy/translator/platform/__init__.py
   pypy/branch/cbuild-refactor/pypy/translator/platform/distutils_platform.py
   pypy/branch/cbuild-refactor/pypy/translator/platform/test/test_platform.py
   pypy/branch/cbuild-refactor/pypy/translator/platform/test/test_posix.py
Log:
Let most tests pass on Windows in pypy\translator\platform:

- Do not add the exception message to the distutils output: the compiler already provided useful messages.

- on win32, "echo" is a shell builtin

- convert line endings when needed.
  Calling subprocess.Popen with universal_newlines=True could have been better, but it does not work with my python 2.5.1 :-(


Modified: pypy/branch/cbuild-refactor/pypy/translator/platform/__init__.py
==============================================================================
--- pypy/branch/cbuild-refactor/pypy/translator/platform/__init__.py	(original)
+++ pypy/branch/cbuild-refactor/pypy/translator/platform/__init__.py	Thu Oct 16 16:19:44 2008
@@ -27,8 +27,8 @@
 
 class CompilationError(Exception):
     def __init__(self, out, err):
-        self.out = out
-        self.err = err
+        self.out = out.replace('\r\n', '\n')
+        self.err = err.replace('\r\n', '\n')
 
     def __repr__(self):
         return "<CompilationError instance>"
@@ -38,8 +38,8 @@
 class ExecutionResult(object):
     def __init__(self, returncode, out, err):
         self.returncode = returncode
-        self.out = out
-        self.err = err
+        self.out = out.replace('\r\n', '\n')
+        self.err = err.replace('\r\n', '\n')
 
     def __repr__(self):
         return "<ExecutionResult retcode=%d>" % (self.returncode,)

Modified: pypy/branch/cbuild-refactor/pypy/translator/platform/distutils_platform.py
==============================================================================
--- pypy/branch/cbuild-refactor/pypy/translator/platform/distutils_platform.py	(original)
+++ pypy/branch/cbuild-refactor/pypy/translator/platform/distutils_platform.py	Thu Oct 16 16:19:44 2008
@@ -84,8 +84,8 @@
         data = ''
         try:
             saved_environ = os.environ.copy()
+            c = stdoutcapture.Capture(mixed_out_err = True)
             try:
-                c = stdoutcapture.Capture(mixed_out_err = True)
                 self._build()
             finally:
                 # workaround for a distutils bugs where some env vars can
@@ -96,15 +96,11 @@
                 foutput, foutput = c.done()
                 data = foutput.read()
                 if data:
-                    fdump = basename.new(ext='errors').open("w")
+                    fdump = basename.new(ext='errors').open("wb")
                     fdump.write(data)
                     fdump.close()
         except (distutils.errors.CompileError,
                 distutils.errors.LinkError), e:
-            data = data.rstrip()
-            if data:
-                data += '\n'
-            data += str(e)
             raise CompilationError('', data)
         except:
             print >>sys.stderr, data

Modified: pypy/branch/cbuild-refactor/pypy/translator/platform/test/test_platform.py
==============================================================================
--- pypy/branch/cbuild-refactor/pypy/translator/platform/test/test_platform.py	(original)
+++ pypy/branch/cbuild-refactor/pypy/translator/platform/test/test_platform.py	Thu Oct 16 16:19:44 2008
@@ -58,7 +58,7 @@
             executable = self.platform.compile([cfile], ExternalCompilationInfo())
         except CompilationError, e:
             filename = cfile.dirpath().join(cfile.purebasename + '.errors')
-            assert filename.read() == e.err
+            assert filename.read('r') == e.err
         else:
             py.test.fail("Did not raise")
 

Modified: pypy/branch/cbuild-refactor/pypy/translator/platform/test/test_posix.py
==============================================================================
--- pypy/branch/cbuild-refactor/pypy/translator/platform/test/test_posix.py	(original)
+++ pypy/branch/cbuild-refactor/pypy/translator/platform/test/test_posix.py	Thu Oct 16 16:19:44 2008
@@ -3,12 +3,19 @@
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
 from pypy.tool.udir import udir
 from StringIO import StringIO
+import sys
 
 def test_echo():
     res = host.execute('echo', '42 24')
     assert res.out == '42 24\n'
-    res = host.execute('echo', ['42', '24'])
-    assert res.out == '42 24\n'
+
+    if sys.platform == 'win32':
+        # echo is a shell builtin on Windows
+        res = host.execute('cmd', ['/c', 'echo', '42', '24'])
+        assert res.out == '42 24\n'
+    else:
+        res = host.execute('echo', ['42', '24'])
+        assert res.out == '42 24\n'
 
 class TestMakefile(object):
     platform = host



More information about the Pypy-commit mailing list