| 589 | return result |
| 590 | |
| 591 | def fail_test(self, condition, dump_difference=True, dump_stdio=True, |
| 592 | dump_stack=True): |
| 593 | if not condition: |
| 594 | return |
| 595 | |
| 596 | if dump_difference and hasattr(self, "difference"): |
| 597 | f = StringIO() |
| 598 | self.difference.pprint(f) |
| 599 | annotation("changes caused by the last build command", |
| 600 | f.getvalue()) |
| 601 | |
| 602 | if dump_stdio: |
| 603 | self.dump_stdio() |
| 604 | |
| 605 | if "--preserve" in sys.argv: |
| 606 | print() |
| 607 | print("*** Copying the state of working dir into 'failed_test' ***") |
| 608 | print() |
| 609 | path = os.path.join(self.original_workdir, "failed_test") |
| 610 | if os.path.isdir(path): |
| 611 | shutil.rmtree(path, ignore_errors=False) |
| 612 | elif os.path.exists(path): |
| 613 | raise "Path " + path + " already exists and is not a directory" |
| 614 | shutil.copytree(self.workdir, path) |
| 615 | print("The failed command was:") |
| 616 | print(" ".join(self.last_program_invocation)) |
| 617 | |
| 618 | if dump_stack: |
| 619 | annotate_stack_trace() |
| 620 | sys.exit(1) |
| 621 | |
| 622 | # A number of methods below check expectations with actual difference |
| 623 | # between directory trees before and after a build. All the 'expect*' |