Commit c7dc24bc authored by Stefan Behnel's avatar Stefan Behnel

runtests: include the C compiler error output in the compile exception to show...

runtests: include the C compiler error output in the compile exception to show it at the end of the test run.
parent d9adf77d
......@@ -82,7 +82,7 @@ from ..Shadow import __version__ as cython_version
from ..Compiler.Errors import CompileError
from .Inline import cython_inline
from .Dependencies import cythonize
from ..Utils import captured_fd
from ..Utils import captured_fd, print_captured
PGO_CONFIG = {
......@@ -107,37 +107,6 @@ else:
return name
def get_encoding_candidates():
candidates = [sys.getdefaultencoding()]
for stream in (sys.stdout, sys.stdin, sys.__stdout__, sys.__stdin__):
encoding = getattr(stream, 'encoding', None)
# encoding might be None (e.g. somebody redirects stdout):
if encoding is not None and encoding not in candidates:
candidates.append(encoding)
return candidates
def prepare_captured(captured):
captured_bytes = captured.strip()
if not captured_bytes:
return None
for encoding in get_encoding_candidates():
try:
return captured_bytes.decode(encoding)
except UnicodeDecodeError:
pass
# last resort: print at least the readable ascii parts correctly.
return captured_bytes.decode('latin-1')
def print_captured(captured, output, header_line=None):
captured = prepare_captured(captured)
if captured:
if header_line:
output.write(header_line)
output.write(captured)
@magics_class
class CythonMagics(Magics):
......
......@@ -443,6 +443,37 @@ def captured_fd(stream=2, encoding=None):
os.close(orig_stream)
def get_encoding_candidates():
candidates = [sys.getdefaultencoding()]
for stream in (sys.stdout, sys.stdin, sys.__stdout__, sys.__stdin__):
encoding = getattr(stream, 'encoding', None)
# encoding might be None (e.g. somebody redirects stdout):
if encoding is not None and encoding not in candidates:
candidates.append(encoding)
return candidates
def prepare_captured(captured):
captured_bytes = captured.strip()
if not captured_bytes:
return None
for encoding in get_encoding_candidates():
try:
return captured_bytes.decode(encoding)
except UnicodeDecodeError:
pass
# last resort: print at least the readable ascii parts correctly.
return captured_bytes.decode('latin-1')
def print_captured(captured, output, header_line=None):
captured = prepare_captured(captured)
if captured:
if header_line:
output.write(header_line)
output.write(captured)
def print_bytes(s, header_text=None, end=b'\n', file=sys.stdout, flush=True):
if header_text:
file.write(header_text) # note: text! => file.write() instead of out.write()
......
......@@ -1277,10 +1277,25 @@ class CythonCompileTestCase(unittest.TestCase):
extension.language = 'c++'
if IS_PY2:
workdir = str(workdir) # work around type check in distutils that disallows unicode strings
build_extension.extensions = [extension]
build_extension.build_temp = workdir
build_extension.build_lib = workdir
build_extension.run()
from Cython.Utils import captured_fd, prepare_captured
from distutils.errors import CompileError
error = None
with captured_fd(2) as get_stderr:
try:
build_extension.run()
except CompileError as exc:
error = exc
stderr = prepare_captured(get_stderr())
if stderr:
print("Compiler output for module %s:\n%s" % (module, stderr))
if error is not None:
raise CompileError("%s\nCompiler output:\n%s" % (error, stderr))
finally:
os.chdir(cwd)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment