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

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

Issue 1364813003: Error handling for bad `.analysis_options` files. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « pkg/analysis_server/lib/src/context_manager.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 callbacks = new TestContextManagerCallbacks(resourceProvider); 89 callbacks = new TestContextManagerCallbacks(resourceProvider);
90 manager.callbacks = callbacks; 90 manager.callbacks = callbacks;
91 resourceProvider.newFolder(projPath); 91 resourceProvider.newFolder(projPath);
92 ContextManagerImpl.ENABLE_PACKAGESPEC_SUPPORT = true; 92 ContextManagerImpl.ENABLE_PACKAGESPEC_SUPPORT = true;
93 } 93 }
94 94
95 void tearDown() { 95 void tearDown() {
96 ContextManagerImpl.ENABLE_PACKAGESPEC_SUPPORT = false; 96 ContextManagerImpl.ENABLE_PACKAGESPEC_SUPPORT = false;
97 } 97 }
98 98
99 test_analysis_options_parse_failure() async {
100 // Create files.
101 String libPath = newFolder([projPath, LIB_NAME]);
102 newFile([libPath, 'main.dart']);
103 String sdkExtPath = newFolder([projPath, 'sdk_ext']);
104 newFile([sdkExtPath, 'entry.dart']);
105 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']);
106 newFile([sdkExtSrcPath, 'part.dart']);
107 // Setup analysis options file with ignore list.
108 newFile(
109 [projPath, '.analysis_options'],
110 r'''
111 ;
112 ''');
113 // Setup context.
114 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
115
116 // No error means success.
117 }
118
99 void test_contextsInAnalysisRoot_nestedContext() { 119 void test_contextsInAnalysisRoot_nestedContext() {
100 String subProjPath = posix.join(projPath, 'subproj'); 120 String subProjPath = posix.join(projPath, 'subproj');
101 Folder subProjFolder = resourceProvider.newFolder(subProjPath); 121 Folder subProjFolder = resourceProvider.newFolder(subProjPath);
102 resourceProvider.newFile( 122 resourceProvider.newFile(
103 posix.join(subProjPath, 'pubspec.yaml'), 'contents'); 123 posix.join(subProjPath, 'pubspec.yaml'), 'contents');
104 String subProjFilePath = posix.join(subProjPath, 'file.dart'); 124 String subProjFilePath = posix.join(subProjPath, 'file.dart');
105 resourceProvider.newFile(subProjFilePath, 'contents'); 125 resourceProvider.newFile(subProjFilePath, 'contents');
106 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 126 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
107 // Make sure that there really are contexts for both the main project and 127 // Make sure that there really are contexts for both the main project and
108 // the subproject. 128 // the subproject.
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 var contexts = 360 var contexts =
341 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); 361 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
342 expect(contexts.length, 2); 362 expect(contexts.length, 2);
343 expect(contexts[0].name, equals('/my/proj')); 363 expect(contexts[0].name, equals('/my/proj'));
344 expect(contexts[1].name, equals('/my/proj/lib')); 364 expect(contexts[1].name, equals('/my/proj/lib'));
345 } 365 }
346 366
347 // TODO(paulberry): This test only tests PackagesFileDisposition. 367 // TODO(paulberry): This test only tests PackagesFileDisposition.
348 // Once http://dartbug.com/23909 is fixed, add a test for sdk extensions 368 // Once http://dartbug.com/23909 is fixed, add a test for sdk extensions
349 // and PackageMapDisposition. 369 // and PackageMapDisposition.
350 test_sdk_ext_packagespec() async {
351 // Create files.
352 String libPath = newFolder([projPath, LIB_NAME]);
353 newFile([libPath, 'main.dart']);
354 newFile([libPath, 'nope.dart']);
355 String sdkExtPath = newFolder([projPath, 'sdk_ext']);
356 newFile([sdkExtPath, 'entry.dart']);
357 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']);
358 newFile([sdkExtSrcPath, 'part.dart']);
359 // Setup sdk extension mapping.
360 newFile(
361 [libPath, '_sdkext'],
362 r'''
363 {
364 "dart:foobar": "../sdk_ext/entry.dart"
365 }
366 ''');
367 // Setup .packages file
368 newFile(
369 [projPath, '.packages'],
370 r'''
371 test_pack:lib/
372 ''');
373 // Setup context.
374 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
375 // Confirm that one context was created.
376 var contexts =
377 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
378 expect(contexts, isNotNull);
379 expect(contexts.length, equals(1));
380 var context = contexts[0];
381 var source = context.sourceFactory.forUri('dart:foobar');
382 expect(source.fullName, equals('/my/proj/sdk_ext/entry.dart'));
383 }
384
385 test_refresh_folder_with_packagespec() { 370 test_refresh_folder_with_packagespec() {
386 // create a context with a .packages file 371 // create a context with a .packages file
387 String packagespecFile = posix.join(projPath, '.packages'); 372 String packagespecFile = posix.join(projPath, '.packages');
388 resourceProvider.newFile(packagespecFile, ''); 373 resourceProvider.newFile(packagespecFile, '');
389 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 374 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
390 return pumpEventQueue().then((_) { 375 return pumpEventQueue().then((_) {
391 expect(callbacks.currentContextPaths.toList(), [projPath]); 376 expect(callbacks.currentContextPaths.toList(), [projPath]);
392 callbacks.now++; 377 callbacks.now++;
393 manager.refresh(null); 378 manager.refresh(null);
394 return pumpEventQueue().then((_) { 379 return pumpEventQueue().then((_) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 callbacks.now++; 467 callbacks.now++;
483 manager.refresh([resourceProvider.getResource(proj2Path)]); 468 manager.refresh([resourceProvider.getResource(proj2Path)]);
484 return pumpEventQueue().then((_) { 469 return pumpEventQueue().then((_) {
485 expect(callbacks.currentContextPaths.toList(), unorderedEquals(roots)); 470 expect(callbacks.currentContextPaths.toList(), unorderedEquals(roots));
486 expect(callbacks.currentContextTimestamps[projPath], then); 471 expect(callbacks.currentContextTimestamps[projPath], then);
487 expect(callbacks.currentContextTimestamps[proj2Path], callbacks.now); 472 expect(callbacks.currentContextTimestamps[proj2Path], callbacks.now);
488 }); 473 });
489 }); 474 });
490 } 475 }
491 476
477 test_sdk_ext_packagespec() async {
478 // Create files.
479 String libPath = newFolder([projPath, LIB_NAME]);
480 newFile([libPath, 'main.dart']);
481 newFile([libPath, 'nope.dart']);
482 String sdkExtPath = newFolder([projPath, 'sdk_ext']);
483 newFile([sdkExtPath, 'entry.dart']);
484 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']);
485 newFile([sdkExtSrcPath, 'part.dart']);
486 // Setup sdk extension mapping.
487 newFile(
488 [libPath, '_sdkext'],
489 r'''
490 {
491 "dart:foobar": "../sdk_ext/entry.dart"
492 }
493 ''');
494 // Setup .packages file
495 newFile(
496 [projPath, '.packages'],
497 r'''
498 test_pack:lib/
499 ''');
500 // Setup context.
501 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
502 // Confirm that one context was created.
503 var contexts =
504 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
505 expect(contexts, isNotNull);
506 expect(contexts.length, equals(1));
507 var context = contexts[0];
508 var source = context.sourceFactory.forUri('dart:foobar');
509 expect(source.fullName, equals('/my/proj/sdk_ext/entry.dart'));
510 }
511
492 void test_setRoots_addFolderWithDartFile() { 512 void test_setRoots_addFolderWithDartFile() {
493 String filePath = posix.join(projPath, 'foo.dart'); 513 String filePath = posix.join(projPath, 'foo.dart');
494 resourceProvider.newFile(filePath, 'contents'); 514 resourceProvider.newFile(filePath, 'contents');
495 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 515 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
496 // verify 516 // verify
497 var filePaths = callbacks.currentContextFilePaths[projPath]; 517 var filePaths = callbacks.currentContextFilePaths[projPath];
498 expect(filePaths, hasLength(1)); 518 expect(filePaths, hasLength(1));
499 expect(filePaths, contains(filePath)); 519 expect(filePaths, contains(filePath));
500 List<AnalysisContext> contextsInAnalysisRoot = 520 List<AnalysisContext> contextsInAnalysisRoot =
501 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); 521 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
(...skipping 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1718 class TestUriResolver extends UriResolver { 1738 class TestUriResolver extends UriResolver {
1719 Map<Uri, Source> uriMap; 1739 Map<Uri, Source> uriMap;
1720 1740
1721 TestUriResolver(this.uriMap); 1741 TestUriResolver(this.uriMap);
1722 1742
1723 @override 1743 @override
1724 Source resolveAbsolute(Uri uri, [Uri actualUri]) { 1744 Source resolveAbsolute(Uri uri, [Uri actualUri]) {
1725 return uriMap[uri]; 1745 return uriMap[uri];
1726 } 1746 }
1727 } 1747 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/context_manager.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698