Commit bde66547 authored by Stefan Behnel's avatar Stefan Behnel

capture C compiler output in test runner and discard it when expecting C compiler failures

parent e1e15520
...@@ -867,15 +867,33 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -867,15 +867,33 @@ class CythonCompileTestCase(unittest.TestCase):
so_path = None so_path = None
if not self.cython_only: if not self.cython_only:
c_compiler_output = None
orig_stderr = os.dup(2) # remember original stderr
try: try:
so_path = self.run_distutils(test_directory, module, workdir, incdir) with tempfile.TemporaryFile() as temp_stderr:
except Exception: os.dup2(temp_stderr.fileno(), 2) # replace stderr by temp file
if expected_errors != '_FAIL_C_COMPILE': try:
raise try:
else: so_path = self.run_distutils(test_directory, module, workdir, incdir)
if expected_errors == '_FAIL_C_COMPILE': finally:
# must raise this outside the try block temp_stderr.seek(0)
raise RuntimeError('should have failed C compile') c_compiler_output = temp_stderr.read().strip()
except Exception:
if expected_errors == '_FAIL_C_COMPILE':
assert c_compiler_output
else:
raise
else:
if c_compiler_output:
print("\n=== C/C++ compiler output: ===")
print(c_compiler_output)
if expected_errors == '_FAIL_C_COMPILE':
# must raise this outside the try block
raise RuntimeError('should have failed C compile')
finally:
os.dup2(orig_stderr, 2) # restore stderr
finally:
os.close(orig_stderr)
return so_path return so_path
class CythonRunTestCase(CythonCompileTestCase): class CythonRunTestCase(CythonCompileTestCase):
......
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