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'; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 serverPlugin, | 60 serverPlugin, |
61 new AnalysisServerOptions(), | 61 new AnalysisServerOptions(), |
62 new DartSdkManager('/', false), | 62 new DartSdkManager('/', false), |
63 InstrumentationService.NULL_SERVICE); | 63 InstrumentationService.NULL_SERVICE); |
64 handler = new AnalysisDomainHandler(server); | 64 handler = new AnalysisDomainHandler(server); |
65 }); | 65 }); |
66 | 66 |
67 group('updateContent', testUpdateContent); | 67 group('updateContent', testUpdateContent); |
68 | 68 |
69 group('AnalysisDomainHandler', () { | 69 group('AnalysisDomainHandler', () { |
70 group('getReachableSources', () { | 70 // TODO(brianwilkerson) Re-enable these tests if we re-enable the |
71 test('valid sources', () async { | 71 // analysis.getReachableSources request. |
72 String fileA = '/project/a.dart'; | 72 // group('getReachableSources', () { |
73 String fileB = '/project/b.dart'; | 73 // test('valid sources', () async { |
74 resourceProvider.newFile(fileA, 'import "b.dart";'); | 74 // String fileA = '/project/a.dart'; |
75 resourceProvider.newFile(fileB, ''); | 75 // String fileB = '/project/b.dart'; |
76 | 76 // resourceProvider.newFile(fileA, 'import "b.dart";'); |
77 server.setAnalysisRoots('0', ['/project/'], [], {}); | 77 // resourceProvider.newFile(fileB, ''); |
78 | 78 // |
79 await server.onAnalysisComplete; | 79 // server.setAnalysisRoots('0', ['/project/'], [], {}); |
80 | 80 // |
81 var request = | 81 // await server.onAnalysisComplete; |
82 new AnalysisGetReachableSourcesParams(fileA).toRequest('0'); | 82 // |
83 var response = handler.handleRequest(request); | 83 // var request = |
84 | 84 // new AnalysisGetReachableSourcesParams(fileA).toRequest('0'); |
85 Map json = response.toJson()[Response.RESULT]; | 85 // var response = handler.handleRequest(request); |
86 | 86 // |
87 // Sanity checks. | 87 // Map json = response.toJson()[Response.RESULT]; |
88 expect(json['sources'], hasLength(6)); | 88 // |
89 expect(json['sources']['file:///project/a.dart'], | 89 // // Sanity checks. |
90 unorderedEquals(['dart:core', 'file:///project/b.dart'])); | 90 // expect(json['sources'], hasLength(6)); |
91 expect(json['sources']['file:///project/b.dart'], ['dart:core']); | 91 // expect(json['sources']['file:///project/a.dart'], |
92 }); | 92 // unorderedEquals(['dart:core', 'file:///project/b.dart'])); |
93 | 93 // expect(json['sources']['file:///project/b.dart'], ['dart:core']); |
94 test('invalid source', () async { | 94 // }); |
95 resourceProvider.newFile('/project/a.dart', 'import "b.dart";'); | 95 // |
96 server.setAnalysisRoots('0', ['/project/'], [], {}); | 96 // test('invalid source', () async { |
97 | 97 // resourceProvider.newFile('/project/a.dart', 'import "b.dart";'); |
98 await server.onAnalysisComplete; | 98 // server.setAnalysisRoots('0', ['/project/'], [], {}); |
99 | 99 // |
100 var request = | 100 // await server.onAnalysisComplete; |
101 new AnalysisGetReachableSourcesParams('/does/not/exist.dart') | 101 // |
102 .toRequest('0'); | 102 // var request = |
103 var response = handler.handleRequest(request); | 103 // new AnalysisGetReachableSourcesParams('/does/not/exist.dart') |
104 expect(response.error, isNotNull); | 104 // .toRequest('0'); |
105 expect(response.error.code, | 105 // var response = handler.handleRequest(request); |
106 RequestErrorCode.GET_REACHABLE_SOURCES_INVALID_FILE); | 106 // expect(response.error, isNotNull); |
107 }); | 107 // expect(response.error.code, |
108 }); | 108 // RequestErrorCode.GET_REACHABLE_SOURCES_INVALID_FILE); |
| 109 // }); |
| 110 // }); |
109 | 111 |
110 group('setAnalysisRoots', () { | 112 group('setAnalysisRoots', () { |
111 Response testSetAnalysisRoots( | 113 Response testSetAnalysisRoots( |
112 List<String> included, List<String> excluded) { | 114 List<String> included, List<String> excluded) { |
113 Request request = new AnalysisSetAnalysisRootsParams(included, excluded) | 115 Request request = new AnalysisSetAnalysisRootsParams(included, excluded) |
114 .toRequest('0'); | 116 .toRequest('0'); |
115 return handler.handleRequest(request); | 117 return handler.handleRequest(request); |
116 } | 118 } |
117 | 119 |
118 group('excluded', () { | 120 group('excluded', () { |
119 test('excluded folder', () async { | 121 test('excluded folder', () async { |
120 String fileA = '/project/aaa/a.dart'; | 122 String fileA = '/project/aaa/a.dart'; |
121 String fileB = '/project/bbb/b.dart'; | 123 String fileB = '/project/bbb/b.dart'; |
122 resourceProvider.newFile(fileA, '// a'); | 124 resourceProvider.newFile(fileA, '// a'); |
123 resourceProvider.newFile(fileB, '// b'); | 125 resourceProvider.newFile(fileB, '// b'); |
124 var response = testSetAnalysisRoots(['/project'], ['/project/bbb']); | 126 var response = testSetAnalysisRoots(['/project'], ['/project/bbb']); |
125 var serverRef = server; | |
126 expect(response, isResponseSuccess('0')); | 127 expect(response, isResponseSuccess('0')); |
127 // unit "a" is resolved eventually | |
128 // unit "b" is not resolved | |
129 await server.onAnalysisComplete; | |
130 expect(await serverRef.getResolvedCompilationUnit(fileA), isNotNull); | |
131 expect(await serverRef.getResolvedCompilationUnit(fileB), isNull); | |
132 }); | 128 }); |
133 | 129 |
134 test('not absolute', () async { | 130 test('not absolute', () async { |
135 var response = testSetAnalysisRoots([], ['foo/bar']); | 131 var response = testSetAnalysisRoots([], ['foo/bar']); |
136 expect( | 132 expect( |
137 response, | 133 response, |
138 isResponseFailure( | 134 isResponseFailure( |
139 '0', RequestErrorCode.INVALID_FILE_PATH_FORMAT)); | 135 '0', RequestErrorCode.INVALID_FILE_PATH_FORMAT)); |
140 }); | 136 }); |
141 | 137 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 expect( | 184 expect( |
189 response, | 185 response, |
190 isResponseFailure( | 186 isResponseFailure( |
191 '0', RequestErrorCode.INVALID_FILE_PATH_FORMAT)); | 187 '0', RequestErrorCode.INVALID_FILE_PATH_FORMAT)); |
192 }); | 188 }); |
193 }); | 189 }); |
194 }); | 190 }); |
195 | 191 |
196 group('setPriorityFiles', () { | 192 group('setPriorityFiles', () { |
197 test('invalid', () { | 193 test('invalid', () { |
198 // TODO(paulberry): under the "eventual consistency" model this request | |
199 // should not be invalid. | |
200 var request = new AnalysisSetPriorityFilesParams(['/project/lib.dart']) | 194 var request = new AnalysisSetPriorityFilesParams(['/project/lib.dart']) |
201 .toRequest('0'); | 195 .toRequest('0'); |
202 var response = handler.handleRequest(request); | 196 var response = handler.handleRequest(request); |
203 expect(response, isResponseFailure('0')); | 197 expect(response, isResponseSuccess('0')); |
204 }); | 198 }); |
205 | 199 |
206 test('valid', () { | 200 test('valid', () { |
207 resourceProvider.newFolder('/p1'); | 201 resourceProvider.newFolder('/p1'); |
208 resourceProvider.newFile('/p1/a.dart', 'library a;'); | 202 resourceProvider.newFile('/p1/a.dart', 'library a;'); |
209 resourceProvider.newFolder('/p2'); | 203 resourceProvider.newFolder('/p2'); |
210 resourceProvider.newFile('/p2/b.dart', 'library b;'); | 204 resourceProvider.newFile('/p2/b.dart', 'library b;'); |
211 resourceProvider.newFile('/p2/c.dart', 'library c;'); | 205 resourceProvider.newFile('/p2/c.dart', 'library c;'); |
212 | 206 |
213 var setRootsRequest = | 207 var setRootsRequest = |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 serverChannel = new MockServerChannel(); | 439 serverChannel = new MockServerChannel(); |
446 resourceProvider = new MemoryResourceProvider(); | 440 resourceProvider = new MemoryResourceProvider(); |
447 // Create an SDK in the mock file system. | 441 // Create an SDK in the mock file system. |
448 new MockSdk(resourceProvider: resourceProvider); | 442 new MockSdk(resourceProvider: resourceProvider); |
449 server = new AnalysisServer( | 443 server = new AnalysisServer( |
450 serverChannel, | 444 serverChannel, |
451 resourceProvider, | 445 resourceProvider, |
452 new MockPackageMapProvider(), | 446 new MockPackageMapProvider(), |
453 null, | 447 null, |
454 serverPlugin, | 448 serverPlugin, |
455 new AnalysisServerOptions()..enableNewAnalysisDriver = true, | 449 new AnalysisServerOptions(), |
456 new DartSdkManager('/', false), | 450 new DartSdkManager('/', false), |
457 InstrumentationService.NULL_SERVICE); | 451 InstrumentationService.NULL_SERVICE); |
458 handler = new AnalysisDomainHandler(server); | 452 handler = new AnalysisDomainHandler(server); |
459 // listen for notifications | 453 // listen for notifications |
460 Stream<Notification> notificationStream = | 454 Stream<Notification> notificationStream = |
461 serverChannel.notificationController.stream; | 455 serverChannel.notificationController.stream; |
462 notificationStream.listen((Notification notification) { | 456 notificationStream.listen((Notification notification) { |
463 if (notification.event == ANALYSIS_ERRORS) { | 457 if (notification.event == ANALYSIS_ERRORS) { |
464 var decoded = new AnalysisErrorsParams.fromNotification(notification); | 458 var decoded = new AnalysisErrorsParams.fromNotification(notification); |
465 filesErrors[decoded.file] = decoded.errors; | 459 filesErrors[decoded.file] = decoded.errors; |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 plugin.AnalysisSetSubscriptionsParams params = | 807 plugin.AnalysisSetSubscriptionsParams params = |
814 pluginManager.analysisSetSubscriptionsParams; | 808 pluginManager.analysisSetSubscriptionsParams; |
815 expect(params, isNotNull); | 809 expect(params, isNotNull); |
816 Map<plugin.AnalysisService, List<String>> subscriptions = | 810 Map<plugin.AnalysisService, List<String>> subscriptions = |
817 params.subscriptions; | 811 params.subscriptions; |
818 expect(subscriptions, hasLength(1)); | 812 expect(subscriptions, hasLength(1)); |
819 List<String> files = subscriptions[plugin.AnalysisService.HIGHLIGHTS]; | 813 List<String> files = subscriptions[plugin.AnalysisService.HIGHLIGHTS]; |
820 expect(files, [testFile]); | 814 expect(files, [testFile]); |
821 } | 815 } |
822 } | 816 } |
OLD | NEW |