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

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

Issue 725143004: Format and sort analyzer and analysis_server packages. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 | Annotate | Revision Log
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.analysis_server; 5 library test.analysis_server;
6 6
7 import 'package:analysis_server/src/analysis_server.dart'; 7 import 'package:analysis_server/src/analysis_server.dart';
8 import 'package:analysis_server/src/constants.dart'; 8 import 'package:analysis_server/src/constants.dart';
9 import 'package:analysis_server/src/domain_server.dart'; 9 import 'package:analysis_server/src/domain_server.dart';
10 import 'package:analysis_server/src/operation/operation.dart'; 10 import 'package:analysis_server/src/operation/operation.dart';
11 import 'package:analysis_server/src/protocol.dart'; 11 import 'package:analysis_server/src/protocol.dart';
12 import 'package:analyzer/file_system/memory_file_system.dart'; 12 import 'package:analyzer/file_system/memory_file_system.dart';
13 import 'package:analyzer/src/generated/engine.dart'; 13 import 'package:analyzer/src/generated/engine.dart';
14 import 'package:analyzer/src/generated/java_engine.dart'; 14 import 'package:analyzer/src/generated/java_engine.dart';
15 import 'package:analyzer/src/generated/source.dart'; 15 import 'package:analyzer/src/generated/source.dart';
16 import 'package:typed_mock/typed_mock.dart'; 16 import 'package:typed_mock/typed_mock.dart';
17 import 'package:unittest/unittest.dart'; 17 import 'package:unittest/unittest.dart';
18 18
19 import 'mock_sdk.dart';
19 import 'mocks.dart'; 20 import 'mocks.dart';
20 import 'mock_sdk.dart';
21 21
22 main() { 22 main() {
23 group('AnalysisServer', () { 23 group('AnalysisServer', () {
24 test('server.status notifications', () { 24 test('server.status notifications', () {
25 AnalysisServerTestHelper helper = new AnalysisServerTestHelper(); 25 AnalysisServerTestHelper helper = new AnalysisServerTestHelper();
26 MockAnalysisContext context = new MockAnalysisContext('context'); 26 MockAnalysisContext context = new MockAnalysisContext('context');
27 MockSource source = new MockSource('source'); 27 MockSource source = new MockSource('source');
28 when(source.fullName).thenReturn('foo.dart'); 28 when(source.fullName).thenReturn('foo.dart');
29 when(source.isInSystemLibrary).thenReturn(false); 29 when(source.isInSystemLibrary).thenReturn(false);
30 ChangeNoticeImpl notice = new ChangeNoticeImpl(source); 30 ChangeNoticeImpl notice = new ChangeNoticeImpl(source);
31 notice.setErrors([], new LineInfo([0])); 31 notice.setErrors([], new LineInfo([0]));
32 AnalysisResult firstResult = new AnalysisResult([notice], 0, '', 0); 32 AnalysisResult firstResult = new AnalysisResult([notice], 0, '', 0);
33 AnalysisResult lastResult = new AnalysisResult(null, 1, '', 1); 33 AnalysisResult lastResult = new AnalysisResult(null, 1, '', 1);
34 when(context.performAnalysisTask).thenReturnList( 34 when(
35 [firstResult, firstResult, firstResult, lastResult]); 35 context.performAnalysisTask).thenReturnList(
36 [firstResult, firstResult, firstResult, lastResult]);
36 helper.server.serverServices.add(ServerService.STATUS); 37 helper.server.serverServices.add(ServerService.STATUS);
37 helper.server.schedulePerformAnalysisOperation(context); 38 helper.server.schedulePerformAnalysisOperation(context);
38 // Pump the event queue to make sure the server has finished any 39 // Pump the event queue to make sure the server has finished any
39 // analysis. 40 // analysis.
40 return pumpEventQueue().then((_) { 41 return pumpEventQueue().then((_) {
41 List<Notification> notifications = helper.channel.notificationsReceived; 42 List<Notification> notifications = helper.channel.notificationsReceived;
42 expect(notifications, isNot(isEmpty)); 43 expect(notifications, isNot(isEmpty));
43 // expect at least one notification indicating analysis is in progress 44 // expect at least one notification indicating analysis is in progress
44 expect(notifications.any((Notification notification) { 45 expect(notifications.any((Notification notification) {
45 if (notification.event == SERVER_STATUS) { 46 if (notification.event == SERVER_STATUS) {
46 var params = new ServerStatusParams.fromNotification(notification); 47 var params = new ServerStatusParams.fromNotification(notification);
47 return params.analysis.isAnalyzing; 48 return params.analysis.isAnalyzing;
48 } 49 }
49 return false; 50 return false;
50 }), isTrue); 51 }), isTrue);
51 // the last notification should indicate that analysis is complete 52 // the last notification should indicate that analysis is complete
52 Notification notification = notifications[notifications.length - 1]; 53 Notification notification = notifications[notifications.length - 1];
53 var params = new ServerStatusParams.fromNotification(notification); 54 var params = new ServerStatusParams.fromNotification(notification);
54 expect(params.analysis.isAnalyzing, isFalse); 55 expect(params.analysis.isAnalyzing, isFalse);
55 }); 56 });
56 }); 57 });
57 58
58 test('echo', () { 59 test('echo', () {
59 AnalysisServerTestHelper helper = new AnalysisServerTestHelper(); 60 AnalysisServerTestHelper helper = new AnalysisServerTestHelper();
60 helper.server.handlers = [new EchoHandler()]; 61 helper.server.handlers = [new EchoHandler()];
61 var request = new Request('my22', 'echo'); 62 var request = new Request('my22', 'echo');
62 return helper.channel.sendRequest(request) 63 return helper.channel.sendRequest(request).then((Response response) {
63 .then((Response response) { 64 expect(response.id, equals('my22'));
64 expect(response.id, equals('my22')); 65 expect(response.error, isNull);
65 expect(response.error, isNull); 66 });
66 });
67 }); 67 });
68 68
69 test('shutdown', () { 69 test('shutdown', () {
70 AnalysisServerTestHelper helper = new AnalysisServerTestHelper(); 70 AnalysisServerTestHelper helper = new AnalysisServerTestHelper();
71 helper.server.handlers = [new ServerDomainHandler(helper.server)]; 71 helper.server.handlers = [new ServerDomainHandler(helper.server)];
72 var request = new Request('my28', SERVER_SHUTDOWN); 72 var request = new Request('my28', SERVER_SHUTDOWN);
73 return helper.channel.sendRequest(request) 73 return helper.channel.sendRequest(request).then((Response response) {
74 .then((Response response) { 74 expect(response.id, equals('my28'));
75 expect(response.id, equals('my28')); 75 expect(response.error, isNull);
76 expect(response.error, isNull); 76 });
77 });
78 }); 77 });
79 78
80 test('unknownRequest', () { 79 test('unknownRequest', () {
81 AnalysisServerTestHelper helper = new AnalysisServerTestHelper(); 80 AnalysisServerTestHelper helper = new AnalysisServerTestHelper();
82 helper.server.handlers = [new EchoHandler()]; 81 helper.server.handlers = [new EchoHandler()];
83 var request = new Request('my22', 'randomRequest'); 82 var request = new Request('my22', 'randomRequest');
84 return helper.channel.sendRequest(request) 83 return helper.channel.sendRequest(request).then((Response response) {
85 .then((Response response) { 84 expect(response.id, equals('my22'));
86 expect(response.id, equals('my22')); 85 expect(response.error, isNotNull);
87 expect(response.error, isNotNull); 86 });
88 });
89 }); 87 });
90 88
91 test('rethrow exceptions', () { 89 test('rethrow exceptions', () {
92 AnalysisServerTestHelper helper = new AnalysisServerTestHelper(); 90 AnalysisServerTestHelper helper = new AnalysisServerTestHelper();
93 Exception exceptionToThrow = new Exception('test exception'); 91 Exception exceptionToThrow = new Exception('test exception');
94 MockServerOperation operation = new MockServerOperation( 92 MockServerOperation operation =
95 ServerOperationPriority.ANALYSIS, (_) { throw exceptionToThrow; }); 93 new MockServerOperation(ServerOperationPriority.ANALYSIS, (_) {
94 throw exceptionToThrow;
95 });
96 helper.server.operationQueue.add(operation); 96 helper.server.operationQueue.add(operation);
97 helper.server.performOperationPending = true; 97 helper.server.performOperationPending = true;
98 try { 98 try {
99 helper.server.performOperation(); 99 helper.server.performOperation();
100 fail('exception not rethrown'); 100 fail('exception not rethrown');
101 } on AnalysisException catch (exception) { 101 } on AnalysisException catch (exception) {
102 expect(exception.cause.exception, equals(exceptionToThrow)); 102 expect(exception.cause.exception, equals(exceptionToThrow));
103 } 103 }
104 }); 104 });
105 105
(...skipping 21 matching lines...) Expand all
127 127
128 helper.server.setAnalysisRoots('0', ['/foo'], [], {}); 128 helper.server.setAnalysisRoots('0', ['/foo'], [], {});
129 return pumpEventQueue().then((_) { 129 return pumpEventQueue().then((_) {
130 expect(wasAdded, isTrue); 130 expect(wasAdded, isTrue);
131 expect(wasChanged, isFalse); 131 expect(wasChanged, isFalse);
132 expect(wasRemoved, isFalse); 132 expect(wasRemoved, isFalse);
133 133
134 wasAdded = false; 134 wasAdded = false;
135 wasChanged = false; 135 wasChanged = false;
136 wasRemoved = false; 136 wasRemoved = false;
137 helper.server.setAnalysisRoots('0', ['/foo'], [], {'/foo':'/bar'}); 137 helper.server.setAnalysisRoots('0', ['/foo'], [], {
138 '/foo': '/bar'
139 });
138 return pumpEventQueue(); 140 return pumpEventQueue();
139 }).then((_) { 141 }).then((_) {
140 expect(wasAdded, isFalse); 142 expect(wasAdded, isFalse);
141 expect(wasChanged, isTrue); 143 expect(wasChanged, isTrue);
142 expect(wasRemoved, isFalse); 144 expect(wasRemoved, isFalse);
143 145
144 wasAdded = false; 146 wasAdded = false;
145 wasChanged = false; 147 wasChanged = false;
146 wasRemoved = false; 148 wasRemoved = false;
147 helper.server.setAnalysisRoots('0', [], [], {}); 149 helper.server.setAnalysisRoots('0', [], [], {});
148 return pumpEventQueue(); 150 return pumpEventQueue();
149 }).then((_) { 151 }).then((_) {
150 expect(wasAdded, isFalse); 152 expect(wasAdded, isFalse);
151 expect(wasChanged, isFalse); 153 expect(wasChanged, isFalse);
152 expect(wasRemoved, isTrue); 154 expect(wasRemoved, isTrue);
153 }); 155 });
154 }); 156 });
155 }); 157 });
156 } 158 }
157 159
158 class AnalysisServerTestHelper { 160 class AnalysisServerTestHelper {
159 MockServerChannel channel; 161 MockServerChannel channel;
160 AnalysisServer server; 162 AnalysisServer server;
161 MemoryResourceProvider resourceProvider; 163 MemoryResourceProvider resourceProvider;
162 164
163 AnalysisServerTestHelper({bool rethrowExceptions: true}) { 165 AnalysisServerTestHelper({bool rethrowExceptions: true}) {
164 channel = new MockServerChannel(); 166 channel = new MockServerChannel();
165 resourceProvider = new MemoryResourceProvider(); 167 resourceProvider = new MemoryResourceProvider();
166 server = new AnalysisServer(channel, resourceProvider, 168 server = new AnalysisServer(
167 new MockPackageMapProvider(), null, new MockSdk(), 169 channel,
170 resourceProvider,
171 new MockPackageMapProvider(),
172 null,
173 new MockSdk(),
168 rethrowExceptions: rethrowExceptions); 174 rethrowExceptions: rethrowExceptions);
169 } 175 }
170 } 176 }
171 177
172 class EchoHandler implements RequestHandler { 178 class EchoHandler implements RequestHandler {
173 @override 179 @override
174 Response handleRequest(Request request) { 180 Response handleRequest(Request request) {
175 if (request.method == 'echo') { 181 if (request.method == 'echo') {
176 return new Response(request.id, result: {'echo': true}); 182 return new Response(request.id, result: {
183 'echo': true
184 });
177 } 185 }
178 return null; 186 return null;
179 } 187 }
180 } 188 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/analysis_abstract.dart ('k') | pkg/analysis_server/test/channel/byte_stream_channel_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698