| OLD | NEW | 
|---|
| 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.analysis_server; | 5 library test.analysis_server; | 
| 6 | 6 | 
| 7 import 'dart:async'; | 7 import 'dart:async'; | 
| 8 | 8 | 
| 9 import 'package:analysis_server/src/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; | 
| 10 import 'package:analysis_server/src/constants.dart'; | 10 import 'package:analysis_server/src/constants.dart'; | 
| 11 import 'package:analysis_server/src/context_manager.dart'; | 11 import 'package:analysis_server/src/context_manager.dart'; | 
| 12 import 'package:analysis_server/src/domain_server.dart'; | 12 import 'package:analysis_server/src/domain_server.dart'; | 
| 13 import 'package:analysis_server/src/operation/operation.dart'; | 13 import 'package:analysis_server/src/operation/operation.dart'; | 
| 14 import 'package:analysis_server/src/plugin/server_plugin.dart'; | 14 import 'package:analysis_server/src/plugin/server_plugin.dart'; | 
| 15 import 'package:analysis_server/src/protocol.dart'; | 15 import 'package:analysis_server/src/protocol.dart'; | 
| 16 import 'package:analyzer/file_system/file_system.dart'; | 16 import 'package:analyzer/file_system/file_system.dart'; | 
| 17 import 'package:analyzer/file_system/memory_file_system.dart'; | 17 import 'package:analyzer/file_system/memory_file_system.dart'; | 
| 18 import 'package:analyzer/instrumentation/instrumentation.dart'; | 18 import 'package:analyzer/instrumentation/instrumentation.dart'; | 
| 19 import 'package:analyzer/source/package_map_resolver.dart'; | 19 import 'package:analyzer/source/package_map_resolver.dart'; | 
| 20 import 'package:analyzer/src/generated/engine.dart'; | 20 import 'package:analyzer/src/generated/engine.dart'; | 
| 21 import 'package:analyzer/src/generated/java_engine.dart'; | 21 import 'package:analyzer/src/generated/java_engine.dart'; | 
| 22 import 'package:analyzer/src/generated/source.dart'; | 22 import 'package:analyzer/src/generated/source.dart'; | 
| 23 import 'package:plugin/manager.dart'; | 23 import 'package:plugin/manager.dart'; | 
| 24 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 24 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 
| 25 import 'package:typed_mock/typed_mock.dart'; | 25 import 'package:typed_mock/typed_mock.dart'; | 
| 26 import 'package:unittest/unittest.dart'; | 26 import 'package:unittest/unittest.dart'; | 
| 27 | 27 | 
| 28 import 'mock_sdk.dart'; | 28 import 'mock_sdk.dart'; | 
| 29 import 'mocks.dart'; | 29 import 'mocks.dart'; | 
|  | 30 import 'utils.dart'; | 
| 30 | 31 | 
| 31 main() { | 32 main() { | 
| 32   groupSep = ' | '; | 33   initializeTestEnvironment(); | 
| 33   defineReflectiveTests(AnalysisServerTest); | 34   defineReflectiveTests(AnalysisServerTest); | 
| 34 } | 35 } | 
| 35 | 36 | 
| 36 @reflectiveTest | 37 @reflectiveTest | 
| 37 class AnalysisServerTest { | 38 class AnalysisServerTest { | 
| 38   MockServerChannel channel; | 39   MockServerChannel channel; | 
| 39   AnalysisServer server; | 40   AnalysisServer server; | 
| 40   MemoryResourceProvider resourceProvider; | 41   MemoryResourceProvider resourceProvider; | 
| 41   MockPackageMapProvider packageMapProvider; | 42   MockPackageMapProvider packageMapProvider; | 
| 42 | 43 | 
| 43   /** | 44   /** | 
| 44    * Verify that getAnalysisContextForSource returns the correct contexts even | 45    * Verify that getAnalysisContextForSource returns the correct contexts even | 
| 45    * for sources that are included by multiple contexts. | 46    * for sources that are included by multiple contexts. | 
| 46    * | 47    * | 
| 47    * See dartbug.com/21898 | 48    * See dartbug.com/21898 | 
| 48    */ | 49    */ | 
| 49   Future fail_getAnalysisContextForSource_crossImports() { | 50   Future fail_getAnalysisContextForSource_crossImports() { | 
| 50     // Subscribe to STATUS so we'll know when analysis is done. | 51     // Subscribe to STATUS so we'll know when analysis is done. | 
| 51     server.serverServices = [ServerService.STATUS].toSet(); | 52     server.serverServices = [ServerService.STATUS].toSet(); | 
| 52     // Analyze project foo containing foo.dart and project bar containing | 53     // Analyze project foo containing foo.dart and project bar containing | 
| 53     // bar.dart. | 54     // bar.dart. | 
| 54     resourceProvider.newFolder('/foo'); | 55     resourceProvider.newFolder('/foo'); | 
| 55     resourceProvider.newFolder('/bar'); | 56     resourceProvider.newFolder('/bar'); | 
| 56     File foo = resourceProvider.newFile('/foo/foo.dart', ''' | 57     File foo = resourceProvider.newFile( | 
|  | 58         '/foo/foo.dart', | 
|  | 59         ''' | 
| 57 libary foo; | 60 libary foo; | 
| 58 import "../bar/bar.dart"; | 61 import "../bar/bar.dart"; | 
| 59 '''); | 62 '''); | 
| 60     Source fooSource = foo.createSource(); | 63     Source fooSource = foo.createSource(); | 
| 61     File bar = resourceProvider.newFile('/bar/bar.dart', ''' | 64     File bar = resourceProvider.newFile( | 
|  | 65         '/bar/bar.dart', | 
|  | 66         ''' | 
| 62 library bar; | 67 library bar; | 
| 63 import "../foo/foo.dart"; | 68 import "../foo/foo.dart"; | 
| 64 '''); | 69 '''); | 
| 65     Source barSource = bar.createSource(); | 70     Source barSource = bar.createSource(); | 
| 66     server.setAnalysisRoots('0', ['/foo', '/bar'], [], {}); | 71     server.setAnalysisRoots('0', ['/foo', '/bar'], [], {}); | 
| 67     return pumpEventQueue(40).then((_) { | 72     return pumpEventQueue(40).then((_) { | 
| 68       expect(server.statusAnalyzing, isFalse); | 73       expect(server.statusAnalyzing, isFalse); | 
| 69       // Make sure getAnalysisContext returns the proper context for each. | 74       // Make sure getAnalysisContext returns the proper context for each. | 
| 70       AnalysisContext fooContext = | 75       AnalysisContext fooContext = | 
| 71           server.getAnalysisContextForSource(fooSource); | 76           server.getAnalysisContextForSource(fooSource); | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 114     }); | 119     }); | 
| 115   } | 120   } | 
| 116 | 121 | 
| 117   void setUp() { | 122   void setUp() { | 
| 118     channel = new MockServerChannel(); | 123     channel = new MockServerChannel(); | 
| 119     resourceProvider = new MemoryResourceProvider(); | 124     resourceProvider = new MemoryResourceProvider(); | 
| 120     packageMapProvider = new MockPackageMapProvider(); | 125     packageMapProvider = new MockPackageMapProvider(); | 
| 121     ExtensionManager manager = new ExtensionManager(); | 126     ExtensionManager manager = new ExtensionManager(); | 
| 122     ServerPlugin serverPlugin = new ServerPlugin(); | 127     ServerPlugin serverPlugin = new ServerPlugin(); | 
| 123     manager.processPlugins([serverPlugin]); | 128     manager.processPlugins([serverPlugin]); | 
| 124     server = new AnalysisServer(channel, resourceProvider, packageMapProvider, | 129     server = new AnalysisServer( | 
| 125         null, serverPlugin, new AnalysisServerOptions(), new MockSdk(), | 130         channel, | 
| 126         InstrumentationService.NULL_SERVICE, rethrowExceptions: true); | 131         resourceProvider, | 
|  | 132         packageMapProvider, | 
|  | 133         null, | 
|  | 134         serverPlugin, | 
|  | 135         new AnalysisServerOptions(), | 
|  | 136         new MockSdk(), | 
|  | 137         InstrumentationService.NULL_SERVICE, | 
|  | 138         rethrowExceptions: true); | 
| 127   } | 139   } | 
| 128 | 140 | 
| 129   Future test_contextDisposed() { | 141   Future test_contextDisposed() { | 
| 130     resourceProvider.newFolder('/foo'); | 142     resourceProvider.newFolder('/foo'); | 
| 131     resourceProvider.newFile('/foo/bar.dart', 'library lib;'); | 143     resourceProvider.newFile('/foo/bar.dart', 'library lib;'); | 
| 132     server.setAnalysisRoots('0', ['/foo'], [], {}); | 144     server.setAnalysisRoots('0', ['/foo'], [], {}); | 
| 133     AnalysisContext context; | 145     AnalysisContext context; | 
| 134     return pumpEventQueue().then((_) { | 146     return pumpEventQueue().then((_) { | 
| 135       context = server.getAnalysisContext('/foo/bar.dart'); | 147       context = server.getAnalysisContext('/foo/bar.dart'); | 
| 136       server.setAnalysisRoots('1', [], [], {}); | 148       server.setAnalysisRoots('1', [], [], {}); | 
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 398       server.setPriorityFiles('17', []); | 410       server.setPriorityFiles('17', []); | 
| 399       return pumpEventQueue(); | 411       return pumpEventQueue(); | 
| 400     }).then((_) { | 412     }).then((_) { | 
| 401       expect(eventCount, 3); | 413       expect(eventCount, 3); | 
| 402       expect(firstSource, isNull); | 414       expect(firstSource, isNull); | 
| 403     }); | 415     }); | 
| 404   } | 416   } | 
| 405 | 417 | 
| 406   void test_rethrowExceptions() { | 418   void test_rethrowExceptions() { | 
| 407     Exception exceptionToThrow = new Exception('test exception'); | 419     Exception exceptionToThrow = new Exception('test exception'); | 
| 408     MockServerOperation operation = new MockServerOperation( | 420     MockServerOperation operation = | 
| 409         ServerOperationPriority.ANALYSIS, (_) { | 421         new MockServerOperation(ServerOperationPriority.ANALYSIS, (_) { | 
| 410       throw exceptionToThrow; | 422       throw exceptionToThrow; | 
| 411     }); | 423     }); | 
| 412     server.operationQueue.add(operation); | 424     server.operationQueue.add(operation); | 
| 413     server.performOperationPending = true; | 425     server.performOperationPending = true; | 
| 414     try { | 426     try { | 
| 415       server.performOperation(); | 427       server.performOperation(); | 
| 416       fail('exception not rethrown'); | 428       fail('exception not rethrown'); | 
| 417     } on AnalysisException catch (exception) { | 429     } on AnalysisException catch (exception) { | 
| 418       expect(exception.cause.exception, equals(exceptionToThrow)); | 430       expect(exception.cause.exception, equals(exceptionToThrow)); | 
| 419     } | 431     } | 
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 502   _MockServerOperation(this.context); | 514   _MockServerOperation(this.context); | 
| 503 | 515 | 
| 504   @override | 516   @override | 
| 505   ServerOperationPriority get priority => ServerOperationPriority.ANALYSIS; | 517   ServerOperationPriority get priority => ServerOperationPriority.ANALYSIS; | 
| 506 | 518 | 
| 507   @override | 519   @override | 
| 508   void perform(AnalysisServer server) { | 520   void perform(AnalysisServer server) { | 
| 509     isComplete = true; | 521     isComplete = true; | 
| 510   } | 522   } | 
| 511 } | 523 } | 
| OLD | NEW | 
|---|