OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Test for TranslationUnitGenerator tool.""" | 6 """Test for TranslationUnitGenerator tool.""" |
7 | 7 |
8 import difflib | 8 import difflib |
9 import glob | 9 import glob |
10 import json | 10 import json |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 actual += '.filepaths' | 61 actual += '.filepaths' |
62 expected = actual + '.expected' | 62 expected = actual + '.expected' |
63 print '[ RUN ] %s' % os.path.relpath(actual) | 63 print '[ RUN ] %s' % os.path.relpath(actual) |
64 expected_output = actual_output = None | 64 expected_output = actual_output = None |
65 with open(expected, 'r') as f: | 65 with open(expected, 'r') as f: |
66 expected_output = f.readlines() | 66 expected_output = f.readlines() |
67 with open(actual, 'r') as f: | 67 with open(actual, 'r') as f: |
68 actual_output = f.readlines() | 68 actual_output = f.readlines() |
69 has_same_filepaths = True | 69 has_same_filepaths = True |
70 for expected_line, actual_line in zip(expected_output, actual_output): | 70 for expected_line, actual_line in zip(expected_output, actual_output): |
| 71 if '//' in actual_output: |
| 72 if actual_output.split('//')[1] != expected_output: |
| 73 sys.stdout.write('expected: %s' % expected_output) |
| 74 sys.stdout.write('actual: %s' % actual_output.split('//')[1]) |
| 75 break |
| 76 else: |
| 77 continue |
71 if ntpath.basename(expected_line) != ntpath.basename(actual_line): | 78 if ntpath.basename(expected_line) != ntpath.basename(actual_line): |
72 sys.stdout.write(ntpath.basename(expected_line)) | 79 sys.stdout.write('expected: %s' % ntpath.basename(expected_line)) |
73 sys.stdout.write(ntpath.basename(actual_line)) | 80 sys.stdout.write('actual: %s' % ntpath.basename(actual_line)) |
74 has_same_filepaths = False | 81 has_same_filepaths = False |
75 break | 82 break |
76 if not has_same_filepaths: | 83 if not has_same_filepaths: |
77 failed += 1 | 84 failed += 1 |
78 for line in difflib.unified_diff(expected_output, actual_output, | 85 for line in difflib.unified_diff(expected_output, actual_output, |
79 fromfile=os.path.relpath(expected), | 86 fromfile=os.path.relpath(expected), |
80 tofile=os.path.relpath(actual)): | 87 tofile=os.path.relpath(actual)): |
81 sys.stdout.write(line) | 88 sys.stdout.write(line) |
82 print '[ FAILED ] %s' % os.path.relpath(actual) | 89 print '[ FAILED ] %s' % os.path.relpath(actual) |
83 # Don't clean up the file on failure, so the results can be referenced | 90 # Don't clean up the file on failure, so the results can be referenced |
84 # more easily. | 91 # more easily. |
85 continue | 92 continue |
86 print '[ OK ] %s' % os.path.relpath(actual) | 93 print '[ OK ] %s' % os.path.relpath(actual) |
87 passed += 1 | 94 passed += 1 |
88 os.remove(actual) | 95 os.remove(actual) |
89 | 96 |
90 if failed == 0: | 97 if failed == 0: |
91 os.remove(compile_database) | 98 os.remove(compile_database) |
92 | 99 |
93 print '[==========] %s ran.' % _NumberOfTestsToString(len(source_files)) | 100 print '[==========] %s ran.' % _NumberOfTestsToString(len(source_files)) |
94 if passed > 0: | 101 if passed > 0: |
95 print '[ PASSED ] %s.' % _NumberOfTestsToString(passed) | 102 print '[ PASSED ] %s.' % _NumberOfTestsToString(passed) |
96 if failed > 0: | 103 if failed > 0: |
97 print '[ FAILED ] %s.' % _NumberOfTestsToString(failed) | 104 print '[ FAILED ] %s.' % _NumberOfTestsToString(failed) |
98 | 105 |
99 | 106 |
100 if __name__ == '__main__': | 107 if __name__ == '__main__': |
101 sys.exit(main()) | 108 sys.exit(main()) |
OLD | NEW |