OLD | NEW |
1 # Copyright (C) 2011 Google Inc. All rights reserved. | 1 # Copyright (C) 2011 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions | 4 # modification, are permitted provided that the following conditions |
5 # are met: | 5 # are met: |
6 # 1. Redistributions of source code must retain the above copyright | 6 # 1. Redistributions of source code must retain the above copyright |
7 # notice, this list of conditions and the following disclaimer. | 7 # notice, this list of conditions and the following disclaimer. |
8 # 2. Redistributions in binary form must reproduce the above copyright | 8 # 2. Redistributions in binary form must reproduce the above copyright |
9 # notice, this list of conditions and the following disclaimer in the | 9 # notice, this list of conditions and the following disclaimer in the |
10 # documentation and/or other materials provided with the distribution. | 10 # documentation and/or other materials provided with the distribution. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 'TestImplements2.idl', | 50 'TestImplements2.idl', |
51 'TestImplements3.idl', | 51 'TestImplements3.idl', |
52 'TestPartialInterface.idl', | 52 'TestPartialInterface.idl', |
53 'TestPartialInterfacePython.idl', | 53 'TestPartialInterfacePython.idl', |
54 'TestPartialInterfacePython2.idl', | 54 'TestPartialInterfacePython2.idl', |
55 ]) | 55 ]) |
56 | 56 |
57 all_input_directory = '.' # Relative to Source/ | 57 all_input_directory = '.' # Relative to Source/ |
58 test_input_directory = os.path.join('bindings', 'tests', 'idls') | 58 test_input_directory = os.path.join('bindings', 'tests', 'idls') |
59 reference_directory = os.path.join('bindings', 'tests', 'results') | 59 reference_directory = os.path.join('bindings', 'tests', 'results') |
60 reference_event_names_filename = os.path.join(reference_directory, 'EventInterfa
ces.in') | |
61 | 60 |
62 | 61 |
63 class ScopedTempFileProvider(object): | 62 class ScopedTempFileProvider(object): |
64 def __init__(self): | 63 def __init__(self): |
65 self.file_handles = [] | 64 self.file_handles = [] |
66 self.file_paths = [] | 65 self.file_paths = [] |
67 self.dir_paths = [] | 66 self.dir_paths = [] |
68 | 67 |
69 def __enter__(self): | 68 def __enter__(self): |
70 return self | 69 return self |
(...skipping 26 matching lines...) Expand all Loading... |
97 self.verbose = verbose | 96 self.verbose = verbose |
98 self.executive = executive.Executive() | 97 self.executive = executive.Executive() |
99 self.provider = provider | 98 self.provider = provider |
100 _, self.interfaces_info_filename = provider.new_temp_file() | 99 _, self.interfaces_info_filename = provider.new_temp_file() |
101 # Generate output into the reference directory if resetting results, or | 100 # Generate output into the reference directory if resetting results, or |
102 # a temp directory if not. | 101 # a temp directory if not. |
103 if reset_results: | 102 if reset_results: |
104 self.output_directory = reference_directory | 103 self.output_directory = reference_directory |
105 else: | 104 else: |
106 self.output_directory = provider.new_temp_dir() | 105 self.output_directory = provider.new_temp_dir() |
107 self.event_names_filename = os.path.join(self.output_directory, 'EventIn
terfaces.in') | |
108 | 106 |
109 def run_command(self, cmd): | 107 def run_command(self, cmd): |
110 output = self.executive.run_command(cmd) | 108 output = self.executive.run_command(cmd) |
111 if output: | 109 if output: |
112 print output | 110 print output |
113 | 111 |
114 def generate_from_idl(self, idl_file): | 112 def generate_from_idl(self, idl_file): |
115 cmd = ['python', | 113 cmd = ['python', |
116 'bindings/scripts/idl_compiler.py', | 114 'bindings/scripts/idl_compiler.py', |
117 '--output-dir', self.output_directory, | 115 '--output-dir', self.output_directory, |
(...skipping 21 matching lines...) Expand all Loading... |
139 for filename in fnmatch.filter(files, '*.idl')) | 137 for filename in fnmatch.filter(files, '*.idl')) |
140 return idl_paths | 138 return idl_paths |
141 | 139 |
142 def write_list_file(idl_paths): | 140 def write_list_file(idl_paths): |
143 list_file, list_filename = self.provider.new_temp_file() | 141 list_file, list_filename = self.provider.new_temp_file() |
144 list_contents = ''.join(idl_path + '\n' | 142 list_contents = ''.join(idl_path + '\n' |
145 for idl_path in idl_paths) | 143 for idl_path in idl_paths) |
146 os.write(list_file, list_contents) | 144 os.write(list_file, list_contents) |
147 return list_filename | 145 return list_filename |
148 | 146 |
149 def generate_event_interfaces(event_names_filename): | |
150 cmd = ['python', | |
151 'bindings/scripts/generate_event_interfaces.py', | |
152 '--interfaces-info-file', self.interfaces_info_filename, | |
153 '--event-names-file', event_names_filename, | |
154 '--write-file-only-if-changed', '0'] | |
155 self.run_command(cmd) | |
156 | |
157 def compute_interfaces_info(idl_files_list_filename): | 147 def compute_interfaces_info(idl_files_list_filename): |
158 cmd = ['python', | 148 cmd = ['python', |
159 'bindings/scripts/compute_interfaces_info.py', | 149 'bindings/scripts/compute_interfaces_info.py', |
160 '--idl-files-list', idl_files_list_filename, | 150 '--idl-files-list', idl_files_list_filename, |
161 '--interfaces-info-file', self.interfaces_info_filename, | 151 '--interfaces-info-file', self.interfaces_info_filename, |
162 '--write-file-only-if-changed', '0'] | 152 '--write-file-only-if-changed', '0'] |
163 self.run_command(cmd) | 153 self.run_command(cmd) |
164 | 154 |
165 test_idl_files_list_filename = write_list_file(idl_paths(test_input_dire
ctory)) | 155 # We compute interfaces info for *all* IDL files, not just test IDL |
| 156 # files, as code generator output depends on inheritance (both ancestor |
| 157 # chain and inherited extended attributes), and some real interfaces |
| 158 # are special-cased, such as Node. |
| 159 # |
| 160 # For example, when testing the behavior of interfaces that inherit |
| 161 # from Node, we also need to know that these inherit from EventTarget, |
| 162 # since this is also special-cased and Node inherits from EventTarget, |
| 163 # but this inheritance information requires computing dependencies for |
| 164 # the real Node.idl file. |
166 all_idl_files_list_filename = write_list_file(idl_paths_recursive(all_in
put_directory)) | 165 all_idl_files_list_filename = write_list_file(idl_paths_recursive(all_in
put_directory)) |
167 | |
168 if self.reset_results and self.verbose: | |
169 print 'Reset results: EventInterfaces.in' | |
170 try: | 166 try: |
171 # We first compute interfaces info for testing files only, | |
172 # so we can compare EventInterfaces.in. | |
173 compute_interfaces_info(test_idl_files_list_filename) | |
174 generate_event_interfaces(self.event_names_filename) | |
175 | |
176 # We then compute interfaces info for all IDL files, as code | |
177 # generator output depends on inheritance (both ancestor chain and | |
178 # inherited extended attributes), and some real interfaces are | |
179 # special-cased, such as Node. | |
180 # For example, when testing the behavior of interfaces that inherit | |
181 # from Node, we also need to know that these inherit from | |
182 # EventTarget, since this is also special-cased and Node inherits | |
183 # from EventTarget, but this inheritance information requires | |
184 # computing dependencies for the real Node.idl file. | |
185 # | |
186 # Don't overwrite the event names file generated for testing IDLs | |
187 compute_interfaces_info(all_idl_files_list_filename) | 167 compute_interfaces_info(all_idl_files_list_filename) |
188 except ScriptError, e: | 168 except ScriptError, e: |
189 print 'ERROR: compute_interfaces_info.py' | 169 print 'ERROR: compute_interfaces_info.py' |
190 print e.output | 170 print e.output |
191 return e.exit_code | 171 return e.exit_code |
192 return 0 | 172 return 0 |
193 | 173 |
194 def identical_file(self, reference_filename, output_filename): | 174 def identical_file(self, reference_filename, output_filename): |
195 reference_basename = os.path.basename(reference_filename) | 175 reference_basename = os.path.basename(reference_filename) |
196 cmd = ['diff', | 176 cmd = ['diff', |
(...skipping 19 matching lines...) Expand all Loading... |
216 for output_file in os.listdir(self.output_directory) | 196 for output_file in os.listdir(self.output_directory) |
217 # Skip cache | 197 # Skip cache |
218 if (output_file != 'parsetab.py' and # PLY cache | 198 if (output_file != 'parsetab.py' and # PLY cache |
219 not output_file.endswith('.cache'))] # Jinja cache | 199 not output_file.endswith('.cache'))] # Jinja cache |
220 return all([self.identical_file(reference_filename, output_filename) | 200 return all([self.identical_file(reference_filename, output_filename) |
221 for (reference_filename, output_filename) in file_pairs]) | 201 for (reference_filename, output_filename) in file_pairs]) |
222 | 202 |
223 def no_excess_files(self): | 203 def no_excess_files(self): |
224 generated_files = set(os.listdir(self.output_directory)) | 204 generated_files = set(os.listdir(self.output_directory)) |
225 generated_files.add('.svn') # Subversion working copy directory | 205 generated_files.add('.svn') # Subversion working copy directory |
226 generated_files.add('EventInterfaces.in') # only in Perl, not Python | |
227 excess_files = [output_file | 206 excess_files = [output_file |
228 for output_file in os.listdir(reference_directory) | 207 for output_file in os.listdir(reference_directory) |
229 if output_file not in generated_files] | 208 if output_file not in generated_files] |
230 if excess_files: | 209 if excess_files: |
231 print ('Excess reference files! ' | 210 print ('Excess reference files! ' |
232 '(probably cruft from renaming or deleting):\n' + | 211 '(probably cruft from renaming or deleting):\n' + |
233 '\n'.join(excess_files)) | 212 '\n'.join(excess_files)) |
234 return False | 213 return False |
235 return True | 214 return True |
236 | 215 |
(...skipping 11 matching lines...) Expand all Loading... |
248 print 'DEPENDENCY: %s' % input_filename | 227 print 'DEPENDENCY: %s' % input_filename |
249 continue | 228 continue |
250 | 229 |
251 idl_path = os.path.join(test_input_directory, input_filename) | 230 idl_path = os.path.join(test_input_directory, input_filename) |
252 if self.generate_from_idl(idl_path): | 231 if self.generate_from_idl(idl_path): |
253 return False | 232 return False |
254 if self.reset_results and self.verbose: | 233 if self.reset_results and self.verbose: |
255 print 'Reset results: %s' % input_filename | 234 print 'Reset results: %s' % input_filename |
256 | 235 |
257 # Detect all changes | 236 # Detect all changes |
258 passed = self.identical_file(reference_event_names_filename, | 237 passed = self.identical_output_files() |
259 self.event_names_filename) | |
260 passed &= self.identical_output_files() | |
261 passed &= self.no_excess_files() | 238 passed &= self.no_excess_files() |
262 return passed | 239 return passed |
263 | 240 |
264 def main(self): | 241 def main(self): |
265 current_scm = detect_scm_system(os.curdir) | 242 current_scm = detect_scm_system(os.curdir) |
266 os.chdir(os.path.join(current_scm.checkout_root, 'Source')) | 243 os.chdir(os.path.join(current_scm.checkout_root, 'Source')) |
267 | 244 |
268 all_tests_passed = self.run_tests() | 245 all_tests_passed = self.run_tests() |
269 if all_tests_passed: | 246 if all_tests_passed: |
270 if self.verbose: | 247 if self.verbose: |
271 print | 248 print |
272 print PASS_MESSAGE | 249 print PASS_MESSAGE |
273 return 0 | 250 return 0 |
274 print | 251 print |
275 print FAIL_MESSAGE | 252 print FAIL_MESSAGE |
276 return -1 | 253 return -1 |
277 | 254 |
278 | 255 |
279 def run_bindings_tests(reset_results, verbose): | 256 def run_bindings_tests(reset_results, verbose): |
280 with ScopedTempFileProvider() as provider: | 257 with ScopedTempFileProvider() as provider: |
281 return BindingsTests(reset_results, verbose, provider).main() | 258 return BindingsTests(reset_results, verbose, provider).main() |
OLD | NEW |