|
17 | 17 | from mypy import build
|
18 | 18 | from mypy.errors import CompileError
|
19 | 19 | from mypy.options import Options
|
20 |
| -from mypy.test.config import test_temp_dir |
| 20 | +from mypy.test.config import mypyc_output_dir, test_temp_dir |
21 | 21 | from mypy.test.data import DataDrivenTestCase
|
22 | 22 | from mypy.test.helpers import assert_module_equivalence, perform_file_operations
|
23 | 23 | from mypyc.build import construct_groups
|
@@ -281,6 +281,7 @@ def run_case_step(self, testcase: DataDrivenTestCase, incremental_step: int) ->
|
281 | 281 | if not run_setup(setup_file, ["build_ext", "--inplace"]):
|
282 | 282 | if testcase.config.getoption("--mypyc-showc"):
|
283 | 283 | show_c(cfiles)
|
| 284 | + copy_output_files(mypyc_output_dir) |
284 | 285 | assert False, "Compilation failed"
|
285 | 286 |
|
286 | 287 | # Assert that an output file got created
|
@@ -344,6 +345,7 @@ def run_case_step(self, testcase: DataDrivenTestCase, incremental_step: int) ->
|
344 | 345 | )
|
345 | 346 | print("hint: You may need to build a debug version of Python first and use it")
|
346 | 347 | print('hint: See also "Debuggging Segfaults" in mypyc/doc/dev-intro.md')
|
| 348 | + copy_output_files(mypyc_output_dir) |
347 | 349 |
|
348 | 350 | # Verify output.
|
349 | 351 | if bench:
|
@@ -457,3 +459,17 @@ def fix_native_line_number(message: str, fnam: str, delta: int) -> str:
|
457 | 459 | message,
|
458 | 460 | )
|
459 | 461 | return message
|
| 462 | + |
| 463 | + |
| 464 | +def copy_output_files(target_dir: str) -> None: |
| 465 | + try: |
| 466 | + os.mkdir(target_dir) |
| 467 | + except OSError: |
| 468 | + # Only copy data for the first failure, to avoid excessive output in case |
| 469 | + # many tests fail |
| 470 | + return |
| 471 | + |
| 472 | + for fnam in glob.glob("build/*.[ch]"): |
| 473 | + shutil.copy(fnam, target_dir) |
| 474 | + |
| 475 | + sys.stderr.write(f"\nGenerated files: {target_dir} (for first failure only)\n\n") |
0 commit comments