OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2014 Google Inc. All rights reserved. | 2 # Copyright (c) 2014 Google Inc. 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 """Tests for analyzer | 6 """Tests for analyzer |
7 """ | 7 """ |
8 | 8 |
9 import json | 9 import json |
10 import TestGyp | 10 import TestGyp |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 actual_invalid_targets = set(result['invalid_targets']) | 141 actual_invalid_targets = set(result['invalid_targets']) |
142 if actual_invalid_targets != expected_invalid_targets: | 142 if actual_invalid_targets != expected_invalid_targets: |
143 print 'actual invalid_targets:', actual_invalid_targets, \ | 143 print 'actual invalid_targets:', actual_invalid_targets, \ |
144 '\nexpected :', expected_invalid_targets | 144 '\nexpected :', expected_invalid_targets |
145 test.fail_test() | 145 test.fail_test() |
146 | 146 |
147 | 147 |
148 # Two targets, A and B (both static_libraries) and A depends upon B. If a file | 148 # Two targets, A and B (both static_libraries) and A depends upon B. If a file |
149 # in B changes, then both A and B are output. It is not strictly necessary that | 149 # in B changes, then both A and B are output. It is not strictly necessary that |
150 # A is compiled in this case, only B. | 150 # A is compiled in this case, only B. |
151 _CreateConfigFile(['b.c'], []) | 151 _CreateConfigFile(['b.c'], ['a']) |
152 test.run_gyp('static_library_test.gyp', *CommonArgs()) | 152 test.run_gyp('static_library_test.gyp', *CommonArgs()) |
153 EnsureContains(matched=True, build_targets={'a' ,'b'}) | 153 EnsureContains(targets={'a'}, matched=True, build_targets={'a' ,'b'}) |
154 | 154 |
155 # Verifies config_path must be specified. | 155 # Verifies config_path must be specified. |
156 test.run_gyp('test.gyp') | 156 test.run_gyp('test.gyp') |
157 EnsureStdoutContains('Must specify files to analyze via config_path') | 157 EnsureStdoutContains('Must specify files to analyze via config_path') |
158 | 158 |
159 # Verifies config_path must point to a valid file. | 159 # Verifies config_path must point to a valid file. |
160 test.run_gyp('test.gyp', '-Gconfig_path=bogus_file', | 160 test.run_gyp('test.gyp', '-Gconfig_path=bogus_file', |
161 '-Ganalyzer_output_path=analyzer_output') | 161 '-Ganalyzer_output_path=analyzer_output') |
162 EnsureError('Unable to open file bogus_file') | 162 EnsureError('Unable to open file bogus_file') |
163 | 163 |
164 # Verify 'invalid_targets' is present when bad target is specified. | 164 # Verify 'invalid_targets' is present when bad target is specified. |
165 _CreateConfigFile(['exe2.c'], ['bad_target']) | 165 _CreateConfigFile(['exe2.c'], ['bad_target', 'all', 'exe2']) |
166 run_analyzer() | 166 run_analyzer() |
167 EnsureInvalidTargets({'bad_target'}) | 167 EnsureInvalidTargets({'bad_target'}) |
168 | 168 |
169 # Verifies config_path must point to a valid json file. | 169 # Verifies config_path must point to a valid json file. |
170 _CreateBogusConfigFile() | 170 _CreateBogusConfigFile() |
171 run_analyzer() | 171 run_analyzer() |
172 EnsureError('Unable to parse config file test_file') | 172 EnsureError('Unable to parse config file test_file') |
173 | 173 |
174 # Trivial test of a source. | 174 # Trivial test of a source. |
175 _CreateConfigFile(['foo.c'], []) | 175 _CreateConfigFile(['foo.c'], ['all', 'exe2']) |
176 run_analyzer() | 176 run_analyzer() |
177 EnsureContains(matched=True, build_targets={'exe'}) | 177 EnsureContains(targets={'all'}, matched=True, build_targets={'exe'}) |
178 | 178 |
179 # Conditional source that is excluded. | 179 # Conditional source that is excluded. |
180 _CreateConfigFile(['conditional_source.c'], []) | 180 _CreateConfigFile(['conditional_source.c'], ['all', 'exe2']) |
181 run_analyzer() | 181 run_analyzer() |
182 EnsureContains(matched=False) | 182 EnsureContains(matched=False) |
183 | 183 |
184 # Conditional source that is included by way of argument. | 184 # Conditional source that is included by way of argument. |
185 _CreateConfigFile(['conditional_source.c'], []) | 185 _CreateConfigFile(['conditional_source.c'], ['all', 'exe2']) |
186 run_analyzer('-Dtest_variable=1') | 186 run_analyzer('-Dtest_variable=1') |
187 EnsureContains(matched=True, build_targets={'exe'}) | 187 EnsureContains(targets={'all'}, matched=True, build_targets={'exe'}) |
188 | 188 |
189 # Two unknown files. | 189 # Two unknown files. |
190 _CreateConfigFile(['unknown1.c', 'unoknow2.cc'], []) | 190 _CreateConfigFile(['unknown1.c', 'unoknow2.cc'], ['all', 'exe2']) |
191 run_analyzer() | 191 run_analyzer() |
192 EnsureContains() | 192 EnsureContains() |
193 | 193 |
194 # Two unknown files. | 194 # Two unknown files. |
195 _CreateConfigFile(['unknown1.c', 'subdir/subdir_sourcex.c'], []) | 195 _CreateConfigFile(['unknown1.c', 'subdir/subdir_sourcex.c'], ['all', 'exe2']) |
196 run_analyzer() | 196 run_analyzer() |
197 EnsureContains() | 197 EnsureContains() |
198 | 198 |
199 # Included dependency | 199 # Included dependency |
200 _CreateConfigFile(['unknown1.c', 'subdir/subdir_source.c'], []) | 200 _CreateConfigFile(['unknown1.c', 'subdir/subdir_source.c'], ['all', 'exe2']) |
201 run_analyzer() | 201 run_analyzer() |
202 EnsureContains(matched=True, build_targets={'exe', 'exe3'}) | 202 EnsureContains(targets={'all'}, matched=True, build_targets={'exe', 'exe3'}) |
203 | 203 |
204 # Included inputs to actions. | 204 # Included inputs to actions. |
205 _CreateConfigFile(['action_input.c'], []) | 205 _CreateConfigFile(['action_input.c'], ['all', 'exe2']) |
206 run_analyzer() | 206 run_analyzer() |
207 EnsureContains(matched=True, build_targets={'exe'}) | 207 EnsureContains(targets={'all'}, matched=True, build_targets={'exe'}) |
208 | 208 |
209 # Don't consider outputs. | 209 # Don't consider outputs. |
210 _CreateConfigFile(['action_output.c'], []) | 210 _CreateConfigFile(['action_output.c'], ['all', 'exe2']) |
211 run_analyzer() | 211 run_analyzer() |
212 EnsureContains(matched=False) | 212 EnsureContains(matched=False) |
213 | 213 |
214 # Rule inputs. | 214 # Rule inputs. |
215 _CreateConfigFile(['rule_input.c'], []) | 215 _CreateConfigFile(['rule_input.c'], ['all', 'exe2']) |
216 run_analyzer() | 216 run_analyzer() |
217 EnsureContains(matched=True, build_targets={'exe'}) | 217 EnsureContains(targets={'all'}, matched=True, build_targets={'exe'}) |
218 | 218 |
219 # Ignore path specified with PRODUCT_DIR. | 219 # Ignore path specified with PRODUCT_DIR. |
220 _CreateConfigFile(['product_dir_input.c'], []) | 220 _CreateConfigFile(['product_dir_input.c'], ['all', 'exe2']) |
221 run_analyzer() | 221 run_analyzer() |
222 EnsureContains(matched=False) | 222 EnsureContains(matched=False) |
223 | 223 |
224 # Path specified via a variable. | 224 # Path specified via a variable. |
225 _CreateConfigFile(['subdir/subdir_source2.c'], []) | 225 _CreateConfigFile(['subdir/subdir_source2.c'], ['all', 'exe2']) |
226 run_analyzer() | 226 run_analyzer() |
227 EnsureContains(matched=True, build_targets={'exe'}) | 227 EnsureContains(targets={'all'}, matched=True, build_targets={'exe'}) |
228 | 228 |
229 # Verifies paths with // are fixed up correctly. | 229 # Verifies paths with // are fixed up correctly. |
230 _CreateConfigFile(['parent_source.c'], []) | 230 _CreateConfigFile(['parent_source.c'], ['all', 'exe2']) |
231 run_analyzer() | 231 run_analyzer() |
232 EnsureContains(matched=True, build_targets={'exe', 'exe3'}) | 232 EnsureContains(targets={'all'}, matched=True, build_targets={'exe', 'exe3'}) |
233 | 233 |
234 # Verifies relative paths are resolved correctly. | 234 # Verifies relative paths are resolved correctly. |
235 _CreateConfigFile(['subdir/subdir_source.h'], []) | 235 _CreateConfigFile(['subdir/subdir_source.h'], ['all', 'exe2']) |
236 run_analyzer() | 236 run_analyzer() |
237 EnsureContains(matched=True, build_targets={'exe'}) | 237 EnsureContains(targets={'all'}, matched=True, build_targets={'exe'}) |
238 | 238 |
239 # Verifies relative paths in inputs are resolved correctly. | 239 # Verifies relative paths in inputs are resolved correctly. |
240 _CreateConfigFile(['rel_path1.h'], []) | 240 _CreateConfigFile(['rel_path1.h'], ['all', 'exe2']) |
241 run_analyzer() | 241 run_analyzer() |
242 EnsureContains(matched=True, build_targets={'exe'}) | 242 EnsureContains(targets={'all'}, matched=True, build_targets={'exe'}) |
243 | 243 |
244 # Various permutations when passing in targets. | 244 # Various permutations when passing in targets. |
245 _CreateConfigFile(['exe2.c', 'subdir/subdir2b_source.c'], ['exe', 'exe3']) | 245 _CreateConfigFile(['exe2.c', 'subdir/subdir2b_source.c'], |
| 246 ['exe', 'exe3', 'all', 'exe2']) |
246 run_analyzer() | 247 run_analyzer() |
247 EnsureContains(matched=True, targets={'exe3'}, build_targets={'exe2', 'exe3'}) | 248 EnsureContains(matched=True, targets={'all', 'exe2', 'exe3'}, |
| 249 build_targets={'exe2', 'exe3'}) |
248 | 250 |
249 _CreateConfigFile(['exe2.c', 'subdir/subdir2b_source.c'], ['exe']) | 251 _CreateConfigFile(['exe2.c', 'subdir/subdir2b_source.c'], |
| 252 ['exe', 'all', 'exe2']) |
250 run_analyzer() | 253 run_analyzer() |
251 EnsureContains(matched=True, build_targets={'exe2', 'exe3'}) | 254 EnsureContains(matched=True, targets={'all', 'exe2'}, |
| 255 build_targets={'exe2', 'exe3'}) |
252 | 256 |
253 # Verifies duplicates are ignored. | 257 # Verifies duplicates are ignored. |
254 _CreateConfigFile(['exe2.c', 'subdir/subdir2b_source.c'], ['exe', 'exe']) | 258 _CreateConfigFile(['exe2.c', 'subdir/subdir2b_source.c'], |
| 259 ['exe', 'exe', 'all', 'exe2']) |
255 run_analyzer() | 260 run_analyzer() |
256 EnsureContains(matched=True, build_targets={'exe2', 'exe3'}) | 261 EnsureContains(matched=True, targets={'all', 'exe2'}, |
| 262 build_targets={'exe2', 'exe3'}) |
257 | 263 |
258 _CreateConfigFile(['exe2.c'], ['exe']) | 264 _CreateConfigFile(['exe2.c'], ['exe', 'all', 'exe2']) |
259 run_analyzer() | 265 run_analyzer() |
260 EnsureContains(matched=True, build_targets={'exe2'}) | 266 EnsureContains(matched=True, targets={'exe2'}, build_targets={'exe2'}) |
261 | 267 |
262 _CreateConfigFile(['exe2.c'], []) | 268 _CreateConfigFile(['exe2.c'], ['all', 'exe2']) |
263 run_analyzer() | 269 run_analyzer() |
264 EnsureContains(matched=True, build_targets={'exe2'}) | 270 EnsureContains(matched=True, targets={'exe2'}, build_targets={'exe2'}) |
265 | 271 |
266 _CreateConfigFile(['subdir/subdir2b_source.c', 'exe2.c'], []) | 272 _CreateConfigFile(['subdir/subdir2b_source.c', 'exe2.c'], ['all', 'exe2']) |
267 run_analyzer() | 273 run_analyzer() |
268 EnsureContains(matched=True, build_targets={'exe2', 'exe3'}) | 274 EnsureContains(matched=True, targets={'all', 'exe2'}, |
| 275 build_targets={'exe2', 'exe3'}) |
269 | 276 |
270 _CreateConfigFile(['subdir/subdir2b_source.c'], ['exe3']) | 277 _CreateConfigFile(['subdir/subdir2b_source.c'], ['exe3', 'all', 'exe2']) |
271 run_analyzer() | 278 run_analyzer() |
272 EnsureContains(matched=True, targets={'exe3'}, build_targets={'exe3'}) | 279 EnsureContains(matched=True, targets={'all', 'exe3'}, build_targets={'exe3'}) |
273 | 280 |
274 _CreateConfigFile(['exe2.c'], []) | 281 _CreateConfigFile(['foo.c'], ['all', 'exe2']) |
275 run_analyzer() | 282 run_analyzer() |
276 EnsureContains(matched=True, build_targets={'exe2'}) | 283 EnsureContains(matched=True, targets={'all'}, build_targets={'exe'}) |
277 | |
278 _CreateConfigFile(['foo.c'], []) | |
279 run_analyzer() | |
280 EnsureContains(matched=True, build_targets={'exe'}) | |
281 | 284 |
282 # Assertions when modifying build (gyp/gypi) files, especially when said files | 285 # Assertions when modifying build (gyp/gypi) files, especially when said files |
283 # are included. | 286 # are included. |
284 _CreateConfigFile(['subdir2/d.cc'], ['exe', 'exe2', 'foo', 'exe3']) | 287 _CreateConfigFile(['subdir2/d.cc'], ['exe', 'exe2', 'foo', 'exe3']) |
285 run_analyzer2() | 288 run_analyzer2() |
286 EnsureContains(matched=True, targets={'exe', 'foo'}, build_targets={'exe'}) | 289 EnsureContains(matched=True, targets={'exe', 'foo'}, build_targets={'exe'}) |
287 | 290 |
288 _CreateConfigFile(['subdir2/subdir.includes.gypi'], | 291 _CreateConfigFile(['subdir2/subdir.includes.gypi'], |
289 ['exe', 'exe2', 'foo', 'exe3']) | 292 ['exe', 'exe2', 'foo', 'exe3']) |
290 run_analyzer2() | 293 run_analyzer2() |
291 EnsureContains(matched=True, targets={'exe', 'foo'}, build_targets={'exe'}) | 294 EnsureContains(matched=True, targets={'exe', 'foo'}, build_targets={'exe'}) |
292 | 295 |
293 _CreateConfigFile(['subdir2/subdir.gyp'], ['exe', 'exe2', 'foo', 'exe3']) | 296 _CreateConfigFile(['subdir2/subdir.gyp'], ['exe', 'exe2', 'foo', 'exe3']) |
294 run_analyzer2() | 297 run_analyzer2() |
295 EnsureContains(matched=True, targets={'exe', 'foo'}, build_targets={'exe'}) | 298 EnsureContains(matched=True, targets={'exe', 'foo'}, build_targets={'exe'}) |
296 | 299 |
297 _CreateConfigFile(['test2.includes.gypi'], ['exe', 'exe2', 'foo', 'exe3']) | 300 _CreateConfigFile(['test2.includes.gypi'], ['exe', 'exe2', 'foo', 'exe3']) |
298 run_analyzer2() | 301 run_analyzer2() |
299 EnsureContains(matched=True, targets={'exe', 'exe2', 'exe3'}, | 302 EnsureContains(matched=True, targets={'exe', 'exe2', 'exe3'}, |
300 build_targets={'exe', 'exe2', 'exe3'}) | 303 build_targets={'exe', 'exe2', 'exe3'}) |
301 | 304 |
302 # Verify modifying a file included makes all targets dirty. | 305 # Verify modifying a file included makes all targets dirty. |
303 _CreateConfigFile(['common.gypi'], ['exe', 'exe2', 'foo', 'exe3']) | 306 _CreateConfigFile(['common.gypi'], ['exe', 'exe2', 'foo', 'exe3']) |
304 run_analyzer2('-Icommon.gypi') | 307 run_analyzer2('-Icommon.gypi') |
305 EnsureMatchedAll({'exe', 'exe2', 'foo', 'exe3'}) | 308 EnsureMatchedAll({'exe', 'exe2', 'foo', 'exe3'}) |
306 | 309 |
307 # Assertions from test3.gyp. | 310 # Assertions from test3.gyp. |
308 _CreateConfigFile(['d.c', 'f.c'], ['a']) | 311 _CreateConfigFile(['d.c', 'f.c'], ['a', 'all']) |
309 run_analyzer3() | 312 run_analyzer3() |
310 EnsureContains(matched=True, targets={'a'}, build_targets={'a', 'b'}) | 313 EnsureContains(matched=True, targets={'a', 'all'}, build_targets={'a', 'b'}) |
311 | 314 |
312 _CreateConfigFile(['f.c'], ['a']) | 315 _CreateConfigFile(['f.c'], ['a', 'all']) |
313 run_analyzer3() | 316 run_analyzer3() |
314 EnsureContains(matched=True, targets={'a'}, build_targets={'a', 'b'}) | 317 EnsureContains(matched=True, targets={'a', 'all'}, build_targets={'a', 'b'}) |
315 | 318 |
316 _CreateConfigFile(['f.c'], []) | 319 _CreateConfigFile(['f.c'], ['all']) |
317 run_analyzer3() | 320 run_analyzer3() |
318 EnsureContains(matched=True, build_targets={'a', 'b'}) | 321 EnsureContains(matched=True, targets={'all'}, build_targets={'a', 'b'}) |
319 | 322 |
320 _CreateConfigFile(['c.c', 'e.c'], []) | 323 _CreateConfigFile(['c.c', 'e.c'], ['all']) |
321 run_analyzer3() | 324 run_analyzer3() |
322 EnsureContains(matched=True, build_targets={'a', 'b', 'c', 'e'}) | 325 EnsureContains(matched=True, targets={'all'}, |
| 326 build_targets={'a', 'b', 'c', 'e'}) |
323 | 327 |
324 _CreateConfigFile(['d.c'], ['a']) | 328 _CreateConfigFile(['d.c'], ['a', 'all']) |
325 run_analyzer3() | 329 run_analyzer3() |
326 EnsureContains(matched=True, targets={'a'}, build_targets={'a', 'b'}) | 330 EnsureContains(matched=True, targets={'a', 'all'}, build_targets={'a', 'b'}) |
327 | 331 |
328 _CreateConfigFile(['a.c'], ['a', 'b']) | 332 _CreateConfigFile(['a.c'], ['a', 'b', 'all']) |
329 run_analyzer3() | 333 run_analyzer3() |
330 EnsureContains(matched=True, targets={'a'}, build_targets={'a'}) | 334 EnsureContains(matched=True, targets={'a', 'all'}, build_targets={'a'}) |
331 | 335 |
332 _CreateConfigFile(['a.c'], ['a', 'b']) | 336 _CreateConfigFile(['a.c'], ['a', 'b', 'all']) |
333 run_analyzer3() | 337 run_analyzer3() |
334 EnsureContains(matched=True, targets={'a'}, build_targets={'a'}) | 338 EnsureContains(matched=True, targets={'a', 'all'}, build_targets={'a'}) |
335 | 339 |
336 _CreateConfigFile(['d.c'], ['a', 'b']) | 340 _CreateConfigFile(['d.c'], ['a', 'b', 'all']) |
337 run_analyzer3() | 341 run_analyzer3() |
338 EnsureContains(matched=True, targets={'a', 'b'}, build_targets={'a', 'b'}) | 342 EnsureContains(matched=True, targets={'a', 'b', 'all'}, |
| 343 build_targets={'a', 'b'}) |
339 | 344 |
340 _CreateConfigFile(['f.c'], ['a']) | 345 _CreateConfigFile(['f.c'], ['a', 'all']) |
341 run_analyzer3() | 346 run_analyzer3() |
342 EnsureContains(matched=True, targets={'a'}, build_targets={'a', 'b'}) | 347 EnsureContains(matched=True, targets={'a', 'all'}, build_targets={'a', 'b'}) |
343 | 348 |
344 _CreateConfigFile(['a.c'], ['a']) | 349 _CreateConfigFile(['a.c'], ['a', 'all']) |
345 run_analyzer3() | 350 run_analyzer3() |
346 EnsureContains(matched=True, targets={'a'}, build_targets={'a'}) | 351 EnsureContains(matched=True, targets={'a', 'all'}, build_targets={'a'}) |
347 | 352 |
348 _CreateConfigFile(['a.c'], []) | 353 _CreateConfigFile(['a.c'], ['all']) |
349 run_analyzer3() | 354 run_analyzer3() |
350 EnsureContains(matched=True, build_targets={'a'}) | 355 EnsureContains(matched=True, targets={'all'}, build_targets={'a'}) |
351 | 356 |
352 _CreateConfigFile(['d.c'], []) | 357 _CreateConfigFile(['d.c'], ['all']) |
353 run_analyzer3() | 358 run_analyzer3() |
354 EnsureContains(matched=True, build_targets={'a', 'b'}) | 359 EnsureContains(matched=True, targets={'all'}, build_targets={'a', 'b'}) |
355 | 360 |
356 # Assertions around test4.gyp. | 361 # Assertions around test4.gyp. |
357 _CreateConfigFile(['f.c'], []) | 362 _CreateConfigFile(['f.c'], ['a', 'e', 'h']) |
358 run_analyzer4() | 363 run_analyzer4() |
359 EnsureContains(matched=True, build_targets={'e', 'f'}) | 364 EnsureContains(matched=True, targets={'e'}, build_targets={'e', 'f'}) |
360 | 365 |
361 _CreateConfigFile(['d.c'], []) | 366 _CreateConfigFile(['d.c'], ['a', 'e', 'h']) |
362 run_analyzer4() | 367 run_analyzer4() |
363 EnsureContains(matched=True, build_targets={'a', 'b', 'c', 'd'}) | 368 EnsureContains(matched=True, targets={'a'}, build_targets={'a', 'b', 'c', 'd'}) |
364 | 369 |
365 _CreateConfigFile(['i.c'], []) | 370 _CreateConfigFile(['i.c'], ['a', 'e', 'h']) |
366 run_analyzer4() | 371 run_analyzer4() |
367 EnsureContains(matched=True, build_targets={'h', 'i'}) | 372 EnsureContains(matched=True, targets={'h'}, build_targets={'h', 'i'}) |
368 | 373 |
369 test.pass_test() | 374 test.pass_test() |
OLD | NEW |