Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Side by Side Diff: test/analyzer/gyptest-analyzer.py

Issue 1454433002: Python 3 compatibility Base URL: https://chromium.googlesource.com/external/gyp.git@master
Patch Set: Rebase with master (4ec6c4e3a94bd04a6da2858163d40b2429b8aad1) Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 from __future__ import print_function
10
9 import json 11 import json
10 import TestGyp 12 import TestGyp
11 13
12 found = 'Found dependency' 14 found = 'Found dependency'
13 found_all = 'Found dependency (all)' 15 found_all = 'Found dependency (all)'
14 not_found = 'No dependencies' 16 not_found = 'No dependencies'
15 17
16 18
17 def _CreateConfigFile(files, additional_compile_targets, test_targets=[]): 19 def _CreateConfigFile(files, additional_compile_targets, test_targets=[]):
18 """Creates the analyzer config file, which is used as the input to analyzer. 20 """Creates the analyzer config file, which is used as the input to analyzer.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 def run_analyzer4(*args, **kw): 70 def run_analyzer4(*args, **kw):
69 """Same as run_analyzer(), but passes in test3.gyp instead of test.gyp.""" 71 """Same as run_analyzer(), but passes in test3.gyp instead of test.gyp."""
70 args += CommonArgs() 72 args += CommonArgs()
71 test.run_gyp('test4.gyp', *args, **kw) 73 test.run_gyp('test4.gyp', *args, **kw)
72 74
73 75
74 def EnsureContains(matched=False, compile_targets=set(), test_targets=set()): 76 def EnsureContains(matched=False, compile_targets=set(), test_targets=set()):
75 """Verifies output contains |compile_targets|.""" 77 """Verifies output contains |compile_targets|."""
76 result = _ReadOutputFileContents() 78 result = _ReadOutputFileContents()
77 if 'error' in result: 79 if 'error' in result:
78 print 'unexpected error', result.get('error') 80 print('unexpected error', result.get('error'))
79 test.fail_test() 81 test.fail_test()
80 82
81 if 'invalid_targets' in result: 83 if 'invalid_targets' in result:
82 print 'unexpected invalid_targets', result.get('invalid_targets') 84 print('unexpected invalid_targets', result.get('invalid_targets'))
83 test.fail_test() 85 test.fail_test()
84 86
85 actual_compile_targets = set(result['compile_targets']) 87 actual_compile_targets = set(result['compile_targets'])
86 if actual_compile_targets != compile_targets: 88 if actual_compile_targets != compile_targets:
87 print 'actual compile_targets:', actual_compile_targets, \ 89 print('actual compile_targets:', actual_compile_targets,
88 '\nexpected compile_targets:', compile_targets 90 '\nexpected compile_targets:', compile_targets)
89 test.fail_test() 91 test.fail_test()
90 92
91 actual_test_targets = set(result['test_targets']) 93 actual_test_targets = set(result['test_targets'])
92 if actual_test_targets != test_targets: 94 if actual_test_targets != test_targets:
93 print 'actual test_targets:', actual_test_targets, \ 95 print('actual test_targets:', actual_test_targets,
94 '\nexpected test_targets:', test_targets 96 '\nexpected test_targets:', test_targets)
95 test.fail_test() 97 test.fail_test()
96 98
97 if matched and result['status'] != found: 99 if matched and result['status'] != found:
98 print 'expected', found, 'got', result['status'] 100 print('expected', found, 'got', result['status'])
99 test.fail_test() 101 test.fail_test()
100 elif not matched and result['status'] != not_found: 102 elif not matched and result['status'] != not_found:
101 print 'expected', not_found, 'got', result['status'] 103 print('expected', not_found, 'got', result['status'])
102 test.fail_test() 104 test.fail_test()
103 105
104 106
105 def EnsureMatchedAll(compile_targets, test_targets=set()): 107 def EnsureMatchedAll(compile_targets, test_targets=set()):
106 result = _ReadOutputFileContents() 108 result = _ReadOutputFileContents()
107 if 'error' in result: 109 if 'error' in result:
108 print 'unexpected error', result.get('error') 110 print('unexpected error', result.get('error'))
109 test.fail_test() 111 test.fail_test()
110 112
111 if 'invalid_targets' in result: 113 if 'invalid_targets' in result:
112 print 'unexpected invalid_targets', result.get('invalid_targets') 114 print('unexpected invalid_targets', result.get('invalid_targets'))
113 test.fail_test() 115 test.fail_test()
114 116
115 if result['status'] != found_all: 117 if result['status'] != found_all:
116 print 'expected', found_all, 'got', result['status'] 118 print('expected', found_all, 'got', result['status'])
117 test.fail_test() 119 test.fail_test()
118 120
119 actual_compile_targets = set(result['compile_targets']) 121 actual_compile_targets = set(result['compile_targets'])
120 if actual_compile_targets != compile_targets: 122 if actual_compile_targets != compile_targets:
121 print ('actual compile_targets:', actual_compile_targets, 123 print('actual compile_targets:', actual_compile_targets,
122 '\nexpected compile_targets:', compile_targets) 124 '\nexpected compile_targets:', compile_targets)
123 test.fail_test() 125 test.fail_test()
124 126
125 actual_test_targets = set(result['test_targets']) 127 actual_test_targets = set(result['test_targets'])
126 if actual_test_targets != test_targets: 128 if actual_test_targets != test_targets:
127 print ('actual test_targets:', actual_test_targets, 129 print('actual test_targets:', actual_test_targets,
128 '\nexpected test_targets:', test_targets) 130 '\nexpected test_targets:', test_targets)
129 test.fail_test() 131 test.fail_test()
130 132
131 133
132 def EnsureError(expected_error_string): 134 def EnsureError(expected_error_string):
133 """Verifies output contains the error string.""" 135 """Verifies output contains the error string."""
134 result = _ReadOutputFileContents() 136 result = _ReadOutputFileContents()
135 if result.get('error', '').find(expected_error_string) == -1: 137 if result.get('error', '').find(expected_error_string) == -1:
136 print 'actual error:', result.get('error', ''), '\nexpected error:', \ 138 print('actual error:', result.get('error', ''), '\nexpected error:',
137 expected_error_string 139 expected_error_string)
138 test.fail_test() 140 test.fail_test()
139 141
140 142
141 def EnsureStdoutContains(expected_error_string): 143 def EnsureStdoutContains(expected_error_string):
142 if test.stdout().find(expected_error_string) == -1: 144 if test.stdout().find(expected_error_string) == -1:
143 print 'actual stdout:', test.stdout(), '\nexpected stdout:', \ 145 print('actual stdout:', test.stdout(), '\nexpected stdout:',
144 expected_error_string 146 expected_error_string)
145 test.fail_test() 147 test.fail_test()
146 148
147 149
148 def EnsureInvalidTargets(expected_invalid_targets): 150 def EnsureInvalidTargets(expected_invalid_targets):
149 """Verifies output contains invalid_targets.""" 151 """Verifies output contains invalid_targets."""
150 result = _ReadOutputFileContents() 152 result = _ReadOutputFileContents()
151 actual_invalid_targets = set(result['invalid_targets']) 153 actual_invalid_targets = set(result['invalid_targets'])
152 if actual_invalid_targets != expected_invalid_targets: 154 if actual_invalid_targets != expected_invalid_targets:
153 print 'actual invalid_targets:', actual_invalid_targets, \ 155 print('actual invalid_targets:', actual_invalid_targets,
154 '\nexpected :', expected_invalid_targets 156 '\nexpected :', expected_invalid_targets)
155 test.fail_test() 157 test.fail_test()
156 158
157 159
158 # Two targets, A and B (both static_libraries) and A depends upon B. If a file 160 # Two targets, A and B (both static_libraries) and A depends upon B. If a file
159 # in B changes, then both A and B are output. It is not strictly necessary that 161 # in B changes, then both A and B are output. It is not strictly necessary that
160 # A is compiled in this case, only B. 162 # A is compiled in this case, only B.
161 _CreateConfigFile(['b.c'], ['all']) 163 _CreateConfigFile(['b.c'], ['all'])
162 test.run_gyp('static_library_test.gyp', *CommonArgs()) 164 test.run_gyp('static_library_test.gyp', *CommonArgs())
163 EnsureContains(matched=True, compile_targets={'a' ,'b'}) 165 EnsureContains(matched=True, compile_targets={'a' ,'b'})
164 166
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 run_analyzer() 418 run_analyzer()
417 EnsureContains(matched=True, compile_targets={'exe3', 'all'}, 419 EnsureContains(matched=True, compile_targets={'exe3', 'all'},
418 test_targets={'all'}) 420 test_targets={'all'})
419 421
420 _CreateConfigFile(['exe2.c'], [], ['all', 'exe2']) 422 _CreateConfigFile(['exe2.c'], [], ['all', 'exe2'])
421 run_analyzer() 423 run_analyzer()
422 EnsureContains(matched=True, compile_targets={'exe2', 'all'}, 424 EnsureContains(matched=True, compile_targets={'exe2', 'all'},
423 test_targets={'all', 'exe2'}) 425 test_targets={'all', 'exe2'})
424 426
425 test.pass_test() 427 test.pass_test()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698