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

Side by Side Diff: pkg/analyzer/test/src/command_line/arguments_test.dart

Issue 2976963002: Add --no-declaration-casts option to analyzer. (Closed)
Patch Set: Fix comment Created 3 years, 5 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 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.test.src.command_line.arguments_test; 5 library analyzer.test.src.command_line.arguments_test;
6 6
7 import 'package:analyzer/file_system/memory_file_system.dart'; 7 import 'package:analyzer/file_system/memory_file_system.dart';
8 import 'package:analyzer/src/command_line/arguments.dart'; 8 import 'package:analyzer/src/command_line/arguments.dart';
9 import 'package:analyzer/src/context/builder.dart'; 9 import 'package:analyzer/src/context/builder.dart';
10 import 'package:analyzer/src/dart/sdk/sdk.dart'; 10 import 'package:analyzer/src/dart/sdk/sdk.dart';
(...skipping 17 matching lines...) Expand all
28 String defaultPackageFilePath = 'c'; 28 String defaultPackageFilePath = 'c';
29 String defaultPackagesDirectoryPath = 'd'; 29 String defaultPackagesDirectoryPath = 'd';
30 MemoryResourceProvider provider = new MemoryResourceProvider(); 30 MemoryResourceProvider provider = new MemoryResourceProvider();
31 ArgParser parser = new ArgParser(); 31 ArgParser parser = new ArgParser();
32 defineAnalysisArguments(parser); 32 defineAnalysisArguments(parser);
33 List<String> args = [ 33 List<String> args = [
34 '--dart-sdk-summary=$dartSdkSummaryPath', 34 '--dart-sdk-summary=$dartSdkSummaryPath',
35 '-Dfoo=1', 35 '-Dfoo=1',
36 '-Dbar=2', 36 '-Dbar=2',
37 '--enable-strict-call-checks', 37 '--enable-strict-call-checks',
38 '--no-declaration-casts',
38 '--no-implicit-casts', 39 '--no-implicit-casts',
39 '--no-implicit-dynamic', 40 '--no-implicit-dynamic',
40 '--options=$defaultAnalysisOptionsFilePath', 41 '--options=$defaultAnalysisOptionsFilePath',
41 '--packages=$defaultPackageFilePath', 42 '--packages=$defaultPackageFilePath',
42 '--package-root=$defaultPackagesDirectoryPath', 43 '--package-root=$defaultPackagesDirectoryPath',
43 '--strong', 44 '--strong',
44 '--supermixin', 45 '--supermixin',
45 ]; 46 ];
46 ArgResults result = parse(provider, parser, args); 47 ArgResults result = parse(provider, parser, args);
47 ContextBuilderOptions options = createContextBuilderOptions(result); 48 ContextBuilderOptions options = createContextBuilderOptions(result);
48 expect(options, isNotNull); 49 expect(options, isNotNull);
49 expect(options.dartSdkSummaryPath, dartSdkSummaryPath); 50 expect(options.dartSdkSummaryPath, dartSdkSummaryPath);
50 Map<String, String> declaredVariables = options.declaredVariables; 51 Map<String, String> declaredVariables = options.declaredVariables;
51 expect(declaredVariables, hasLength(2)); 52 expect(declaredVariables, hasLength(2));
52 expect(declaredVariables['foo'], '1'); 53 expect(declaredVariables['foo'], '1');
53 expect(declaredVariables['bar'], '2'); 54 expect(declaredVariables['bar'], '2');
54 expect( 55 expect(
55 options.defaultAnalysisOptionsFilePath, defaultAnalysisOptionsFilePath); 56 options.defaultAnalysisOptionsFilePath, defaultAnalysisOptionsFilePath);
56 expect(options.defaultPackageFilePath, defaultPackageFilePath); 57 expect(options.defaultPackageFilePath, defaultPackageFilePath);
57 expect(options.defaultPackagesDirectoryPath, defaultPackagesDirectoryPath); 58 expect(options.defaultPackagesDirectoryPath, defaultPackagesDirectoryPath);
58 AnalysisOptionsImpl defaultOptions = options.defaultOptions; 59 AnalysisOptionsImpl defaultOptions = options.defaultOptions;
59 expect(defaultOptions, isNotNull); 60 expect(defaultOptions, isNotNull);
60 expect(defaultOptions.enableStrictCallChecks, true); 61 expect(defaultOptions.enableStrictCallChecks, true);
61 expect(defaultOptions.strongMode, true); 62 expect(defaultOptions.strongMode, true);
63 expect(defaultOptions.declarationCasts, false);
62 expect(defaultOptions.implicitCasts, false); 64 expect(defaultOptions.implicitCasts, false);
63 expect(defaultOptions.implicitDynamic, false); 65 expect(defaultOptions.implicitDynamic, false);
64 } 66 }
65 67
66 void test_createContextBuilderOptions_none() { 68 void test_createContextBuilderOptions_none() {
67 MemoryResourceProvider provider = new MemoryResourceProvider(); 69 MemoryResourceProvider provider = new MemoryResourceProvider();
68 ArgParser parser = new ArgParser(); 70 ArgParser parser = new ArgParser();
69 defineAnalysisArguments(parser); 71 defineAnalysisArguments(parser);
70 List<String> args = []; 72 List<String> args = [];
71 ArgResults result = parse(provider, parser, args); 73 ArgResults result = parse(provider, parser, args);
72 ContextBuilderOptions options = createContextBuilderOptions(result); 74 ContextBuilderOptions options = createContextBuilderOptions(result);
73 expect(options, isNotNull); 75 expect(options, isNotNull);
74 expect(options.dartSdkSummaryPath, isNull); 76 expect(options.dartSdkSummaryPath, isNull);
75 expect(options.declaredVariables, isEmpty); 77 expect(options.declaredVariables, isEmpty);
76 expect(options.defaultAnalysisOptionsFilePath, isNull); 78 expect(options.defaultAnalysisOptionsFilePath, isNull);
77 expect(options.defaultPackageFilePath, isNull); 79 expect(options.defaultPackageFilePath, isNull);
78 expect(options.defaultPackagesDirectoryPath, isNull); 80 expect(options.defaultPackagesDirectoryPath, isNull);
79 AnalysisOptionsImpl defaultOptions = options.defaultOptions; 81 AnalysisOptionsImpl defaultOptions = options.defaultOptions;
80 expect(defaultOptions, isNotNull); 82 expect(defaultOptions, isNotNull);
81 expect(defaultOptions.enableStrictCallChecks, false); 83 expect(defaultOptions.enableStrictCallChecks, false);
82 expect(defaultOptions.strongMode, false); 84 expect(defaultOptions.strongMode, false);
85 expect(defaultOptions.declarationCasts, true);
83 expect(defaultOptions.implicitCasts, true); 86 expect(defaultOptions.implicitCasts, true);
84 expect(defaultOptions.implicitDynamic, true); 87 expect(defaultOptions.implicitDynamic, true);
85 } 88 }
86 89
87 void test_createDartSdkManager_noPath_noSummaries() { 90 void test_createDartSdkManager_noPath_noSummaries() {
88 MemoryResourceProvider provider = new MemoryResourceProvider(); 91 MemoryResourceProvider provider = new MemoryResourceProvider();
89 ArgParser parser = new ArgParser(); 92 ArgParser parser = new ArgParser();
90 defineAnalysisArguments(parser); 93 defineAnalysisArguments(parser);
91 List<String> args = []; 94 List<String> args = [];
92 ArgResults result = parse(provider, parser, args); 95 ArgResults result = parse(provider, parser, args);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 ArgParser parser = new ArgParser(); 130 ArgParser parser = new ArgParser();
128 defineAnalysisArguments(parser); 131 defineAnalysisArguments(parser);
129 List<String> args = ['--dart-sdk=y']; 132 List<String> args = ['--dart-sdk=y'];
130 ArgResults result = parse(provider, parser, args); 133 ArgResults result = parse(provider, parser, args);
131 DartSdkManager manager = createDartSdkManager(provider, true, result); 134 DartSdkManager manager = createDartSdkManager(provider, true, result);
132 expect(manager, isNotNull); 135 expect(manager, isNotNull);
133 expect(manager.defaultSdkDirectory, 'y'); 136 expect(manager.defaultSdkDirectory, 'y');
134 expect(manager.canUseSummaries, true); 137 expect(manager.canUseSummaries, true);
135 } 138 }
136 139
140 void test_declarationCast_noImplicitCast() {
141 MemoryResourceProvider provider = new MemoryResourceProvider();
142 ArgParser parser = new ArgParser();
143 defineAnalysisArguments(parser);
144 List<String> args = [
145 '--declaration-casts',
146 '--no-implicit-casts',
147 ];
148 ArgResults result = parse(provider, parser, args);
149 ContextBuilderOptions options = createContextBuilderOptions(result);
150 expect(options, isNotNull);
151 AnalysisOptionsImpl defaultOptions = options.defaultOptions;
152 expect(defaultOptions, isNotNull);
153 expect(defaultOptions.declarationCasts, true);
154 expect(defaultOptions.implicitCasts, false);
155 }
156
137 void test_defineAnalysisArguments() { 157 void test_defineAnalysisArguments() {
138 ArgParser parser = new ArgParser(); 158 ArgParser parser = new ArgParser();
139 defineAnalysisArguments(parser); 159 defineAnalysisArguments(parser);
140 expect(parser.options, hasLength(14)); 160 expect(parser.options, hasLength(15));
141 } 161 }
142 162
143 void test_extractDefinedVariables() { 163 void test_extractDefinedVariables() {
144 List<String> args = ['--a', '-Dbaz', 'go', '-Dc=d', 'e=f', '-Dy=', '-Dx']; 164 List<String> args = ['--a', '-Dbaz', 'go', '-Dc=d', 'e=f', '-Dy=', '-Dx'];
145 Map<String, String> definedVariables = {'one': 'two'}; 165 Map<String, String> definedVariables = {'one': 'two'};
146 args = extractDefinedVariables(args, definedVariables); 166 args = extractDefinedVariables(args, definedVariables);
147 expect(args, orderedEquals(['--a', 'e=f', '-Dx'])); 167 expect(args, orderedEquals(['--a', 'e=f', '-Dx']));
148 expect(definedVariables['one'], 'two'); 168 expect(definedVariables['one'], 'two');
149 expect(definedVariables['two'], isNull); 169 expect(definedVariables['two'], isNull);
150 expect(definedVariables['baz'], 'go'); 170 expect(definedVariables['baz'], 'go');
151 expect(definedVariables['go'], isNull); 171 expect(definedVariables['go'], isNull);
152 expect(definedVariables['c'], 'd'); 172 expect(definedVariables['c'], 'd');
153 expect(definedVariables['d'], isNull); 173 expect(definedVariables['d'], isNull);
154 expect(definedVariables['y'], ''); 174 expect(definedVariables['y'], '');
155 expect(definedVariables, hasLength(4)); 175 expect(definedVariables, hasLength(4));
156 } 176 }
157 177
158 void test_filterUnknownArguments() { 178 void test_filterUnknownArguments() {
159 List<String> args = ['--a', '--b', '--c=0', '--d=1', '-e=2', '-f', 'bar']; 179 List<String> args = ['--a', '--b', '--c=0', '--d=1', '-e=2', '-f', 'bar'];
160 ArgParser parser = new ArgParser(); 180 ArgParser parser = new ArgParser();
161 parser.addFlag('a'); 181 parser.addFlag('a');
162 parser.addOption('c'); 182 parser.addOption('c');
163 parser.addOption('ee', abbr: 'e'); 183 parser.addOption('ee', abbr: 'e');
164 parser.addFlag('ff', abbr: 'f'); 184 parser.addFlag('ff', abbr: 'f');
165 List<String> result = filterUnknownArguments(args, parser); 185 List<String> result = filterUnknownArguments(args, parser);
166 expect(result, orderedEquals(['--a', '--c=0', '-e=2', '-f', 'bar'])); 186 expect(result, orderedEquals(['--a', '--c=0', '-e=2', '-f', 'bar']));
167 } 187 }
168 188
189 void test_noAssignmentCast() {
190 MemoryResourceProvider provider = new MemoryResourceProvider();
191 ArgParser parser = new ArgParser();
192 defineAnalysisArguments(parser);
193 List<String> args = [
194 '--no-declaration-casts',
195 ];
196 ArgResults result = parse(provider, parser, args);
197 ContextBuilderOptions options = createContextBuilderOptions(result);
198 expect(options, isNotNull);
199 AnalysisOptionsImpl defaultOptions = options.defaultOptions;
200 expect(defaultOptions, isNotNull);
201 expect(defaultOptions.declarationCasts, false);
202 expect(defaultOptions.implicitCasts, true);
203 }
204
205 void test_noAssignmentCast_implicitCast() {
206 MemoryResourceProvider provider = new MemoryResourceProvider();
207 ArgParser parser = new ArgParser();
208 defineAnalysisArguments(parser);
209 List<String> args = [
210 '--no-declaration-casts',
211 '--implicit-casts',
212 ];
213 ArgResults result = parse(provider, parser, args);
214 ContextBuilderOptions options = createContextBuilderOptions(result);
215 expect(options, isNotNull);
216 AnalysisOptionsImpl defaultOptions = options.defaultOptions;
217 expect(defaultOptions, isNotNull);
218 expect(defaultOptions.declarationCasts, false);
219 expect(defaultOptions.implicitCasts, true);
220 }
221
222 void test_noImplicitCast() {
223 MemoryResourceProvider provider = new MemoryResourceProvider();
224 ArgParser parser = new ArgParser();
225 defineAnalysisArguments(parser);
226 List<String> args = [
227 '--no-implicit-casts',
228 ];
229 ArgResults result = parse(provider, parser, args);
230 ContextBuilderOptions options = createContextBuilderOptions(result);
231 expect(options, isNotNull);
232 AnalysisOptionsImpl defaultOptions = options.defaultOptions;
233 expect(defaultOptions, isNotNull);
234 expect(defaultOptions.declarationCasts, false);
235 expect(defaultOptions.implicitCasts, false);
236 }
237
169 void test_parse_noReplacement_noIgnored() { 238 void test_parse_noReplacement_noIgnored() {
170 MemoryResourceProvider provider = new MemoryResourceProvider(); 239 MemoryResourceProvider provider = new MemoryResourceProvider();
171 ArgParser parser = new ArgParser(); 240 ArgParser parser = new ArgParser();
172 parser.addFlag('xx'); 241 parser.addFlag('xx');
173 parser.addOption('yy'); 242 parser.addOption('yy');
174 List<String> args = ['--xx', '--yy=abc', 'foo', 'bar']; 243 List<String> args = ['--xx', '--yy=abc', 'foo', 'bar'];
175 ArgResults result = parse(provider, parser, args); 244 ArgResults result = parse(provider, parser, args);
176 expect(result, isNotNull); 245 expect(result, isNotNull);
177 expect(result['xx'], true); 246 expect(result['xx'], true);
178 expect(result['yy'], 'abc'); 247 expect(result['yy'], 'abc');
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 } 285 }
217 286
218 void test_preprocessArgs_replacement_notLast() { 287 void test_preprocessArgs_replacement_notLast() {
219 MemoryResourceProvider provider = new MemoryResourceProvider(); 288 MemoryResourceProvider provider = new MemoryResourceProvider();
220 String filePath = provider.convertPath('/args.txt'); 289 String filePath = provider.convertPath('/args.txt');
221 List<String> args = ['a', '@$filePath', 'b']; 290 List<String> args = ['a', '@$filePath', 'b'];
222 List<String> result = preprocessArgs(provider, args); 291 List<String> result = preprocessArgs(provider, args);
223 expect(result, orderedEquals(args)); 292 expect(result, orderedEquals(args));
224 } 293 }
225 } 294 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/strong/checker.dart ('k') | pkg/analyzer/test/src/context/builder_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698