| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:analysis_server/protocol/protocol.dart'; | 7 import 'package:analysis_server/protocol/protocol.dart'; |
| 8 import 'package:analysis_server/protocol/protocol_generated.dart'; | 8 import 'package:analysis_server/protocol/protocol_generated.dart'; |
| 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/domain_server.dart'; | 11 import 'package:analysis_server/src/domain_server.dart'; |
| 12 import 'package:analysis_server/src/operation/operation.dart'; | |
| 13 import 'package:analysis_server/src/plugin/server_plugin.dart'; | 12 import 'package:analysis_server/src/plugin/server_plugin.dart'; |
| 14 import 'package:analyzer/exception/exception.dart'; | |
| 15 import 'package:analyzer/file_system/file_system.dart'; | 13 import 'package:analyzer/file_system/file_system.dart'; |
| 16 import 'package:analyzer/file_system/memory_file_system.dart'; | 14 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 17 import 'package:analyzer/instrumentation/instrumentation.dart'; | 15 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 18 import 'package:analyzer/src/generated/engine.dart'; | 16 import 'package:analyzer/src/generated/engine.dart'; |
| 19 import 'package:analyzer/src/generated/sdk.dart'; | 17 import 'package:analyzer/src/generated/sdk.dart'; |
| 20 import 'package:analyzer/src/generated/source.dart'; | |
| 21 import 'package:analyzer_plugin/protocol/protocol_common.dart'; | 18 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
| 22 import 'package:plugin/manager.dart'; | 19 import 'package:plugin/manager.dart'; |
| 23 import 'package:plugin/plugin.dart'; | 20 import 'package:plugin/plugin.dart'; |
| 24 import 'package:test/test.dart'; | 21 import 'package:test/test.dart'; |
| 25 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 22 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 26 import 'package:typed_mock/typed_mock.dart'; | |
| 27 | 23 |
| 28 import 'mock_sdk.dart'; | 24 import 'mock_sdk.dart'; |
| 29 import 'mocks.dart'; | 25 import 'mocks.dart'; |
| 30 | 26 |
| 31 main() { | 27 main() { |
| 32 defineReflectiveSuite(() { | 28 defineReflectiveSuite(() { |
| 33 defineReflectiveTests(AnalysisServerTest); | 29 defineReflectiveTests(AnalysisServerTest); |
| 34 }); | 30 }); |
| 35 } | 31 } |
| 36 | 32 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 new MockSdk(resourceProvider: resourceProvider); | 104 new MockSdk(resourceProvider: resourceProvider); |
| 109 packageMapProvider = new MockPackageMapProvider(); | 105 packageMapProvider = new MockPackageMapProvider(); |
| 110 server = new AnalysisServer( | 106 server = new AnalysisServer( |
| 111 channel, | 107 channel, |
| 112 resourceProvider, | 108 resourceProvider, |
| 113 packageMapProvider, | 109 packageMapProvider, |
| 114 null, | 110 null, |
| 115 serverPlugin, | 111 serverPlugin, |
| 116 new AnalysisServerOptions(), | 112 new AnalysisServerOptions(), |
| 117 new DartSdkManager('/', false), | 113 new DartSdkManager('/', false), |
| 118 InstrumentationService.NULL_SERVICE, | 114 InstrumentationService.NULL_SERVICE); |
| 119 rethrowExceptions: true); | |
| 120 } | 115 } |
| 121 | 116 |
| 122 Future test_echo() { | 117 Future test_echo() { |
| 123 server.handlers = [new EchoHandler()]; | 118 server.handlers = [new EchoHandler()]; |
| 124 var request = new Request('my22', 'echo'); | 119 var request = new Request('my22', 'echo'); |
| 125 return channel.sendRequest(request).then((Response response) { | 120 return channel.sendRequest(request).then((Response response) { |
| 126 expect(response.id, equals('my22')); | 121 expect(response.id, equals('my22')); |
| 127 expect(response.error, isNull); | 122 expect(response.error, isNull); |
| 128 }); | 123 }); |
| 129 } | 124 } |
| 130 | 125 |
| 131 void test_rethrowExceptions() { | |
| 132 Exception exceptionToThrow = new Exception('test exception'); | |
| 133 MockServerOperation operation = | |
| 134 new MockServerOperation(ServerOperationPriority.ANALYSIS, (_) { | |
| 135 throw exceptionToThrow; | |
| 136 }); | |
| 137 server.operationQueue.add(operation); | |
| 138 server.performOperationPending = true; | |
| 139 try { | |
| 140 server.performOperation(); | |
| 141 fail('exception not rethrown'); | |
| 142 } on AnalysisException catch (exception) { | |
| 143 expect(exception.cause.exception, equals(exceptionToThrow)); | |
| 144 } | |
| 145 } | |
| 146 | |
| 147 Future test_serverStatusNotifications() { | 126 Future test_serverStatusNotifications() { |
| 148 MockAnalysisContext context = new MockAnalysisContext('context'); | |
| 149 MockSource source = new MockSource('source'); | |
| 150 when(source.fullName).thenReturn('foo.dart'); | |
| 151 when(source.isInSystemLibrary).thenReturn(false); | |
| 152 ChangeNoticeImpl notice = new ChangeNoticeImpl(source); | |
| 153 notice.setErrors([], new LineInfo([0])); | |
| 154 AnalysisResult firstResult = new AnalysisResult([notice], 0, '', 0); | |
| 155 AnalysisResult lastResult = new AnalysisResult(null, 1, '', 1); | |
| 156 when(context.analysisOptions).thenReturn(new AnalysisOptionsImpl()); | |
| 157 when(context.performAnalysisTask) | |
| 158 .thenReturnList([firstResult, firstResult, firstResult, lastResult]); | |
| 159 server.serverServices.add(ServerService.STATUS); | 127 server.serverServices.add(ServerService.STATUS); |
| 160 server.schedulePerformAnalysisOperation(context); | 128 resourceProvider.newFolder('/pkg'); |
| 129 resourceProvider.newFolder('/pkg/lib'); |
| 130 resourceProvider.newFile('/pkg/lib/test.dart', 'class C {}'); |
| 131 server.setAnalysisRoots('0', ['/pkg'], [], {}); |
| 161 // Pump the event queue to make sure the server has finished any | 132 // Pump the event queue to make sure the server has finished any |
| 162 // analysis. | 133 // analysis. |
| 163 return pumpEventQueue().then((_) { | 134 return pumpEventQueue().then((_) { |
| 164 List<Notification> notifications = channel.notificationsReceived; | 135 List<Notification> notifications = channel.notificationsReceived; |
| 165 expect(notifications, isNotEmpty); | 136 expect(notifications, isNotEmpty); |
| 166 // expect at least one notification indicating analysis is in progress | 137 // expect at least one notification indicating analysis is in progress |
| 167 expect(notifications.any((Notification notification) { | 138 expect(notifications.any((Notification notification) { |
| 168 if (notification.event == SERVER_STATUS) { | 139 if (notification.event == SERVER_STATUS) { |
| 169 var params = new ServerStatusParams.fromNotification(notification); | 140 var params = new ServerStatusParams.fromNotification(notification); |
| 170 return params.analysis.isAnalyzing; | 141 if (params.analysis != null) { |
| 142 return params.analysis.isAnalyzing; |
| 143 } |
| 171 } | 144 } |
| 172 return false; | 145 return false; |
| 173 }), isTrue); | 146 }), isTrue); |
| 174 // the last notification should indicate that analysis is complete | 147 // the last notification should indicate that analysis is complete |
| 175 Notification notification = notifications[notifications.length - 1]; | 148 Notification notification = notifications[notifications.length - 1]; |
| 176 var params = new ServerStatusParams.fromNotification(notification); | 149 var params = new ServerStatusParams.fromNotification(notification); |
| 177 expect(params.analysis.isAnalyzing, isFalse); | 150 expect(params.analysis.isAnalyzing, isFalse); |
| 178 }); | 151 }); |
| 179 } | 152 } |
| 180 | 153 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 214 |
| 242 class EchoHandler implements RequestHandler { | 215 class EchoHandler implements RequestHandler { |
| 243 @override | 216 @override |
| 244 Response handleRequest(Request request) { | 217 Response handleRequest(Request request) { |
| 245 if (request.method == 'echo') { | 218 if (request.method == 'echo') { |
| 246 return new Response(request.id, result: {'echo': true}); | 219 return new Response(request.id, result: {'echo': true}); |
| 247 } | 220 } |
| 248 return null; | 221 return null; |
| 249 } | 222 } |
| 250 } | 223 } |
| OLD | NEW |