[pypy-svn] r58907 - in pypy/branch/cbuild-refactor/pypy/translator/platform: . test
fijal at codespeak.net
fijal at codespeak.net
Fri Oct 10 15:28:41 CEST 2008
Author: fijal
Date: Fri Oct 10 15:28:39 2008
New Revision: 58907
Modified:
pypy/branch/cbuild-refactor/pypy/translator/platform/linux.py
pypy/branch/cbuild-refactor/pypy/translator/platform/test/test_platform.py
Log:
(pedronis, fijal) Nice error messages
Modified: pypy/branch/cbuild-refactor/pypy/translator/platform/linux.py
==============================================================================
--- pypy/branch/cbuild-refactor/pypy/translator/platform/linux.py (original)
+++ pypy/branch/cbuild-refactor/pypy/translator/platform/linux.py Fri Oct 10 15:28:39 2008
@@ -3,6 +3,11 @@
from pypy.translator.platform import Platform, CompilationError, ExecutionResult
from subprocess import PIPE, Popen
+import py
+from pypy.tool.ansi_print import ansi_log
+log = py.log.Producer("cbuild")
+py.log.setconsumer("cbuild", ansi_log)
+
def _run_subprocess(args):
pipe = Popen(args, executable=args[0],
stdout=PIPE, stderr=PIPE, shell=False)
@@ -19,8 +24,16 @@
args = [self.cc] + [str(f) for f in cfiles]
exe_name = cfiles[0].dirpath().join(cfiles[0].purebasename)
args += ['-o', str(exe_name)]
+ log.execute(' '.join(args))
returncode, stdout, stderr = _run_subprocess(args)
if returncode != 0:
+ errorfile = exe_name.new(ext='errors')
+ errorfile.write(stderr)
+ stderrlines = stderr.splitlines()
+ for line in stderrlines[:5]:
+ log.ERROR(line)
+ if len(stderrlines) > 5:
+ log.ERROR('...')
raise CompilationError(stdout, stderr)
return exe_name
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 Fri Oct 10 15:28:39 2008
@@ -1,10 +1,11 @@
+import py
from pypy.tool.udir import udir
-from pypy.translator.platform import host
+from pypy.translator.platform import host, CompilationError
def test_simple_enough():
cfile = udir.join('test_simple_enough.c')
- tmpdir = cfile.write('''
+ cfile.write('''
#include <stdio.h>
int main()
{
@@ -17,3 +18,15 @@
assert res.out == '42\n'
assert res.err == ''
assert res.returncode == 0
+
+def test_nice_errors():
+ cfile = udir.join('test_nice_errors.c')
+ cfile.write('')
+ try:
+ executable = host.compile([cfile], None)
+ except CompilationError, e:
+ filename = cfile.dirpath().join(cfile.purebasename + '.errors')
+ assert filename.read() == e.err
+ else:
+ py.test.fail("Did not raise")
+
More information about the Pypy-commit
mailing list