| 562 | return result |
| 563 | |
| 564 | def fail_test(self, condition, dump_difference=True, dump_stdio=True, |
| 565 | dump_stack=True): |
| 566 | if not condition: |
| 567 | return |
| 568 | |
| 569 | if dump_difference and hasattr(self, "difference"): |
| 570 | f = StringIO.StringIO() |
| 571 | self.difference.pprint(f) |
| 572 | annotation("changes caused by the last build command", |
| 573 | f.getvalue()) |
| 574 | |
| 575 | if dump_stdio: |
| 576 | self.dump_stdio() |
| 577 | |
| 578 | if "--preserve" in sys.argv: |
| 579 | print |
| 580 | print "*** Copying the state of working dir into 'failed_test' ***" |
| 581 | print |
| 582 | path = os.path.join(self.original_workdir, "failed_test") |
| 583 | if os.path.isdir(path): |
| 584 | shutil.rmtree(path, ignore_errors=False) |
| 585 | elif os.path.exists(path): |
| 586 | raise "Path " + path + " already exists and is not a directory" |
| 587 | shutil.copytree(self.workdir, path) |
| 588 | print "The failed command was:" |
| 589 | print " ".join(self.last_program_invocation) |
| 590 | |
| 591 | if dump_stack: |
| 592 | annotate_stack_trace() |
| 593 | sys.exit(1) |
| 594 | |
| 595 | # A number of methods below check expectations with actual difference |
| 596 | # between directory trees before and after a build. All the 'expect*' |