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 |
11 | 11 |
12 found = 'Found dependency' | 12 found = 'Found dependency' |
13 found_all = 'Found dependency (all)' | 13 found_all = 'Found dependency (all)' |
14 not_found = 'No dependencies' | 14 not_found = 'No dependencies' |
15 | 15 |
16 | 16 |
17 def _CreateConfigFile(files, targets): | 17 def _CreateConfigFile(files, targets): |
18 """Creates the analyzer conflig file, which is used as the input to analyzer. | 18 """Creates the analyzer config file, which is used as the input to analyzer. |
19 See description of analyzer.py for description of the arguments.""" | 19 See description of analyzer.py for description of the arguments.""" |
20 f = open('test_file', 'w') | 20 f = open('test_file', 'w') |
21 to_write = {'files': files, 'targets': targets } | 21 to_write = {'files': files, 'targets': targets } |
22 json.dump(to_write, f) | 22 json.dump(to_write, f) |
23 f.close() | 23 f.close() |
24 | 24 |
25 | 25 |
26 def _CreateBogusConfigFile(): | 26 def _CreateBogusConfigFile(): |
27 f = open('test_file','w') | 27 f = open('test_file','w') |
28 f.write('bogus') | 28 f.write('bogus') |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 | 137 |
138 def EnsureInvalidTargets(expected_invalid_targets): | 138 def EnsureInvalidTargets(expected_invalid_targets): |
139 """Verifies output contains invalid_targets.""" | 139 """Verifies output contains invalid_targets.""" |
140 result = _ReadOutputFileContents() | 140 result = _ReadOutputFileContents() |
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 |
| 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 |
| 150 # A is compiled in this case, only B. |
| 151 _CreateConfigFile(['b.c'], []) |
| 152 test.run_gyp('static_library_test.gyp', *CommonArgs()) |
| 153 EnsureContains(matched=True, build_targets={'a' ,'b'}) |
| 154 |
147 # Verifies config_path must be specified. | 155 # Verifies config_path must be specified. |
148 test.run_gyp('test.gyp') | 156 test.run_gyp('test.gyp') |
149 EnsureStdoutContains('Must specify files to analyze via config_path') | 157 EnsureStdoutContains('Must specify files to analyze via config_path') |
150 | 158 |
151 # Verifies config_path must point to a valid file. | 159 # Verifies config_path must point to a valid file. |
152 test.run_gyp('test.gyp', '-Gconfig_path=bogus_file', | 160 test.run_gyp('test.gyp', '-Gconfig_path=bogus_file', |
153 '-Ganalyzer_output_path=analyzer_output') | 161 '-Ganalyzer_output_path=analyzer_output') |
154 EnsureError('Unable to open file bogus_file') | 162 EnsureError('Unable to open file bogus_file') |
155 | 163 |
156 # Verify 'invalid_targets' is present when bad target is specified. | 164 # Verify 'invalid_targets' is present when bad target is specified. |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 _CreateConfigFile(['f.c'], []) | 352 _CreateConfigFile(['f.c'], []) |
345 run_analyzer4() | 353 run_analyzer4() |
346 EnsureContains(matched=True, build_targets={'e', 'f'}) | 354 EnsureContains(matched=True, build_targets={'e', 'f'}) |
347 | 355 |
348 _CreateConfigFile(['d.c'], []) | 356 _CreateConfigFile(['d.c'], []) |
349 run_analyzer4() | 357 run_analyzer4() |
350 EnsureContains(matched=True, build_targets={'a', 'b', 'c', 'd'}) | 358 EnsureContains(matched=True, build_targets={'a', 'b', 'c', 'd'}) |
351 | 359 |
352 _CreateConfigFile(['i.c'], []) | 360 _CreateConfigFile(['i.c'], []) |
353 run_analyzer4() | 361 run_analyzer4() |
354 EnsureContains(matched=True, build_targets={'h'}) | 362 EnsureContains(matched=True, build_targets={'h', 'i'}) |
355 | 363 |
356 test.pass_test() | 364 test.pass_test() |
OLD | NEW |