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

Side by Side Diff: pkg/analysis_server/test/context_manager_test.dart

Issue 1923973004: Pubspec-specified analysis configuration (#26359). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: typeo Created 4 years, 7 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 test.context.directory.manager; 5 library test.context.directory.manager;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analysis_server/src/context_manager.dart'; 9 import 'package:analysis_server/src/context_manager.dart';
10 import 'package:analyzer/file_system/file_system.dart'; 10 import 'package:analyzer/file_system/file_system.dart';
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 MemoryResourceProvider resourceProvider; 71 MemoryResourceProvider resourceProvider;
72 72
73 MockPackageMapProvider packageMapProvider; 73 MockPackageMapProvider packageMapProvider;
74 74
75 UriResolver packageResolver = null; 75 UriResolver packageResolver = null;
76 76
77 UriResolver embeddedUriResolver = null; 77 UriResolver embeddedUriResolver = null;
78 78
79 String projPath = '/my/proj'; 79 String projPath = '/my/proj';
80 80
81 AnalysisError missing_required_param = new AnalysisError(
82 new TestSource(), 0, 1, HintCode.MISSING_REQUIRED_PARAM, [
83 ['x']
84 ]);
85
81 AnalysisError missing_return = 86 AnalysisError missing_return =
82 new AnalysisError(new TestSource(), 0, 1, HintCode.MISSING_RETURN, [ 87 new AnalysisError(new TestSource(), 0, 1, HintCode.MISSING_RETURN, [
83 ['x'] 88 ['x']
84 ]); 89 ]);
85 90
86 AnalysisError invalid_assignment_error = 91 AnalysisError invalid_assignment_error =
87 new AnalysisError(new TestSource(), 0, 1, HintCode.INVALID_ASSIGNMENT, [ 92 new AnalysisError(new TestSource(), 0, 1, HintCode.INVALID_ASSIGNMENT, [
88 ['x'], 93 ['x'],
89 ['y'] 94 ['y']
90 ]); 95 ]);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 [projPath, '.analysis_options'], 282 [projPath, '.analysis_options'],
278 r''' 283 r'''
279 ; 284 ;
280 '''); 285 ''');
281 // Setup context. 286 // Setup context.
282 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 287 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
283 288
284 // No error means success. 289 // No error means success.
285 } 290 }
286 291
292 test_configed_options() async {
293 // Create files.
294 String libPath = newFolder([projPath, LIB_NAME]);
295 newFile([projPath, 'test', 'test.dart']);
296 newFile(
297 [projPath, 'pubspec.yaml'],
298 r'''
299 dependencies:
300 test_pack: any
301 analyzer:
302 configuration: test_pack/config
303 ''');
304
305 // Setup .packages file
306 newFile(
307 [projPath, '.packages'],
308 r'''
309 test_pack:lib/''');
310
311 // Setup config.yaml.
312 newFile(
313 [libPath, 'config', 'config.yaml'],
314 r'''
315 analyzer:
316 strong-mode: true
317 language:
318 enableSuperMixins: true
319 errors:
320 missing_return: false
321 linter:
322 rules:
323 - avoid_as
324 ''');
325
326 // Setup .analysis_options
327 newFile(
328 [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE],
329 r'''
330 analyzer:
331 exclude:
332 - 'test/**'
333 language:
334 enableGenericMethods: true
335 enableAsync: false
336 errors:
337 unused_local_variable: false
338 linter:
339 rules:
340 - camel_case_types
341 ''');
342
343 // Setup context.
344 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
345 await pumpEventQueue();
346
347 // Confirm that one context was created.
348 var contexts =
349 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
350 expect(contexts, isNotNull);
351 expect(contexts, hasLength(1));
352
353 var context = contexts.first;
354
355 // Verify options.
356 // * from `config.yaml`:
357 expect(context.analysisOptions.strongMode, isTrue);
358 expect(context.analysisOptions.enableSuperMixins, isTrue);
359 expect(context.analysisOptions.enableAsync, isFalse);
360 // * from `.analysis_options`:
361 expect(context.analysisOptions.enableGenericMethods, isTrue);
362
363 // * verify tests are excluded
364 expect(callbacks.currentContextFilePaths[projPath].keys,
365 unorderedEquals(['/my/proj/.analysis_options']));
366
367 // Verify filter setup.
368 expect(errorProcessors, hasLength(2));
369
370 // * (config.)
371 expect(getProcessor(missing_return).severity, isNull);
372
373 // * (options.)
374 expect(getProcessor(unused_local_variable).severity, isNull);
375
376 // Verify lints.
377 var lintNames = lints.map((lint) => lint.name);
378 expect(
379 lintNames,
380 unorderedEquals(
381 ['avoid_as' /* config */, 'camel_case_types' /* options */]));
382 }
383
287 void test_contextsInAnalysisRoot_nestedContext() { 384 void test_contextsInAnalysisRoot_nestedContext() {
288 String subProjPath = posix.join(projPath, 'subproj'); 385 String subProjPath = posix.join(projPath, 'subproj');
289 Folder subProjFolder = resourceProvider.newFolder(subProjPath); 386 Folder subProjFolder = resourceProvider.newFolder(subProjPath);
290 resourceProvider.newFile( 387 resourceProvider.newFile(
291 posix.join(subProjPath, 'pubspec.yaml'), 'contents'); 388 posix.join(subProjPath, 'pubspec.yaml'), 'contents');
292 String subProjFilePath = posix.join(subProjPath, 'file.dart'); 389 String subProjFilePath = posix.join(subProjPath, 'file.dart');
293 resourceProvider.newFile(subProjFilePath, 'contents'); 390 resourceProvider.newFile(subProjFilePath, 'contents');
294 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 391 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
295 // Make sure that there really are contexts for both the main project and 392 // Make sure that there really are contexts for both the main project and
296 // the subproject. 393 // the subproject.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 contexts = manager.contextsInAnalysisRoot(projectFolder); 452 contexts = manager.contextsInAnalysisRoot(projectFolder);
356 453
357 // Confirm that we still have just one context. 454 // Confirm that we still have just one context.
358 expect(contexts, isNotNull); 455 expect(contexts, isNotNull);
359 expect(contexts, hasLength(1)); 456 expect(contexts, hasLength(1));
360 457
361 // Embedded lib should be defined now. 458 // Embedded lib should be defined now.
362 expect(contexts.first.sourceFactory.forUri('dart:typed_data'), isNotNull); 459 expect(contexts.first.sourceFactory.forUri('dart:typed_data'), isNotNull);
363 } 460 }
364 461
462 test_embedder_and_configed_options() async {
463 // Create files.
464 String libPath = newFolder([projPath, LIB_NAME]);
465 String sdkExtPath = newFolder([projPath, 'sdk_ext']);
466 newFile([projPath, 'test', 'test.dart']);
467 newFile([sdkExtPath, 'entry.dart']);
468
469 // Setup pubspec with configuration.
470 newFile(
471 [projPath, 'pubspec.yaml'],
472 r'''
473 dependencies:
474 test_pack: any
475 analyzer:
476 configuration: test_pack/config
477 ''');
478
479 // Setup _embedder.yaml.
480 newFile(
481 [libPath, '_embedder.yaml'],
482 r'''
483 embedded_libs:
484 "dart:foobar": "../sdk_ext/entry.dart"
485 analyzer:
486 strong-mode: true
487 language:
488 enableSuperMixins: true
489 errors:
490 missing_return: false
491 linter:
492 rules:
493 - avoid_as
494 ''');
495
496 // Setup .packages file
497 newFile(
498 [projPath, '.packages'],
499 r'''
500 test_pack:lib/''');
501
502 // Setup .analysis_options
503 newFile(
504 [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE],
505 r'''
506 analyzer:
507 exclude:
508 - 'test/**'
509 language:
510 enableGenericMethods: true
511 enableAsync: false
512 errors:
513 unused_local_variable: false
514 linter:
515 rules:
516 - camel_case_types
517 ''');
518
519 // Setup config.yaml.
520 newFile(
521 [libPath, 'config', 'config.yaml'],
522 r'''
523 analyzer:
524 errors:
525 missing_required_param: error
526 linter:
527 rules:
528 - always_specify_types
529 ''');
530
531 // Setup context.
532 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
533 await pumpEventQueue();
534
535 // Confirm that one context was created.
536 var contexts =
537 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
538 expect(contexts, isNotNull);
539 expect(contexts, hasLength(1));
540 var context = contexts[0];
541
542 // Verify options.
543 // * from `_embedder.yaml`:
544 expect(context.analysisOptions.strongMode, isTrue);
545 expect(context.analysisOptions.enableSuperMixins, isTrue);
546 expect(context.analysisOptions.enableAsync, isFalse);
547 // * from `.analysis_options`:
548 expect(context.analysisOptions.enableGenericMethods, isTrue);
549
550 // * verify tests are excluded
551 expect(
552 callbacks.currentContextFilePaths[projPath].keys,
553 unorderedEquals(
554 ['/my/proj/sdk_ext/entry.dart', '/my/proj/.analysis_options']));
555
556 // Verify filter setup.
557 expect(errorProcessors, hasLength(3));
558
559 // * (embedder.)
560 expect(getProcessor(missing_return).severity, isNull);
561
562 // * (config.)
563 expect(getProcessor(missing_required_param).severity, ErrorSeverity.ERROR);
564
565 // * (options.)
566 expect(getProcessor(unused_local_variable).severity, isNull);
567
568 // Verify lints.
569 var lintNames = lints.map((lint) => lint.name);
570
571 expect(
572 lintNames,
573 unorderedEquals([
574 'avoid_as' /* embedder */,
575 'always_specify_types' /* config*/,
576 'camel_case_types' /* options */
577 ]));
578
579 // Sanity check embedder libs.
580 var source = context.sourceFactory.forUri('dart:foobar');
581 expect(source, isNotNull);
582 expect(source.fullName,
583 '/my/proj/sdk_ext/entry.dart'.replaceAll('/', JavaFile.separator));
584 }
585
365 test_embedder_options() async { 586 test_embedder_options() async {
366 // Create files. 587 // Create files.
367 String libPath = newFolder([projPath, LIB_NAME]); 588 String libPath = newFolder([projPath, LIB_NAME]);
368 String sdkExtPath = newFolder([projPath, 'sdk_ext']); 589 String sdkExtPath = newFolder([projPath, 'sdk_ext']);
369 newFile([projPath, 'test', 'test.dart']); 590 newFile([projPath, 'test', 'test.dart']);
370 newFile([sdkExtPath, 'entry.dart']); 591 newFile([sdkExtPath, 'entry.dart']);
371 // Setup _embedder.yaml. 592 // Setup _embedder.yaml.
372 newFile( 593 newFile(
373 [libPath, '_embedder.yaml'], 594 [libPath, '_embedder.yaml'],
374 r''' 595 r'''
(...skipping 2134 matching lines...) Expand 10 before | Expand all | Expand 10 after
2509 class TestUriResolver extends UriResolver { 2730 class TestUriResolver extends UriResolver {
2510 Map<Uri, Source> uriMap; 2731 Map<Uri, Source> uriMap;
2511 2732
2512 TestUriResolver(this.uriMap); 2733 TestUriResolver(this.uriMap);
2513 2734
2514 @override 2735 @override
2515 Source resolveAbsolute(Uri uri, [Uri actualUri]) { 2736 Source resolveAbsolute(Uri uri, [Uri actualUri]) {
2516 return uriMap[uri]; 2737 return uriMap[uri];
2517 } 2738 }
2518 } 2739 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698