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

Side by Side Diff: pkg/analyzer/test/src/context/builder_test.dart

Issue 2975253002: Format analyzer, analysis_server, analyzer_plugin, front_end and kernel with the latest dartfmt. (Closed)
Patch Set: 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.context.context_builder_test; 5 library analyzer.test.src.context.context_builder_test;
6 6
7 import 'package:analyzer/context/context_root.dart'; 7 import 'package:analyzer/context/context_root.dart';
8 import 'package:analyzer/file_system/file_system.dart'; 8 import 'package:analyzer/file_system/file_system.dart';
9 import 'package:analyzer/file_system/memory_file_system.dart'; 9 import 'package:analyzer/file_system/memory_file_system.dart';
10 import 'package:analyzer/source/package_map_resolver.dart'; 10 import 'package:analyzer/source/package_map_resolver.dart';
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 Uri convertedDirectoryUri(String directoryPath) { 82 Uri convertedDirectoryUri(String directoryPath) {
83 return new Uri.directory(resourceProvider.convertPath(directoryPath), 83 return new Uri.directory(resourceProvider.convertPath(directoryPath),
84 windows: pathContext.style == path.windows.style); 84 windows: pathContext.style == path.windows.style);
85 } 85 }
86 86
87 void createDefaultSdk(Folder sdkDir) { 87 void createDefaultSdk(Folder sdkDir) {
88 defaultSdkPath = pathContext.join(sdkDir.path, 'default', 'sdk'); 88 defaultSdkPath = pathContext.join(sdkDir.path, 'default', 'sdk');
89 String librariesFilePath = pathContext.join(defaultSdkPath, 'lib', 89 String librariesFilePath = pathContext.join(defaultSdkPath, 'lib',
90 '_internal', 'sdk_library_metadata', 'lib', 'libraries.dart'); 90 '_internal', 'sdk_library_metadata', 'lib', 'libraries.dart');
91 resourceProvider.newFile( 91 resourceProvider.newFile(librariesFilePath, r'''
92 librariesFilePath,
93 r'''
94 const Map<String, LibraryInfo> libraries = const { 92 const Map<String, LibraryInfo> libraries = const {
95 "async": const LibraryInfo("async/async.dart"), 93 "async": const LibraryInfo("async/async.dart"),
96 "core": const LibraryInfo("core/core.dart"), 94 "core": const LibraryInfo("core/core.dart"),
97 }; 95 };
98 '''); 96 ''');
99 sdkManager = new DartSdkManager(defaultSdkPath, false); 97 sdkManager = new DartSdkManager(defaultSdkPath, false);
100 builder = new ContextBuilder(resourceProvider, sdkManager, contentCache, 98 builder = new ContextBuilder(resourceProvider, sdkManager, contentCache,
101 options: builderOptions); 99 options: builderOptions);
102 } 100 }
103 101
(...skipping 26 matching lines...) Expand all
130 var builder = new ContextBuilder(resourceProvider, sdkManager, contentCache, 128 var builder = new ContextBuilder(resourceProvider, sdkManager, contentCache,
131 options: createContextBuilderOptions(argResults)); 129 options: createContextBuilderOptions(argResults));
132 130
133 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); 131 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
134 expected.lint = true; 132 expected.lint = true;
135 expected.lintRules = Registry.ruleRegistry.defaultRules; 133 expected.lintRules = Registry.ruleRegistry.defaultRules;
136 134
137 String path = resourceProvider.convertPath('/some/directory/path'); 135 String path = resourceProvider.convertPath('/some/directory/path');
138 String filePath = 136 String filePath =
139 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); 137 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
140 resourceProvider.newFile( 138 resourceProvider.newFile(filePath, '''
141 filePath,
142 '''
143 '''); 139 ''');
144 140
145 AnalysisOptions options = builder.getAnalysisOptions(path); 141 AnalysisOptions options = builder.getAnalysisOptions(path);
146 _expectEqualOptions(options, expected); 142 _expectEqualOptions(options, expected);
147 } 143 }
148 144
149 void test_cmdline_lint_defined() { 145 void test_cmdline_lint_defined() {
150 _defineMockLintRules(); 146 _defineMockLintRules();
151 ArgParser argParser = new ArgParser(); 147 ArgParser argParser = new ArgParser();
152 defineAnalysisArguments(argParser); 148 defineAnalysisArguments(argParser);
153 ArgResults argResults = argParser.parse(['--$lintsFlag']); 149 ArgResults argResults = argParser.parse(['--$lintsFlag']);
154 var builder = new ContextBuilder(resourceProvider, sdkManager, contentCache, 150 var builder = new ContextBuilder(resourceProvider, sdkManager, contentCache,
155 options: createContextBuilderOptions(argResults)); 151 options: createContextBuilderOptions(argResults));
156 152
157 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); 153 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
158 expected.lint = true; 154 expected.lint = true;
159 expected.lintRules = <LintRule>[ 155 expected.lintRules = <LintRule>[
160 Registry.ruleRegistry['mock_lint_rule'], 156 Registry.ruleRegistry['mock_lint_rule'],
161 ]; 157 ];
162 158
163 String path = resourceProvider.convertPath('/some/directory/path'); 159 String path = resourceProvider.convertPath('/some/directory/path');
164 String filePath = 160 String filePath =
165 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); 161 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
166 resourceProvider.newFile( 162 resourceProvider.newFile(filePath, '''
167 filePath,
168 '''
169 linter: 163 linter:
170 rules: 164 rules:
171 - mock_lint_rule 165 - mock_lint_rule
172 '''); 166 ''');
173 167
174 AnalysisOptions options = builder.getAnalysisOptions(path); 168 AnalysisOptions options = builder.getAnalysisOptions(path);
175 _expectEqualOptions(options, expected); 169 _expectEqualOptions(options, expected);
176 } 170 }
177 171
178 void test_cmdline_lint_off() { 172 void test_cmdline_lint_off() {
179 ArgParser argParser = new ArgParser(); 173 ArgParser argParser = new ArgParser();
180 defineAnalysisArguments(argParser); 174 defineAnalysisArguments(argParser);
181 ArgResults argResults = argParser.parse(['--no-$lintsFlag']); 175 ArgResults argResults = argParser.parse(['--no-$lintsFlag']);
182 var builder = new ContextBuilder(resourceProvider, sdkManager, contentCache, 176 var builder = new ContextBuilder(resourceProvider, sdkManager, contentCache,
183 options: createContextBuilderOptions(argResults)); 177 options: createContextBuilderOptions(argResults));
184 178
185 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); 179 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
186 expected.lint = false; 180 expected.lint = false;
187 expected.lintRules = <LintRule>[ 181 expected.lintRules = <LintRule>[
188 Registry.ruleRegistry['mock_lint_rule'], 182 Registry.ruleRegistry['mock_lint_rule'],
189 ]; 183 ];
190 184
191 String path = resourceProvider.convertPath('/some/directory/path'); 185 String path = resourceProvider.convertPath('/some/directory/path');
192 String filePath = 186 String filePath =
193 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); 187 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
194 resourceProvider.newFile( 188 resourceProvider.newFile(filePath, '''
195 filePath,
196 '''
197 linter: 189 linter:
198 rules: 190 rules:
199 - mock_lint_rule 191 - mock_lint_rule
200 '''); 192 ''');
201 193
202 AnalysisOptions options = builder.getAnalysisOptions(path); 194 AnalysisOptions options = builder.getAnalysisOptions(path);
203 _expectEqualOptions(options, expected); 195 _expectEqualOptions(options, expected);
204 } 196 }
205 197
206 void test_cmdline_lint_unspecified_1() { 198 void test_cmdline_lint_unspecified_1() {
207 ArgParser argParser = new ArgParser(); 199 ArgParser argParser = new ArgParser();
208 defineAnalysisArguments(argParser); 200 defineAnalysisArguments(argParser);
209 ArgResults argResults = argParser.parse([]); 201 ArgResults argResults = argParser.parse([]);
210 var builder = new ContextBuilder(resourceProvider, sdkManager, contentCache, 202 var builder = new ContextBuilder(resourceProvider, sdkManager, contentCache,
211 options: createContextBuilderOptions(argResults)); 203 options: createContextBuilderOptions(argResults));
212 204
213 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); 205 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
214 expected.lint = true; 206 expected.lint = true;
215 expected.lintRules = <LintRule>[ 207 expected.lintRules = <LintRule>[
216 Registry.ruleRegistry['mock_lint_rule'], 208 Registry.ruleRegistry['mock_lint_rule'],
217 ]; 209 ];
218 210
219 String path = resourceProvider.convertPath('/some/directory/path'); 211 String path = resourceProvider.convertPath('/some/directory/path');
220 String filePath = 212 String filePath =
221 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); 213 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
222 resourceProvider.newFile( 214 resourceProvider.newFile(filePath, '''
223 filePath,
224 '''
225 linter: 215 linter:
226 rules: 216 rules:
227 - mock_lint_rule 217 - mock_lint_rule
228 '''); 218 ''');
229 219
230 AnalysisOptions options = builder.getAnalysisOptions(path); 220 AnalysisOptions options = builder.getAnalysisOptions(path);
231 _expectEqualOptions(options, expected); 221 _expectEqualOptions(options, expected);
232 } 222 }
233 223
234 void test_cmdline_lint_unspecified_2() { 224 void test_cmdline_lint_unspecified_2() {
235 ArgParser argParser = new ArgParser(); 225 ArgParser argParser = new ArgParser();
236 defineAnalysisArguments(argParser); 226 defineAnalysisArguments(argParser);
237 ArgResults argResults = argParser.parse([]); 227 ArgResults argResults = argParser.parse([]);
238 var builder = new ContextBuilder(resourceProvider, sdkManager, contentCache, 228 var builder = new ContextBuilder(resourceProvider, sdkManager, contentCache,
239 options: createContextBuilderOptions(argResults)); 229 options: createContextBuilderOptions(argResults));
240 230
241 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); 231 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
242 expected.lint = false; 232 expected.lint = false;
243 expected.lintRules = <LintRule>[]; 233 expected.lintRules = <LintRule>[];
244 234
245 String path = resourceProvider.convertPath('/some/directory/path'); 235 String path = resourceProvider.convertPath('/some/directory/path');
246 String filePath = 236 String filePath =
247 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); 237 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
248 resourceProvider.newFile( 238 resourceProvider.newFile(filePath, '''
249 filePath,
250 '''
251 '''); 239 ''');
252 240
253 AnalysisOptions options = builder.getAnalysisOptions(path); 241 AnalysisOptions options = builder.getAnalysisOptions(path);
254 _expectEqualOptions(options, expected); 242 _expectEqualOptions(options, expected);
255 } 243 }
256 244
257 void test_cmdline_options_override_options_file() { 245 void test_cmdline_options_override_options_file() {
258 ArgParser argParser = new ArgParser(); 246 ArgParser argParser = new ArgParser();
259 defineAnalysisArguments(argParser); 247 defineAnalysisArguments(argParser);
260 ArgResults argResults = argParser.parse(['--$enableStrictCallChecksFlag']); 248 ArgResults argResults = argParser.parse(['--$enableStrictCallChecksFlag']);
261 var builder = new ContextBuilder(resourceProvider, sdkManager, contentCache, 249 var builder = new ContextBuilder(resourceProvider, sdkManager, contentCache,
262 options: createContextBuilderOptions(argResults)); 250 options: createContextBuilderOptions(argResults));
263 251
264 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); 252 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
265 expected.enableSuperMixins = true; 253 expected.enableSuperMixins = true;
266 expected.enableStrictCallChecks = true; 254 expected.enableStrictCallChecks = true;
267 255
268 String path = resourceProvider.convertPath('/some/directory/path'); 256 String path = resourceProvider.convertPath('/some/directory/path');
269 String filePath = 257 String filePath =
270 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); 258 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
271 resourceProvider.newFile( 259 resourceProvider.newFile(filePath, '''
272 filePath,
273 '''
274 analyzer: 260 analyzer:
275 language: 261 language:
276 enableSuperMixins : true 262 enableSuperMixins : true
277 enableStrictCallChecks : false 263 enableStrictCallChecks : false
278 '''); 264 ''');
279 265
280 AnalysisOptions options = builder.getAnalysisOptions(path); 266 AnalysisOptions options = builder.getAnalysisOptions(path);
281 _expectEqualOptions(options, expected); 267 _expectEqualOptions(options, expected);
282 } 268 }
283 269
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 } 356 }
371 357
372 void test_createPackageMap_fromPackageFile_explicit() { 358 void test_createPackageMap_fromPackageFile_explicit() {
373 // Use a package file that is outside the project directory's hierarchy. 359 // Use a package file that is outside the project directory's hierarchy.
374 String rootPath = resourceProvider.convertPath('/root'); 360 String rootPath = resourceProvider.convertPath('/root');
375 String projectPath = pathContext.join(rootPath, 'project'); 361 String projectPath = pathContext.join(rootPath, 'project');
376 String packageFilePath = pathContext.join(rootPath, 'child', '.packages'); 362 String packageFilePath = pathContext.join(rootPath, 'child', '.packages');
377 resourceProvider.newFolder(projectPath); 363 resourceProvider.newFolder(projectPath);
378 Uri fooUri = convertedDirectoryUri('/pkg/foo'); 364 Uri fooUri = convertedDirectoryUri('/pkg/foo');
379 Uri barUri = convertedDirectoryUri('/pkg/bar'); 365 Uri barUri = convertedDirectoryUri('/pkg/bar');
380 createFile( 366 createFile(packageFilePath, '''
381 packageFilePath,
382 '''
383 foo:$fooUri 367 foo:$fooUri
384 bar:$barUri 368 bar:$barUri
385 '''); 369 ''');
386 370
387 builderOptions.defaultPackageFilePath = packageFilePath; 371 builderOptions.defaultPackageFilePath = packageFilePath;
388 Packages packages = builder.createPackageMap(projectPath); 372 Packages packages = builder.createPackageMap(projectPath);
389 expect(packages, isNotNull); 373 expect(packages, isNotNull);
390 Map<String, Uri> map = packages.asMap(); 374 Map<String, Uri> map = packages.asMap();
391 expect(map, hasLength(2)); 375 expect(map, hasLength(2));
392 expect(map['foo'], fooUri); 376 expect(map['foo'], fooUri);
393 expect(map['bar'], barUri); 377 expect(map['bar'], barUri);
394 } 378 }
395 379
396 void test_createPackageMap_fromPackageFile_inParentOfRoot() { 380 void test_createPackageMap_fromPackageFile_inParentOfRoot() {
397 // Use a package file that is inside the parent of the project directory. 381 // Use a package file that is inside the parent of the project directory.
398 String rootPath = resourceProvider.convertPath('/root'); 382 String rootPath = resourceProvider.convertPath('/root');
399 String projectPath = pathContext.join(rootPath, 'project'); 383 String projectPath = pathContext.join(rootPath, 'project');
400 String packageFilePath = pathContext.join(rootPath, '.packages'); 384 String packageFilePath = pathContext.join(rootPath, '.packages');
401 resourceProvider.newFolder(projectPath); 385 resourceProvider.newFolder(projectPath);
402 Uri fooUri = convertedDirectoryUri('/pkg/foo'); 386 Uri fooUri = convertedDirectoryUri('/pkg/foo');
403 Uri barUri = convertedDirectoryUri('/pkg/bar'); 387 Uri barUri = convertedDirectoryUri('/pkg/bar');
404 createFile( 388 createFile(packageFilePath, '''
405 packageFilePath,
406 '''
407 foo:$fooUri 389 foo:$fooUri
408 bar:$barUri 390 bar:$barUri
409 '''); 391 ''');
410 392
411 Packages packages = builder.createPackageMap(projectPath); 393 Packages packages = builder.createPackageMap(projectPath);
412 expect(packages, isNotNull); 394 expect(packages, isNotNull);
413 Map<String, Uri> map = packages.asMap(); 395 Map<String, Uri> map = packages.asMap();
414 expect(map, hasLength(2)); 396 expect(map, hasLength(2));
415 expect(map['foo'], fooUri); 397 expect(map['foo'], fooUri);
416 expect(map['bar'], barUri); 398 expect(map['bar'], barUri);
417 } 399 }
418 400
419 void test_createPackageMap_fromPackageFile_inRoot() { 401 void test_createPackageMap_fromPackageFile_inRoot() {
420 // Use a package file that is inside the project directory. 402 // Use a package file that is inside the project directory.
421 String rootPath = resourceProvider.convertPath('/root'); 403 String rootPath = resourceProvider.convertPath('/root');
422 String projectPath = pathContext.join(rootPath, 'project'); 404 String projectPath = pathContext.join(rootPath, 'project');
423 String packageFilePath = pathContext.join(projectPath, '.packages'); 405 String packageFilePath = pathContext.join(projectPath, '.packages');
424 resourceProvider.newFolder(projectPath); 406 resourceProvider.newFolder(projectPath);
425 Uri fooUri = convertedDirectoryUri('/pkg/foo'); 407 Uri fooUri = convertedDirectoryUri('/pkg/foo');
426 Uri barUri = convertedDirectoryUri('/pkg/bar'); 408 Uri barUri = convertedDirectoryUri('/pkg/bar');
427 createFile( 409 createFile(packageFilePath, '''
428 packageFilePath,
429 '''
430 foo:$fooUri 410 foo:$fooUri
431 bar:$barUri 411 bar:$barUri
432 '''); 412 ''');
433 413
434 Packages packages = builder.createPackageMap(projectPath); 414 Packages packages = builder.createPackageMap(projectPath);
435 expect(packages, isNotNull); 415 expect(packages, isNotNull);
436 Map<String, Uri> map = packages.asMap(); 416 Map<String, Uri> map = packages.asMap();
437 expect(map, hasLength(2)); 417 expect(map, hasLength(2));
438 expect(map['foo'], fooUri); 418 expect(map['foo'], fooUri);
439 expect(map['bar'], barUri); 419 expect(map['bar'], barUri);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 void test_createSourceFactory_noProvider_packages_embedder_extensions() { 472 void test_createSourceFactory_noProvider_packages_embedder_extensions() {
493 String rootPath = resourceProvider.convertPath('/root'); 473 String rootPath = resourceProvider.convertPath('/root');
494 Folder rootFolder = resourceProvider.getFolder(rootPath); 474 Folder rootFolder = resourceProvider.getFolder(rootPath);
495 createDefaultSdk(rootFolder); 475 createDefaultSdk(rootFolder);
496 String projectPath = pathContext.join(rootPath, 'project'); 476 String projectPath = pathContext.join(rootPath, 'project');
497 String packageFilePath = pathContext.join(projectPath, '.packages'); 477 String packageFilePath = pathContext.join(projectPath, '.packages');
498 String packageA = pathContext.join(rootPath, 'pkgs', 'a'); 478 String packageA = pathContext.join(rootPath, 'pkgs', 'a');
499 String embedderPath = pathContext.join(packageA, '_embedder.yaml'); 479 String embedderPath = pathContext.join(packageA, '_embedder.yaml');
500 String packageB = pathContext.join(rootPath, 'pkgs', 'b'); 480 String packageB = pathContext.join(rootPath, 'pkgs', 'b');
501 String extensionPath = pathContext.join(packageB, '_sdkext'); 481 String extensionPath = pathContext.join(packageB, '_sdkext');
502 createFile( 482 createFile(packageFilePath, '''
503 packageFilePath,
504 '''
505 a:${pathContext.toUri(packageA)} 483 a:${pathContext.toUri(packageA)}
506 b:${pathContext.toUri(packageB)} 484 b:${pathContext.toUri(packageB)}
507 '''); 485 ''');
508 String asyncPath = pathContext.join(packageA, 'sdk', 'async.dart'); 486 String asyncPath = pathContext.join(packageA, 'sdk', 'async.dart');
509 String corePath = pathContext.join(packageA, 'sdk', 'core.dart'); 487 String corePath = pathContext.join(packageA, 'sdk', 'core.dart');
510 createFile( 488 createFile(embedderPath, '''
511 embedderPath,
512 '''
513 embedded_libs: 489 embedded_libs:
514 "dart:async": ${_relativeUri(asyncPath, from: packageA)} 490 "dart:async": ${_relativeUri(asyncPath, from: packageA)}
515 "dart:core": ${_relativeUri(corePath, from: packageA)} 491 "dart:core": ${_relativeUri(corePath, from: packageA)}
516 '''); 492 ''');
517 String fooPath = pathContext.join(packageB, 'ext', 'foo.dart'); 493 String fooPath = pathContext.join(packageB, 'ext', 'foo.dart');
518 createFile( 494 createFile(extensionPath, '''{
519 extensionPath,
520 '''{
521 "dart:foo": "${_relativeUri(fooPath, from: packageB)}" 495 "dart:foo": "${_relativeUri(fooPath, from: packageB)}"
522 }'''); 496 }''');
523 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 497 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
524 498
525 SourceFactory factory = builder.createSourceFactory(projectPath, options); 499 SourceFactory factory = builder.createSourceFactory(projectPath, options);
526 500
527 Source asyncSource = factory.forUri('dart:async'); 501 Source asyncSource = factory.forUri('dart:async');
528 expect(asyncSource, isNotNull); 502 expect(asyncSource, isNotNull);
529 expect(asyncSource.fullName, asyncPath); 503 expect(asyncSource.fullName, asyncPath);
530 504
531 Source fooSource = factory.forUri('dart:foo'); 505 Source fooSource = factory.forUri('dart:foo');
532 expect(fooSource, isNotNull); 506 expect(fooSource, isNotNull);
533 expect(fooSource.fullName, fooPath); 507 expect(fooSource.fullName, fooPath);
534 508
535 Source packageSource = factory.forUri('package:b/b.dart'); 509 Source packageSource = factory.forUri('package:b/b.dart');
536 expect(packageSource, isNotNull); 510 expect(packageSource, isNotNull);
537 expect(packageSource.fullName, pathContext.join(packageB, 'b.dart')); 511 expect(packageSource.fullName, pathContext.join(packageB, 'b.dart'));
538 } 512 }
539 513
540 void test_createSourceFactory_noProvider_packages_embedder_noExtensions() { 514 void test_createSourceFactory_noProvider_packages_embedder_noExtensions() {
541 String rootPath = resourceProvider.convertPath('/root'); 515 String rootPath = resourceProvider.convertPath('/root');
542 Folder rootFolder = resourceProvider.getFolder(rootPath); 516 Folder rootFolder = resourceProvider.getFolder(rootPath);
543 createDefaultSdk(rootFolder); 517 createDefaultSdk(rootFolder);
544 String projectPath = pathContext.join(rootPath, 'project'); 518 String projectPath = pathContext.join(rootPath, 'project');
545 String packageFilePath = pathContext.join(projectPath, '.packages'); 519 String packageFilePath = pathContext.join(projectPath, '.packages');
546 String packageA = pathContext.join(rootPath, 'pkgs', 'a'); 520 String packageA = pathContext.join(rootPath, 'pkgs', 'a');
547 String embedderPath = pathContext.join(packageA, '_embedder.yaml'); 521 String embedderPath = pathContext.join(packageA, '_embedder.yaml');
548 String packageB = pathContext.join(rootPath, 'pkgs', 'b'); 522 String packageB = pathContext.join(rootPath, 'pkgs', 'b');
549 createFile( 523 createFile(packageFilePath, '''
550 packageFilePath,
551 '''
552 a:${pathContext.toUri(packageA)} 524 a:${pathContext.toUri(packageA)}
553 b:${pathContext.toUri(packageB)} 525 b:${pathContext.toUri(packageB)}
554 '''); 526 ''');
555 String asyncPath = pathContext.join(packageA, 'sdk', 'async.dart'); 527 String asyncPath = pathContext.join(packageA, 'sdk', 'async.dart');
556 String corePath = pathContext.join(packageA, 'sdk', 'core.dart'); 528 String corePath = pathContext.join(packageA, 'sdk', 'core.dart');
557 createFile( 529 createFile(embedderPath, '''
558 embedderPath,
559 '''
560 embedded_libs: 530 embedded_libs:
561 "dart:async": ${_relativeUri(asyncPath, from: packageA)} 531 "dart:async": ${_relativeUri(asyncPath, from: packageA)}
562 "dart:core": ${_relativeUri(corePath, from: packageA)} 532 "dart:core": ${_relativeUri(corePath, from: packageA)}
563 '''); 533 ''');
564 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 534 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
565 535
566 SourceFactory factory = builder.createSourceFactory(projectPath, options); 536 SourceFactory factory = builder.createSourceFactory(projectPath, options);
567 537
568 Source dartSource = factory.forUri('dart:async'); 538 Source dartSource = factory.forUri('dart:async');
569 expect(dartSource, isNotNull); 539 expect(dartSource, isNotNull);
(...skipping 10 matching lines...) Expand all
580 } 550 }
581 551
582 void test_createSourceFactory_noProvider_packages_noEmbedder_noExtensions() { 552 void test_createSourceFactory_noProvider_packages_noEmbedder_noExtensions() {
583 String rootPath = resourceProvider.convertPath('/root'); 553 String rootPath = resourceProvider.convertPath('/root');
584 Folder rootFolder = resourceProvider.getFolder(rootPath); 554 Folder rootFolder = resourceProvider.getFolder(rootPath);
585 createDefaultSdk(rootFolder); 555 createDefaultSdk(rootFolder);
586 String projectPath = pathContext.join(rootPath, 'project'); 556 String projectPath = pathContext.join(rootPath, 'project');
587 String packageFilePath = pathContext.join(projectPath, '.packages'); 557 String packageFilePath = pathContext.join(projectPath, '.packages');
588 String packageA = pathContext.join(rootPath, 'pkgs', 'a'); 558 String packageA = pathContext.join(rootPath, 'pkgs', 'a');
589 String packageB = pathContext.join(rootPath, 'pkgs', 'b'); 559 String packageB = pathContext.join(rootPath, 'pkgs', 'b');
590 createFile( 560 createFile(packageFilePath, '''
591 packageFilePath,
592 '''
593 a:${pathContext.toUri(packageA)} 561 a:${pathContext.toUri(packageA)}
594 b:${pathContext.toUri(packageB)} 562 b:${pathContext.toUri(packageB)}
595 '''); 563 ''');
596 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 564 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
597 565
598 SourceFactory factory = builder.createSourceFactory(projectPath, options); 566 SourceFactory factory = builder.createSourceFactory(projectPath, options);
599 567
600 Source dartSource = factory.forUri('dart:core'); 568 Source dartSource = factory.forUri('dart:core');
601 expect(dartSource, isNotNull); 569 expect(dartSource, isNotNull);
602 expect(dartSource.fullName, 570 expect(dartSource.fullName,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); 690 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl();
723 builderOptions.defaultOptions = defaultOptions; 691 builderOptions.defaultOptions = defaultOptions;
724 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); 692 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
725 expected.lint = true; 693 expected.lint = true;
726 expected.lintRules = <Linter>[_mockLintRule]; 694 expected.lintRules = <Linter>[_mockLintRule];
727 String packagesFilePath = 695 String packagesFilePath =
728 resourceProvider.convertPath('/some/directory/path/.packages'); 696 resourceProvider.convertPath('/some/directory/path/.packages');
729 createFile(packagesFilePath, 'flutter:/pkg/flutter/lib/'); 697 createFile(packagesFilePath, 'flutter:/pkg/flutter/lib/');
730 String optionsFilePath = resourceProvider 698 String optionsFilePath = resourceProvider
731 .convertPath('/pkg/flutter/lib/analysis_options_user.yaml'); 699 .convertPath('/pkg/flutter/lib/analysis_options_user.yaml');
732 createFile( 700 createFile(optionsFilePath, '''
733 optionsFilePath,
734 '''
735 linter: 701 linter:
736 rules: 702 rules:
737 - mock_lint_rule 703 - mock_lint_rule
738 '''); 704 ''');
739 String projPath = resourceProvider.convertPath('/some/directory/path'); 705 String projPath = resourceProvider.convertPath('/some/directory/path');
740 AnalysisOptions options = builder.getAnalysisOptions(projPath); 706 AnalysisOptions options = builder.getAnalysisOptions(projPath);
741 _expectEqualOptions(options, expected); 707 _expectEqualOptions(options, expected);
742 } 708 }
743 709
744 void test_getAnalysisOptions_default_flutter_disabled() { 710 void test_getAnalysisOptions_default_flutter_disabled() {
745 _defineMockLintRules(); 711 _defineMockLintRules();
746 ArgParser argParser = new ArgParser(); 712 ArgParser argParser = new ArgParser();
747 defineAnalysisArguments(argParser); 713 defineAnalysisArguments(argParser);
748 ArgResults argResults = 714 ArgResults argResults =
749 argParser.parse(['--no-$packageDefaultAnalysisOptions']); 715 argParser.parse(['--no-$packageDefaultAnalysisOptions']);
750 716
751 builderOptions = createContextBuilderOptions(argResults); 717 builderOptions = createContextBuilderOptions(argResults);
752 expect(builderOptions.packageDefaultAnalysisOptions, isFalse); 718 expect(builderOptions.packageDefaultAnalysisOptions, isFalse);
753 builder = new ContextBuilder(resourceProvider, sdkManager, contentCache, 719 builder = new ContextBuilder(resourceProvider, sdkManager, contentCache,
754 options: builderOptions); 720 options: builderOptions);
755 721
756 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); 722 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
757 723
758 String packagesFilePath = 724 String packagesFilePath =
759 resourceProvider.convertPath('/some/directory/path/.packages'); 725 resourceProvider.convertPath('/some/directory/path/.packages');
760 createFile(packagesFilePath, 'flutter:/pkg/flutter/lib/'); 726 createFile(packagesFilePath, 'flutter:/pkg/flutter/lib/');
761 String optionsFilePath = resourceProvider 727 String optionsFilePath = resourceProvider
762 .convertPath('/pkg/flutter/lib/analysis_options_user.yaml'); 728 .convertPath('/pkg/flutter/lib/analysis_options_user.yaml');
763 createFile( 729 createFile(optionsFilePath, '''
764 optionsFilePath,
765 '''
766 linter: 730 linter:
767 rules: 731 rules:
768 - mock_lint_rule 732 - mock_lint_rule
769 '''); 733 ''');
770 String projPath = resourceProvider.convertPath('/some/directory/path'); 734 String projPath = resourceProvider.convertPath('/some/directory/path');
771 AnalysisOptions options = builder.getAnalysisOptions(projPath); 735 AnalysisOptions options = builder.getAnalysisOptions(projPath);
772 _expectEqualOptions(options, expected); 736 _expectEqualOptions(options, expected);
773 } 737 }
774 738
775 void test_getAnalysisOptions_default_flutter_repo() { 739 void test_getAnalysisOptions_default_flutter_repo() {
776 _defineMockLintRules(); 740 _defineMockLintRules();
777 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); 741 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl();
778 builderOptions.defaultOptions = defaultOptions; 742 builderOptions.defaultOptions = defaultOptions;
779 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); 743 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
780 expected.lint = true; 744 expected.lint = true;
781 expected.lintRules = <Linter>[_mockLintRule, _mockPublicMemberApiDocs]; 745 expected.lintRules = <Linter>[_mockLintRule, _mockPublicMemberApiDocs];
782 String packagesFilePath = 746 String packagesFilePath =
783 resourceProvider.convertPath('/some/directory/path/.packages'); 747 resourceProvider.convertPath('/some/directory/path/.packages');
784 createFile(packagesFilePath, 'flutter:/pkg/flutter/lib/'); 748 createFile(packagesFilePath, 'flutter:/pkg/flutter/lib/');
785 String optionsFilePath = resourceProvider 749 String optionsFilePath = resourceProvider
786 .convertPath('/pkg/flutter/lib/analysis_options_user.yaml'); 750 .convertPath('/pkg/flutter/lib/analysis_options_user.yaml');
787 createFile( 751 createFile(optionsFilePath, '''
788 optionsFilePath,
789 '''
790 linter: 752 linter:
791 rules: 753 rules:
792 - mock_lint_rule 754 - mock_lint_rule
793 '''); 755 ''');
794 String projPath = resourceProvider.convertPath('/some/directory/path'); 756 String projPath = resourceProvider.convertPath('/some/directory/path');
795 AnalysisOptions options; 757 AnalysisOptions options;
796 try { 758 try {
797 ContextBuilderOptions.flutterRepo = true; 759 ContextBuilderOptions.flutterRepo = true;
798 options = builder.getAnalysisOptions(projPath); 760 options = builder.getAnalysisOptions(projPath);
799 } finally { 761 } finally {
800 ContextBuilderOptions.flutterRepo = false; 762 ContextBuilderOptions.flutterRepo = false;
801 } 763 }
802 _expectEqualOptions(options, expected); 764 _expectEqualOptions(options, expected);
803 } 765 }
804 766
805 void test_getAnalysisOptions_default_noOverrides() { 767 void test_getAnalysisOptions_default_noOverrides() {
806 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); 768 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl();
807 defaultOptions.enableLazyAssignmentOperators = true; 769 defaultOptions.enableLazyAssignmentOperators = true;
808 builderOptions.defaultOptions = defaultOptions; 770 builderOptions.defaultOptions = defaultOptions;
809 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); 771 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
810 expected.enableLazyAssignmentOperators = true; 772 expected.enableLazyAssignmentOperators = true;
811 String path = resourceProvider.convertPath('/some/directory/path'); 773 String path = resourceProvider.convertPath('/some/directory/path');
812 String filePath = 774 String filePath =
813 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); 775 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
814 resourceProvider.newFile( 776 resourceProvider.newFile(filePath, '''
815 filePath,
816 '''
817 linter: 777 linter:
818 rules: 778 rules:
819 - empty_constructor_bodies 779 - empty_constructor_bodies
820 '''); 780 ''');
821 781
822 AnalysisOptions options = builder.getAnalysisOptions(path); 782 AnalysisOptions options = builder.getAnalysisOptions(path);
823 _expectEqualOptions(options, expected); 783 _expectEqualOptions(options, expected);
824 } 784 }
825 785
826 void test_getAnalysisOptions_default_overrides() { 786 void test_getAnalysisOptions_default_overrides() {
827 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); 787 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl();
828 defaultOptions.enableSuperMixins = false; 788 defaultOptions.enableSuperMixins = false;
829 defaultOptions.enableLazyAssignmentOperators = true; 789 defaultOptions.enableLazyAssignmentOperators = true;
830 builderOptions.defaultOptions = defaultOptions; 790 builderOptions.defaultOptions = defaultOptions;
831 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); 791 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
832 expected.enableSuperMixins = true; 792 expected.enableSuperMixins = true;
833 expected.enableLazyAssignmentOperators = true; 793 expected.enableLazyAssignmentOperators = true;
834 String path = resourceProvider.convertPath('/some/directory/path'); 794 String path = resourceProvider.convertPath('/some/directory/path');
835 String filePath = 795 String filePath =
836 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); 796 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
837 resourceProvider.newFile( 797 resourceProvider.newFile(filePath, '''
838 filePath,
839 '''
840 analyzer: 798 analyzer:
841 language: 799 language:
842 enableSuperMixins : true 800 enableSuperMixins : true
843 '''); 801 ''');
844 802
845 AnalysisOptions options = builder.getAnalysisOptions(path); 803 AnalysisOptions options = builder.getAnalysisOptions(path);
846 _expectEqualOptions(options, expected); 804 _expectEqualOptions(options, expected);
847 } 805 }
848 806
849 void test_getAnalysisOptions_gnWorkspace() { 807 void test_getAnalysisOptions_gnWorkspace() {
(...skipping 23 matching lines...) Expand all
873 builderOptions.defaultOptions = defaultOptions; 831 builderOptions.defaultOptions = defaultOptions;
874 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); 832 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
875 expected.enableSuperMixins = true; 833 expected.enableSuperMixins = true;
876 expected.lint = true; 834 expected.lint = true;
877 expected.lintRules = <Linter>[ 835 expected.lintRules = <Linter>[
878 _mockLintRule, 836 _mockLintRule,
879 _mockLintRule2, 837 _mockLintRule2,
880 _mockLintRule3 838 _mockLintRule3
881 ]; 839 ];
882 resourceProvider.newFile( 840 resourceProvider.newFile(
883 resourceProvider.convertPath('/mypkgs/somepkg/lib/here.yaml'), 841 resourceProvider.convertPath('/mypkgs/somepkg/lib/here.yaml'), '''
884 '''
885 linter: 842 linter:
886 rules: 843 rules:
887 - mock_lint_rule3 844 - mock_lint_rule3
888 '''); 845 ''');
889 String path = resourceProvider.convertPath('/some/directory/path'); 846 String path = resourceProvider.convertPath('/some/directory/path');
890 resourceProvider.newFile( 847 resourceProvider.newFile(pathContext.join(path, '.packages'), '''
891 pathContext.join(path, '.packages'),
892 '''
893 somepkg:../../../mypkgs/somepkg/lib 848 somepkg:../../../mypkgs/somepkg/lib
894 '''); 849 ''');
895 resourceProvider.newFile( 850 resourceProvider.newFile(pathContext.join(path, 'bar.yaml'), '''
896 pathContext.join(path, 'bar.yaml'),
897 '''
898 include: package:somepkg/here.yaml 851 include: package:somepkg/here.yaml
899 analyzer: 852 analyzer:
900 language: 853 language:
901 enableSuperMixins : true 854 enableSuperMixins : true
902 linter: 855 linter:
903 rules: 856 rules:
904 - mock_lint_rule2 857 - mock_lint_rule2
905 '''); 858 ''');
906 String filePath = 859 String filePath =
907 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); 860 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
908 resourceProvider.newFile( 861 resourceProvider.newFile(filePath, '''
909 filePath,
910 '''
911 include: bar.yaml 862 include: bar.yaml
912 linter: 863 linter:
913 rules: 864 rules:
914 - mock_lint_rule 865 - mock_lint_rule
915 '''); 866 ''');
916 867
917 AnalysisOptions options = builder.getAnalysisOptions(path); 868 AnalysisOptions options = builder.getAnalysisOptions(path);
918 _expectEqualOptions(options, expected); 869 _expectEqualOptions(options, expected);
919 } 870 }
920 871
921 void test_getAnalysisOptions_invalid() { 872 void test_getAnalysisOptions_invalid() {
922 String path = resourceProvider.convertPath('/some/directory/path'); 873 String path = resourceProvider.convertPath('/some/directory/path');
923 String filePath = 874 String filePath =
924 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); 875 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
925 resourceProvider.newFile(filePath, ';'); 876 resourceProvider.newFile(filePath, ';');
926 877
927 AnalysisOptions options = builder.getAnalysisOptions(path); 878 AnalysisOptions options = builder.getAnalysisOptions(path);
928 expect(options, isNotNull); 879 expect(options, isNotNull);
929 } 880 }
930 881
931 void test_getAnalysisOptions_noDefault_noOverrides() { 882 void test_getAnalysisOptions_noDefault_noOverrides() {
932 String path = resourceProvider.convertPath('/some/directory/path'); 883 String path = resourceProvider.convertPath('/some/directory/path');
933 String filePath = 884 String filePath =
934 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); 885 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
935 resourceProvider.newFile( 886 resourceProvider.newFile(filePath, '''
936 filePath,
937 '''
938 linter: 887 linter:
939 rules: 888 rules:
940 - empty_constructor_bodies 889 - empty_constructor_bodies
941 '''); 890 ''');
942 891
943 AnalysisOptions options = builder.getAnalysisOptions(path); 892 AnalysisOptions options = builder.getAnalysisOptions(path);
944 _expectEqualOptions(options, new AnalysisOptionsImpl()); 893 _expectEqualOptions(options, new AnalysisOptionsImpl());
945 } 894 }
946 895
947 void test_getAnalysisOptions_noDefault_overrides() { 896 void test_getAnalysisOptions_noDefault_overrides() {
948 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); 897 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
949 expected.enableSuperMixins = true; 898 expected.enableSuperMixins = true;
950 String path = resourceProvider.convertPath('/some/directory/path'); 899 String path = resourceProvider.convertPath('/some/directory/path');
951 String filePath = 900 String filePath =
952 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); 901 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
953 resourceProvider.newFile( 902 resourceProvider.newFile(filePath, '''
954 filePath,
955 '''
956 analyzer: 903 analyzer:
957 language: 904 language:
958 enableSuperMixins : true 905 enableSuperMixins : true
959 '''); 906 ''');
960 907
961 AnalysisOptions options = builder.getAnalysisOptions(path); 908 AnalysisOptions options = builder.getAnalysisOptions(path);
962 _expectEqualOptions(options, expected); 909 _expectEqualOptions(options, expected);
963 } 910 }
964 911
965 void test_getAnalysisOptions_optionsPath() { 912 void test_getAnalysisOptions_optionsPath() {
966 String path = resourceProvider.convertPath('/some/directory/path'); 913 String path = resourceProvider.convertPath('/some/directory/path');
967 String filePath = 914 String filePath =
968 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); 915 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
969 resourceProvider.newFile( 916 resourceProvider.newFile(filePath, '''
970 filePath,
971 '''
972 linter: 917 linter:
973 rules: 918 rules:
974 - empty_constructor_bodies 919 - empty_constructor_bodies
975 '''); 920 ''');
976 921
977 ContextRoot root = new ContextRoot(path, []); 922 ContextRoot root = new ContextRoot(path, []);
978 builder.getAnalysisOptions(path, contextRoot: root); 923 builder.getAnalysisOptions(path, contextRoot: root);
979 expect(root.optionsFilePath, equals(filePath)); 924 expect(root.optionsFilePath, equals(filePath));
980 } 925 }
981 926
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 class _MockLintRule implements LintRule { 1052 class _MockLintRule implements LintRule {
1108 final String _name; 1053 final String _name;
1109 1054
1110 _MockLintRule(this._name); 1055 _MockLintRule(this._name);
1111 1056
1112 @override 1057 @override
1113 String get name => _name; 1058 String get name => _name;
1114 1059
1115 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 1060 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
1116 } 1061 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/command_line/arguments_test.dart ('k') | pkg/analyzer/test/src/context/context_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698