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 |
11 import os | 11 import os |
12 import os.path | 12 import os.path |
13 import subprocess | 13 import subprocess |
14 import shutil | 14 import shutil |
15 import sys | 15 import sys |
16 | 16 |
17 | 17 |
18 def _GenerateCompileCommands(files, include_paths): | 18 def _GenerateCompileCommands(files, include_paths): |
19 """Returns a JSON string containing a compilation database for the input.""" | 19 """Returns a JSON string containing a compilation database for the input.""" |
20 include_path_flags = ''.join('-I %s' % include_path | 20 include_path_flags = ' '.join('-I %s' % include_path |
21 for include_path in include_paths) | 21 for include_path in include_paths) |
22 return json.dumps([{'directory': '.', | 22 return json.dumps([{'directory': '.', |
23 'command': 'clang++ -fsyntax-only %s -c %s' % ( | 23 'command': 'clang++ -fsyntax-only %s -c %s' % ( |
24 include_path_flags, f), | 24 include_path_flags, f), |
25 'file': f} for f in files], indent=2) | 25 'file': f} for f in files], indent=2) |
26 | 26 |
27 | 27 |
28 def _NumberOfTestsToString(tests): | 28 def _NumberOfTestsToString(tests): |
29 """Returns an English describing the number of tests.""" | 29 """Returns an English describing the number of tests.""" |
30 return "%d test%s" % (tests, 's' if tests != 1 else '') | 30 return "%d test%s" % (tests, 's' if tests != 1 else '') |
(...skipping 13 matching lines...) Expand all Loading... | |
44 compile_database = os.path.join(test_directory_for_tool, | 44 compile_database = os.path.join(test_directory_for_tool, |
45 'compile_commands.json') | 45 'compile_commands.json') |
46 source_files = glob.glob(os.path.join(test_directory_for_tool, | 46 source_files = glob.glob(os.path.join(test_directory_for_tool, |
47 '*-original.cc')) | 47 '*-original.cc')) |
48 actual_files = ['-'.join([source_file.rsplit('-', 1)[0], 'actual.cc']) | 48 actual_files = ['-'.join([source_file.rsplit('-', 1)[0], 'actual.cc']) |
49 for source_file in source_files] | 49 for source_file in source_files] |
50 expected_files = ['-'.join([source_file.rsplit('-', 1)[0], 'expected.cc']) | 50 expected_files = ['-'.join([source_file.rsplit('-', 1)[0], 'expected.cc']) |
51 for source_file in source_files] | 51 for source_file in source_files] |
52 include_paths = [] | 52 include_paths = [] |
53 include_paths.append( | 53 include_paths.append( |
54 os.path.realpath(os.path.join(tools_clang_directory, '../..'))) | 54 os.path.realpath(os.path.join(tools_clang_directory, '../..'))) |
Ryan Sleevi
2014/08/23 03:26:36
Ooof. I didn't realize we'd done this.
I had trie
| |
55 # Many gtest headers expect to have testing/gtest/include in the include | |
56 # search path. | |
57 include_paths.append( | |
58 os.path.realpath(os.path.join(tools_clang_directory, | |
59 '../..', | |
60 'testing/gtest/include'))) | |
55 | 61 |
56 try: | 62 try: |
57 # Set up the test environment. | 63 # Set up the test environment. |
58 for source, actual in zip(source_files, actual_files): | 64 for source, actual in zip(source_files, actual_files): |
59 shutil.copyfile(source, actual) | 65 shutil.copyfile(source, actual) |
60 # Stage the test files in the git index. If they aren't staged, then | 66 # Stage the test files in the git index. If they aren't staged, then |
61 # run_tools.py will skip them when applying replacements. | 67 # run_tools.py will skip them when applying replacements. |
62 args = ['git', 'add'] | 68 args = ['git', 'add'] |
63 args.extend(actual_files) | 69 args.extend(actual_files) |
64 subprocess.check_call(args) | 70 subprocess.check_call(args) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 finally: | 117 finally: |
112 # No matter what, unstage the git changes we made earlier to avoid polluting | 118 # No matter what, unstage the git changes we made earlier to avoid polluting |
113 # the index. | 119 # the index. |
114 args = ['git', 'reset', '--quiet', 'HEAD'] | 120 args = ['git', 'reset', '--quiet', 'HEAD'] |
115 args.extend(actual_files) | 121 args.extend(actual_files) |
116 subprocess.call(args) | 122 subprocess.call(args) |
117 | 123 |
118 | 124 |
119 if __name__ == '__main__': | 125 if __name__ == '__main__': |
120 sys.exit(main(sys.argv[1:])) | 126 sys.exit(main(sys.argv[1:])) |
OLD | NEW |