OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 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 harness for chromium clang tools.""" | 6 """Test harness for chromium clang tools.""" |
7 | 7 |
8 import difflib | 8 import difflib |
9 import glob | 9 import glob |
10 import json | 10 import json |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 passed = 0 | 80 passed = 0 |
81 failed = 0 | 81 failed = 0 |
82 for expected, actual in zip(expected_files, actual_files): | 82 for expected, actual in zip(expected_files, actual_files): |
83 print '[ RUN ] %s' % os.path.relpath(actual) | 83 print '[ RUN ] %s' % os.path.relpath(actual) |
84 expected_output = actual_output = None | 84 expected_output = actual_output = None |
85 with open(expected, 'r') as f: | 85 with open(expected, 'r') as f: |
86 expected_output = f.readlines() | 86 expected_output = f.readlines() |
87 with open(actual, 'r') as f: | 87 with open(actual, 'r') as f: |
88 actual_output = f.readlines() | 88 actual_output = f.readlines() |
89 if actual_output != expected_output: | 89 if actual_output != expected_output: |
90 print '[ FAILED ] %s' % os.path.relpath(actual) | |
91 failed += 1 | 90 failed += 1 |
92 for line in difflib.unified_diff(expected_output, actual_output, | 91 for line in difflib.unified_diff(expected_output, actual_output, |
93 fromfile=os.path.relpath(expected), | 92 fromfile=os.path.relpath(expected), |
94 tofile=os.path.relpath(actual)): | 93 tofile=os.path.relpath(actual)): |
95 sys.stdout.write(line) | 94 sys.stdout.write(line) |
| 95 print '[ FAILED ] %s' % os.path.relpath(actual) |
96 # Don't clean up the file on failure, so the results can be referenced | 96 # Don't clean up the file on failure, so the results can be referenced |
97 # more easily. | 97 # more easily. |
98 continue | 98 continue |
99 print '[ OK ] %s' % os.path.relpath(actual) | 99 print '[ OK ] %s' % os.path.relpath(actual) |
100 passed += 1 | 100 passed += 1 |
101 os.remove(actual) | 101 os.remove(actual) |
102 | 102 |
103 if failed == 0: | 103 if failed == 0: |
104 os.remove(compile_database) | 104 os.remove(compile_database) |
105 | 105 |
106 print '[==========] %s ran.' % _NumberOfTestsToString(len(source_files)) | 106 print '[==========] %s ran.' % _NumberOfTestsToString(len(source_files)) |
107 if passed > 0: | 107 if passed > 0: |
108 print '[ PASSED ] %s.' % _NumberOfTestsToString(passed) | 108 print '[ PASSED ] %s.' % _NumberOfTestsToString(passed) |
109 if failed > 0: | 109 if failed > 0: |
110 print '[ FAILED ] %s.' % _NumberOfTestsToString(failed) | 110 print '[ FAILED ] %s.' % _NumberOfTestsToString(failed) |
111 finally: | 111 finally: |
112 # No matter what, unstage the git changes we made earlier to avoid polluting | 112 # No matter what, unstage the git changes we made earlier to avoid polluting |
113 # the index. | 113 # the index. |
114 args = ['git', 'reset', '--quiet', 'HEAD'] | 114 args = ['git', 'reset', '--quiet', 'HEAD'] |
115 args.extend(actual_files) | 115 args.extend(actual_files) |
116 subprocess.call(args) | 116 subprocess.call(args) |
117 | 117 |
118 | 118 |
119 if __name__ == '__main__': | 119 if __name__ == '__main__': |
120 sys.exit(main(sys.argv[1:])) | 120 sys.exit(main(sys.argv[1:])) |
OLD | NEW |