Commit 39bf23cc authored by Stefan Behnel's avatar Stefan Behnel

improve presentation of C compiler stderr/stdout output in test runner

parent 6008ea90
...@@ -388,12 +388,14 @@ def captured_fd(stream=2, encoding=None): ...@@ -388,12 +388,14 @@ def captured_fd(stream=2, encoding=None):
os.close(orig_stream) os.close(orig_stream)
def print_bytes(s, stream=sys.stdout): def print_bytes(s, end=b'\n', file=sys.stdout, flush=True):
stream.flush() file.flush()
try: try:
out = stream.buffer # Py3 out = file.buffer # Py3
except AttributeError: except AttributeError:
out = stream # Py2 out = file # Py2
out.write(s) out.write(s)
out.write(b'\n') if end:
out.write(end)
if flush:
out.flush() out.flush()
...@@ -865,25 +865,35 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -865,25 +865,35 @@ class CythonCompileTestCase(unittest.TestCase):
so_path = None so_path = None
if not self.cython_only: if not self.cython_only:
from Cython.Utils import captured_fd, print_bytes from Cython.Utils import captured_fd, print_bytes
get_stderr = None show_output = True
get_stderr = get_stdout = None
try: try:
with captured_fd(1) as get_stdout:
with captured_fd(2) as get_stderr: with captured_fd(2) as get_stderr:
so_path = self.run_distutils(test_directory, module, workdir, incdir) so_path = self.run_distutils(test_directory, module, workdir, incdir)
except Exception: except Exception:
if 'cerror' in self.tags['tag'] and get_stderr and get_stderr(): if 'cerror' in self.tags['tag'] and get_stderr and get_stderr():
pass show_output = False # expected C compiler failure
else: else:
raise raise
else: else:
c_compiler_stderr = get_stderr().strip()
if c_compiler_stderr:
print("\n=== C/C++ compiler error output: ===")
print_bytes(c_compiler_stderr)
if 'cerror' in self.tags['tag']: if 'cerror' in self.tags['tag']:
# must raise this outside the try block
raise RuntimeError('should have failed C compile') raise RuntimeError('should have failed C compile')
finally:
if show_output:
stdout = get_stdout and get_stdout().strip()
if stdout:
print("\n=== C/C++ compiler output: ===")
print_bytes(stdout, end=None)
stderr = get_stderr and get_stderr().strip()
if stderr:
print("\n=== C/C++ compiler error output: ===")
print_bytes(stderr, end=None)
if stdout or stderr:
print("\n==============================")
return so_path return so_path
class CythonRunTestCase(CythonCompileTestCase): class CythonRunTestCase(CythonCompileTestCase):
def setUp(self): def setUp(self):
CythonCompileTestCase.setUp(self) CythonCompileTestCase.setUp(self)
......
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