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

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

Issue 473483002: Removes old way to specify files to look for (Closed) Base URL: http://gyp.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « pylib/gyp/generator/analyzer.py ('k') | test/analyzer/gyptest-analyzer.new.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 import json 9 import json
10 import TestGyp 10 import TestGyp
11 11
12 # TODO(sky): when done migrating recipes rename to gyptest-analyzer and nuke
13 # existing gyptest-analyzer.
14
15 found = 'Found dependency' 12 found = 'Found dependency'
16 not_found = 'No dependencies' 13 not_found = 'No dependencies'
17 14
15
18 def _CreateTestFile(files, targets): 16 def _CreateTestFile(files, targets):
19 f = open('test_file', 'w') 17 f = open('test_file', 'w')
20 to_write = {'files': files, 'targets': targets } 18 to_write = {'files': files, 'targets': targets }
21 json.dump(to_write, f) 19 json.dump(to_write, f)
22 f.close() 20 f.close()
23 21
22
24 def _CreateBogusTestFile(): 23 def _CreateBogusTestFile():
25 f = open('test_file','w') 24 f = open('test_file','w')
26 f.write('bogus') 25 f.write('bogus')
27 f.close() 26 f.close()
28 27
28
29 def _ReadOutputFileContents(): 29 def _ReadOutputFileContents():
30 f = open('analyzer_output', 'r') 30 f = open('analyzer_output', 'r')
31 result = json.load(f) 31 result = json.load(f)
32 f.close() 32 f.close()
33 return result 33 return result
34 34
35
35 # NOTE: this would be clearer if it subclassed TestGypCustom, but that trips 36 # NOTE: this would be clearer if it subclassed TestGypCustom, but that trips
36 # over a bug in pylint (E1002). 37 # over a bug in pylint (E1002).
37 test = TestGyp.TestGypCustom(format='analyzer') 38 test = TestGyp.TestGypCustom(format='analyzer')
38 39
40
39 def run_analyzer(*args, **kw): 41 def run_analyzer(*args, **kw):
40 """Runs the test specifying a particular config and output path.""" 42 """Runs the test specifying a particular config and output path."""
41 args += ('-Gconfig_path=test_file', 43 args += ('-Gconfig_path=test_file',
42 '-Ganalyzer_output_path=analyzer_output') 44 '-Ganalyzer_output_path=analyzer_output')
43 test.run_gyp('test.gyp', *args, **kw) 45 test.run_gyp('test.gyp', *args, **kw)
44 46
47
45 def run_analyzer2(*args, **kw): 48 def run_analyzer2(*args, **kw):
46 """Runs the test specifying a particular config and output path.""" 49 """Runs the test specifying a particular config and output path."""
47 args += ('-Gconfig_path=test_file', 50 args += ('-Gconfig_path=test_file',
48 '-Ganalyzer_output_path=analyzer_output') 51 '-Ganalyzer_output_path=analyzer_output')
49 test.run_gyp('test2.gyp', *args, **kw) 52 test.run_gyp('test2.gyp', *args, **kw)
50 53
54
51 def EnsureContains(targets=set(), matched=False): 55 def EnsureContains(targets=set(), matched=False):
52 """Verifies output contains |targets|.""" 56 """Verifies output contains |targets|."""
53 result = _ReadOutputFileContents() 57 result = _ReadOutputFileContents()
54 if result.get('error', None): 58 if result.get('error', None):
55 print 'unexpected error', result.get('error') 59 print 'unexpected error', result.get('error')
56 test.fail_test() 60 test.fail_test()
57 61
58 if result.get('warning', None): 62 if result.get('warning', None):
59 print 'unexpected warning', result.get('warning') 63 print 'unexpected warning', result.get('warning')
60 test.fail_test() 64 test.fail_test()
61 65
62 actual_targets = set(result['targets']) 66 actual_targets = set(result['targets'])
63 if actual_targets != targets: 67 if actual_targets != targets:
64 print 'actual targets:', actual_targets, '\nexpected targets:', targets 68 print 'actual targets:', actual_targets, '\nexpected targets:', targets
65 test.fail_test() 69 test.fail_test()
66 70
67 if matched and result['status'] != found: 71 if matched and result['status'] != found:
68 print 'expected', found, 'got', result['status'] 72 print 'expected', found, 'got', result['status']
69 test.fail_test() 73 test.fail_test()
70 elif not matched and result['status'] != not_found: 74 elif not matched and result['status'] != not_found:
71 print 'expected', not_found, 'got', result['status'] 75 print 'expected', not_found, 'got', result['status']
72 test.fail_test() 76 test.fail_test()
73 77
78
74 def EnsureError(expected_error_string): 79 def EnsureError(expected_error_string):
75 """Verifies output contains the error string.""" 80 """Verifies output contains the error string."""
76 result = _ReadOutputFileContents() 81 result = _ReadOutputFileContents()
77 if result.get('error', '').find(expected_error_string) == -1: 82 if result.get('error', '').find(expected_error_string) == -1:
78 print 'actual error:', result.get('error', ''), '\nexpected error:', \ 83 print 'actual error:', result.get('error', ''), '\nexpected error:', \
79 expected_error_string 84 expected_error_string
80 test.fail_test() 85 test.fail_test()
81 86
87
88 def EnsureStdoutContains(expected_error_string):
89 if test.stdout().find(expected_error_string) == -1:
90 print 'actual stdout:', test.stdout(), '\nexpected stdout:', \
91 expected_error_string
92 test.fail_test()
93
94
82 def EnsureWarning(expected_warning_string): 95 def EnsureWarning(expected_warning_string):
83 """Verifies output contains the warning string.""" 96 """Verifies output contains the warning string."""
84 result = _ReadOutputFileContents() 97 result = _ReadOutputFileContents()
85 if result.get('warning', '').find(expected_warning_string) == -1: 98 if result.get('warning', '').find(expected_warning_string) == -1:
86 print 'actual warning:', result.get('warning', ''), \ 99 print 'actual warning:', result.get('warning', ''), \
87 '\nexpected warning:', expected_warning_string 100 '\nexpected warning:', expected_warning_string
88 test.fail_test() 101 test.fail_test()
89 102
90 # Verifies file_path must be specified. 103
91 test.run_gyp('test.gyp', 104 # Verifies config_path must be specified.
92 stdout='Must specify files to analyze via file_path generator ' 105 test.run_gyp('test.gyp')
93 'flag\n') 106 EnsureStdoutContains('Must specify files to analyze via config_path')
94 107
95 # Verifies config_path must point to a valid file. 108 # Verifies config_path must point to a valid file.
96 test.run_gyp('test.gyp', '-Gconfig_path=bogus_file', 109 test.run_gyp('test.gyp', '-Gconfig_path=bogus_file',
97 '-Ganalyzer_output_path=analyzer_output') 110 '-Ganalyzer_output_path=analyzer_output')
98 EnsureError('Unable to open file bogus_file') 111 EnsureError('Unable to open file bogus_file')
99 112
100 # Verify get error when bad target is specified. 113 # Verify get error when bad target is specified.
101 _CreateTestFile(['exe2.c'], ['bad_target']) 114 _CreateTestFile(['exe2.c'], ['bad_target'])
102 run_analyzer() 115 run_analyzer()
103 EnsureWarning('Unable to find all targets') 116 EnsureWarning('Unable to find all targets')
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 _CreateTestFile(['test2.includes.gypi'], ['exe', 'exe2', 'foo', 'exe3']) 233 _CreateTestFile(['test2.includes.gypi'], ['exe', 'exe2', 'foo', 'exe3'])
221 run_analyzer2() 234 run_analyzer2()
222 EnsureContains(matched=True, targets={'exe', 'exe2', 'exe3'}) 235 EnsureContains(matched=True, targets={'exe', 'exe2', 'exe3'})
223 236
224 # Verify modifying a file included makes all targets dirty. 237 # Verify modifying a file included makes all targets dirty.
225 _CreateTestFile(['common.gypi'], ['exe', 'exe2', 'foo', 'exe3']) 238 _CreateTestFile(['common.gypi'], ['exe', 'exe2', 'foo', 'exe3'])
226 run_analyzer2('-Icommon.gypi') 239 run_analyzer2('-Icommon.gypi')
227 EnsureContains(matched=True, targets={'exe', 'foo', 'exe2', 'exe3'}) 240 EnsureContains(matched=True, targets={'exe', 'foo', 'exe2', 'exe3'})
228 241
229 test.pass_test() 242 test.pass_test()
OLDNEW
« no previous file with comments | « pylib/gyp/generator/analyzer.py ('k') | test/analyzer/gyptest-analyzer.new.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698