| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 test.run_gyp('test4.gyp', *args, **kw) | 69 test.run_gyp('test4.gyp', *args, **kw) |
| 70 | 70 |
| 71 | 71 |
| 72 def EnsureContains(targets=set(), matched=False, build_targets=set()): | 72 def EnsureContains(targets=set(), matched=False, build_targets=set()): |
| 73 """Verifies output contains |targets|.""" | 73 """Verifies output contains |targets|.""" |
| 74 result = _ReadOutputFileContents() | 74 result = _ReadOutputFileContents() |
| 75 if result.get('error', None): | 75 if result.get('error', None): |
| 76 print 'unexpected error', result.get('error') | 76 print 'unexpected error', result.get('error') |
| 77 test.fail_test() | 77 test.fail_test() |
| 78 | 78 |
| 79 if result.get('warning', None): | 79 if result.get('invalid_targets', None): |
| 80 print 'unexpected warning', result.get('warning') | 80 print 'unexpected invalid_targets', result.get('invalid_targets') |
| 81 test.fail_test() | 81 test.fail_test() |
| 82 | 82 |
| 83 actual_targets = set(result['targets']) | 83 actual_targets = set(result['targets']) |
| 84 if actual_targets != targets: | 84 if actual_targets != targets: |
| 85 print 'actual targets:', actual_targets, '\nexpected targets:', targets | 85 print 'actual targets:', actual_targets, '\nexpected targets:', targets |
| 86 test.fail_test() | 86 test.fail_test() |
| 87 | 87 |
| 88 actual_build_targets = set(result['build_targets']) | 88 actual_build_targets = set(result['build_targets']) |
| 89 if actual_build_targets != build_targets: | 89 if actual_build_targets != build_targets: |
| 90 print 'actual build_targets:', actual_build_targets, \ | 90 print 'actual build_targets:', actual_build_targets, \ |
| 91 '\nexpected build_targets:', build_targets | 91 '\nexpected build_targets:', build_targets |
| 92 test.fail_test() | 92 test.fail_test() |
| 93 | 93 |
| 94 if matched and result['status'] != found: | 94 if matched and result['status'] != found: |
| 95 print 'expected', found, 'got', result['status'] | 95 print 'expected', found, 'got', result['status'] |
| 96 test.fail_test() | 96 test.fail_test() |
| 97 elif not matched and result['status'] != not_found: | 97 elif not matched and result['status'] != not_found: |
| 98 print 'expected', not_found, 'got', result['status'] | 98 print 'expected', not_found, 'got', result['status'] |
| 99 test.fail_test() | 99 test.fail_test() |
| 100 | 100 |
| 101 | 101 |
| 102 def EnsureMatchedAll(targets): | 102 def EnsureMatchedAll(targets): |
| 103 result = _ReadOutputFileContents() | 103 result = _ReadOutputFileContents() |
| 104 if result.get('error', None): | 104 if result.get('error', None): |
| 105 print 'unexpected error', result.get('error') | 105 print 'unexpected error', result.get('error') |
| 106 test.fail_test() | 106 test.fail_test() |
| 107 | 107 |
| 108 if result.get('warning', None): | 108 if result.get('invalid_targets', None): |
| 109 print 'unexpected warning', result.get('warning') | 109 print 'unexpected invalid_targets', result.get('invalid_targets') |
| 110 test.fail_test() | 110 test.fail_test() |
| 111 | 111 |
| 112 if result['status'] != found_all: | 112 if result['status'] != found_all: |
| 113 print 'expected', found_all, 'got', result['status'] | 113 print 'expected', found_all, 'got', result['status'] |
| 114 test.fail_test() | 114 test.fail_test() |
| 115 | 115 |
| 116 actual_targets = set(result['targets']) | 116 actual_targets = set(result['targets']) |
| 117 if actual_targets != targets: | 117 if actual_targets != targets: |
| 118 print 'actual targets:', actual_targets, '\nexpected targets:', targets | 118 print 'actual targets:', actual_targets, '\nexpected targets:', targets |
| 119 test.fail_test() | 119 test.fail_test() |
| 120 | 120 |
| 121 | 121 |
| 122 def EnsureError(expected_error_string): | 122 def EnsureError(expected_error_string): |
| 123 """Verifies output contains the error string.""" | 123 """Verifies output contains the error string.""" |
| 124 result = _ReadOutputFileContents() | 124 result = _ReadOutputFileContents() |
| 125 if result.get('error', '').find(expected_error_string) == -1: | 125 if result.get('error', '').find(expected_error_string) == -1: |
| 126 print 'actual error:', result.get('error', ''), '\nexpected error:', \ | 126 print 'actual error:', result.get('error', ''), '\nexpected error:', \ |
| 127 expected_error_string | 127 expected_error_string |
| 128 test.fail_test() | 128 test.fail_test() |
| 129 | 129 |
| 130 | 130 |
| 131 def EnsureStdoutContains(expected_error_string): | 131 def EnsureStdoutContains(expected_error_string): |
| 132 if test.stdout().find(expected_error_string) == -1: | 132 if test.stdout().find(expected_error_string) == -1: |
| 133 print 'actual stdout:', test.stdout(), '\nexpected stdout:', \ | 133 print 'actual stdout:', test.stdout(), '\nexpected stdout:', \ |
| 134 expected_error_string | 134 expected_error_string |
| 135 test.fail_test() | 135 test.fail_test() |
| 136 | 136 |
| 137 | 137 |
| 138 def EnsureWarning(expected_warning_string): | 138 def EnsureInvalidTargets(expected_invalid_targets): |
| 139 """Verifies output contains the warning string.""" | 139 """Verifies output contains invalid_targets.""" |
| 140 result = _ReadOutputFileContents() | 140 result = _ReadOutputFileContents() |
| 141 if result.get('warning', '').find(expected_warning_string) == -1: | 141 actual_invalid_targets = set(result['invalid_targets']) |
| 142 print 'actual warning:', result.get('warning', ''), \ | 142 if actual_invalid_targets != expected_invalid_targets: |
| 143 '\nexpected warning:', expected_warning_string | 143 print 'actual invalid_targets:', actual_invalid_targets, \ |
| 144 '\nexpected :', expected_invalid_targets |
| 144 test.fail_test() | 145 test.fail_test() |
| 145 | 146 |
| 146 # Verifies config_path must be specified. | 147 # Verifies config_path must be specified. |
| 147 test.run_gyp('test.gyp') | 148 test.run_gyp('test.gyp') |
| 148 EnsureStdoutContains('Must specify files to analyze via config_path') | 149 EnsureStdoutContains('Must specify files to analyze via config_path') |
| 149 | 150 |
| 150 # Verifies config_path must point to a valid file. | 151 # Verifies config_path must point to a valid file. |
| 151 test.run_gyp('test.gyp', '-Gconfig_path=bogus_file', | 152 test.run_gyp('test.gyp', '-Gconfig_path=bogus_file', |
| 152 '-Ganalyzer_output_path=analyzer_output') | 153 '-Ganalyzer_output_path=analyzer_output') |
| 153 EnsureError('Unable to open file bogus_file') | 154 EnsureError('Unable to open file bogus_file') |
| 154 | 155 |
| 155 # Verify get warning when bad target is specified. | 156 # Verify 'invalid_targets' is present when bad target is specified. |
| 156 _CreateConfigFile(['exe2.c'], ['bad_target']) | 157 _CreateConfigFile(['exe2.c'], ['bad_target']) |
| 157 run_analyzer() | 158 run_analyzer() |
| 158 EnsureWarning('Unable to find all targets') | 159 EnsureInvalidTargets({'bad_target'}) |
| 159 | 160 |
| 160 # Verifies config_path must point to a valid json file. | 161 # Verifies config_path must point to a valid json file. |
| 161 _CreateBogusConfigFile() | 162 _CreateBogusConfigFile() |
| 162 run_analyzer() | 163 run_analyzer() |
| 163 EnsureError('Unable to parse config file test_file') | 164 EnsureError('Unable to parse config file test_file') |
| 164 | 165 |
| 165 # Trivial test of a source. | 166 # Trivial test of a source. |
| 166 _CreateConfigFile(['foo.c'], []) | 167 _CreateConfigFile(['foo.c'], []) |
| 167 run_analyzer() | 168 run_analyzer() |
| 168 EnsureContains(matched=True, build_targets={'exe'}) | 169 EnsureContains(matched=True, build_targets={'exe'}) |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 | 347 |
| 347 _CreateConfigFile(['d.c'], []) | 348 _CreateConfigFile(['d.c'], []) |
| 348 run_analyzer4() | 349 run_analyzer4() |
| 349 EnsureContains(matched=True, build_targets={'a', 'b', 'c', 'd'}) | 350 EnsureContains(matched=True, build_targets={'a', 'b', 'c', 'd'}) |
| 350 | 351 |
| 351 _CreateConfigFile(['i.c'], []) | 352 _CreateConfigFile(['i.c'], []) |
| 352 run_analyzer4() | 353 run_analyzer4() |
| 353 EnsureContains(matched=True, build_targets={'h'}) | 354 EnsureContains(matched=True, build_targets={'h'}) |
| 354 | 355 |
| 355 test.pass_test() | 356 test.pass_test() |
| OLD | NEW |