| OLD | NEW |
| 1 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 # for details. All rights reserved. Use of this source code is governed by a | 2 # for details. All rights reserved. Use of this source code is governed by a |
| 3 # BSD-style license that can be found in the LICENSE file. | 3 # BSD-style license that can be found in the LICENSE file. |
| 4 # | 4 # |
| 5 # For now we have to use this trampoline to turn --dart-flags command line | 5 # For now we have to use this trampoline to turn --dart-flags command line |
| 6 # switch into env variable DART_FLAGS. Eventually, DumpRenderTree should | 6 # switch into env variable DART_FLAGS. Eventually, DumpRenderTree should |
| 7 # support --dart-flags and this hack may go away. | 7 # support --dart-flags and this hack may go away. |
| 8 # | 8 # |
| 9 # Expected invocation: python drt-trampoline.py <path to DRT> <DRT command line> | 9 # Expected invocation: python drt-trampoline.py <path to DRT> <DRT command line> |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 raise Exception( | 41 raise Exception( |
| 42 'Bad file expectation (%s), ' % out_expected_file | 42 'Bad file expectation (%s), ' % out_expected_file |
| 43 + 'please specify either a .txt or a .png file') | 43 + 'please specify either a .txt or a .png file') |
| 44 elif arg.endswith('.html'): | 44 elif arg.endswith('.html'): |
| 45 test_file = arg | 45 test_file = arg |
| 46 cmd.append(arg) | 46 cmd.append(arg) |
| 47 else: | 47 else: |
| 48 cmd.append(arg) | 48 cmd.append(arg) |
| 49 | 49 |
| 50 | 50 |
| 51 p = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE) | 51 stdout = subprocess.PIPE if out_expected_file else None |
| 52 p = subprocess.Popen(cmd, env=env, stdout=stdout) |
| 52 output, error = p.communicate() | 53 output, error = p.communicate() |
| 53 if p.returncode != 0: | 54 if p.returncode != 0: |
| 54 raise Exception('Failed to run command. return code=%s' % p.returncode) | 55 raise Exception('Failed to run command. return code=%s' % p.returncode) |
| 55 | 56 |
| 56 if out_expected_file: | 57 if out_expected_file: |
| 57 # Compare output to the given expectation file. | 58 # Compare output to the given expectation file. |
| 58 expectation = None | 59 expectation = None |
| 59 if is_png: | 60 if is_png: |
| 60 # DRT prints the image to STDOUT, but includes extra text that we trim: | 61 # DRT prints the image to STDOUT, but includes extra text that we trim: |
| 61 # - 4 header lines | 62 # - 4 header lines |
| (...skipping 16 matching lines...) Expand all Loading... |
| 78 print 'Expectation matches' | 79 print 'Expectation matches' |
| 79 else: | 80 else: |
| 80 # Generate a temporary file in the same place as the .html file: | 81 # Generate a temporary file in the same place as the .html file: |
| 81 out_file = test_file[:test_file.rfind('.html')] + out_expected_file[-4:] | 82 out_file = test_file[:test_file.rfind('.html')] + out_expected_file[-4:] |
| 82 with open(out_file, 'w') as f: | 83 with open(out_file, 'w') as f: |
| 83 f.write(output) | 84 f.write(output) |
| 84 print 'FAIL' | 85 print 'FAIL' |
| 85 print 'Expectation didn\'t match. Update expectations by running:\n' | 86 print 'Expectation didn\'t match. Update expectations by running:\n' |
| 86 print 'cp %s %s\n' % (out_file, out_expected_file) | 87 print 'cp %s %s\n' % (out_file, out_expected_file) |
| 87 print '#EOF' | 88 print '#EOF' |
| 88 else: | |
| 89 # Pipe through the output for non-layout tests. | |
| 90 print output | |
| 91 | 89 |
| 92 if __name__ == '__main__': | 90 if __name__ == '__main__': |
| 93 try: | 91 try: |
| 94 sys.exit(main(sys.argv)) | 92 sys.exit(main(sys.argv)) |
| 95 except StandardError as e: | 93 except StandardError as e: |
| 96 print 'Fail: ' + str(e) | 94 print 'Fail: ' + str(e) |
| 97 sys.exit(1) | 95 sys.exit(1) |
| OLD | NEW |