| 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/domain_server.dart'; | 11 import 'package:analysis_server/src/domain_server.dart'; |
| 12 import 'package:analysis_server/src/operation/operation.dart'; | 12 import 'package:analysis_server/src/operation/operation.dart'; |
| 13 import 'package:analysis_server/src/protocol.dart'; | 13 import 'package:analysis_server/src/protocol.dart'; |
| 14 import 'package:analyzer/file_system/file_system.dart'; |
| 14 import 'package:analyzer/file_system/memory_file_system.dart'; | 15 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 15 import 'package:analyzer/instrumentation/instrumentation.dart'; | 16 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 16 import 'package:analyzer/src/generated/engine.dart'; | 17 import 'package:analyzer/src/generated/engine.dart'; |
| 17 import 'package:analyzer/src/generated/java_engine.dart'; | 18 import 'package:analyzer/src/generated/java_engine.dart'; |
| 18 import 'package:analyzer/src/generated/source.dart'; | 19 import 'package:analyzer/src/generated/source.dart'; |
| 19 import 'package:typed_mock/typed_mock.dart'; | 20 import 'package:typed_mock/typed_mock.dart'; |
| 20 import 'package:unittest/unittest.dart'; | 21 import 'package:unittest/unittest.dart'; |
| 21 | 22 |
| 22 import 'mock_sdk.dart'; | 23 import 'mock_sdk.dart'; |
| 23 import 'mocks.dart'; | 24 import 'mocks.dart'; |
| 24 import 'reflective_tests.dart'; | 25 import 'reflective_tests.dart'; |
| 25 | 26 |
| 26 main() { | 27 main() { |
| 27 groupSep = ' | '; | 28 groupSep = ' | '; |
| 28 runReflectiveTests(AnalysisServerTest); | 29 runReflectiveTests(AnalysisServerTest); |
| 29 } | 30 } |
| 30 | 31 |
| 31 @ReflectiveTestCase() | 32 @ReflectiveTestCase() |
| 32 class AnalysisServerTest { | 33 class AnalysisServerTest { |
| 33 MockServerChannel channel; | 34 MockServerChannel channel; |
| 34 AnalysisServer server; | 35 AnalysisServer server; |
| 35 MemoryResourceProvider resourceProvider; | 36 MemoryResourceProvider resourceProvider; |
| 36 | 37 |
| 38 /** |
| 39 * Verify that getAnalysisContextForSource returns the correct contexts even |
| 40 * for sources that are included by multiple contexts. |
| 41 * |
| 42 * See dartbug.com/21898 |
| 43 */ |
| 44 Future fail_getAnalysisContextForSource_crossImports() { |
| 45 // Subscribe to STATUS so we'll know when analysis is done. |
| 46 server.serverServices = [ServerService.STATUS].toSet(); |
| 47 // Analyze project foo containing foo.dart and project bar containing |
| 48 // bar.dart. |
| 49 resourceProvider.newFolder('/foo'); |
| 50 resourceProvider.newFolder('/bar'); |
| 51 File foo = resourceProvider.newFile('/foo/foo.dart', ''' |
| 52 libary foo; |
| 53 import "../bar/bar.dart"; |
| 54 '''); |
| 55 Source fooSource = foo.createSource(); |
| 56 File bar = resourceProvider.newFile('/bar/bar.dart', ''' |
| 57 library bar; |
| 58 import "../foo/foo.dart"; |
| 59 '''); |
| 60 Source barSource = bar.createSource(); |
| 61 server.setAnalysisRoots('0', ['/foo', '/bar'], [], {}); |
| 62 return pumpEventQueue(40).then((_) { |
| 63 expect(server.statusAnalyzing, isFalse); |
| 64 // Make sure getAnalysisContext returns the proper context for each. |
| 65 AnalysisContext fooContext = |
| 66 server.getAnalysisContextForSource(fooSource); |
| 67 expect(fooContext, isNotNull); |
| 68 AnalysisContext barContext = |
| 69 server.getAnalysisContextForSource(barSource); |
| 70 expect(barContext, isNotNull); |
| 71 expect(fooContext, isNot(same(barContext))); |
| 72 expect(fooContext.getKindOf(fooSource), SourceKind.LIBRARY); |
| 73 expect(fooContext.getKindOf(barSource), SourceKind.UNKNOWN); |
| 74 expect(barContext.getKindOf(fooSource), SourceKind.UNKNOWN); |
| 75 expect(barContext.getKindOf(barSource), SourceKind.LIBRARY); |
| 76 }); |
| 77 } |
| 78 |
| 79 /** |
| 80 * Verify that getAnalysisContextForSource returns the correct contexts even |
| 81 * for sources that haven't been analyzed yet. |
| 82 * |
| 83 * See dartbug.com/21898 |
| 84 */ |
| 85 Future fail_getAnalysisContextForSource_unanalyzed() { |
| 86 // Subscribe to STATUS so we'll know when analysis is done. |
| 87 server.serverServices = [ServerService.STATUS].toSet(); |
| 88 // Analyze project foo containing foo.dart and project bar containing |
| 89 // bar.dart. |
| 90 resourceProvider.newFolder('/foo'); |
| 91 resourceProvider.newFolder('/bar'); |
| 92 File foo = resourceProvider.newFile('/foo/foo.dart', 'library lib;'); |
| 93 Source fooSource = foo.createSource(); |
| 94 File bar = resourceProvider.newFile('/bar/bar.dart', 'library lib;'); |
| 95 Source barSource = bar.createSource(); |
| 96 server.setAnalysisRoots('0', ['/foo', '/bar'], [], {}); |
| 97 AnalysisContext fooContext = server.getAnalysisContextForSource(fooSource); |
| 98 expect(fooContext, isNotNull); |
| 99 AnalysisContext barContext = server.getAnalysisContextForSource(barSource); |
| 100 expect(barContext, isNotNull); |
| 101 expect(fooContext, isNot(same(barContext))); |
| 102 return pumpEventQueue(40).then((_) { |
| 103 expect(server.statusAnalyzing, isFalse); |
| 104 // Make sure getAnalysisContext returned the proper context for each. |
| 105 expect(fooContext.getKindOf(fooSource), SourceKind.LIBRARY); |
| 106 expect(fooContext.getKindOf(barSource), SourceKind.UNKNOWN); |
| 107 expect(barContext.getKindOf(fooSource), SourceKind.UNKNOWN); |
| 108 expect(barContext.getKindOf(barSource), SourceKind.LIBRARY); |
| 109 }); |
| 110 } |
| 111 |
| 37 void setUp() { | 112 void setUp() { |
| 38 channel = new MockServerChannel(); | 113 channel = new MockServerChannel(); |
| 39 resourceProvider = new MemoryResourceProvider(); | 114 resourceProvider = new MemoryResourceProvider(); |
| 40 server = new AnalysisServer( | 115 server = new AnalysisServer( |
| 41 channel, | 116 channel, |
| 42 resourceProvider, | 117 resourceProvider, |
| 43 new MockPackageMapProvider(), | 118 new MockPackageMapProvider(), |
| 44 null, | 119 null, |
| 45 new AnalysisServerOptions(), | 120 new AnalysisServerOptions(), |
| 46 new MockSdk(), | 121 new MockSdk(), |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 176 |
| 102 Future test_echo() { | 177 Future test_echo() { |
| 103 server.handlers = [new EchoHandler()]; | 178 server.handlers = [new EchoHandler()]; |
| 104 var request = new Request('my22', 'echo'); | 179 var request = new Request('my22', 'echo'); |
| 105 return channel.sendRequest(request).then((Response response) { | 180 return channel.sendRequest(request).then((Response response) { |
| 106 expect(response.id, equals('my22')); | 181 expect(response.id, equals('my22')); |
| 107 expect(response.error, isNull); | 182 expect(response.error, isNull); |
| 108 }); | 183 }); |
| 109 } | 184 } |
| 110 | 185 |
| 186 Future test_getAnalysisContextForSource() { |
| 187 // Subscribe to STATUS so we'll know when analysis is done. |
| 188 server.serverServices = [ServerService.STATUS].toSet(); |
| 189 // Analyze project foo containing foo.dart and project bar containing |
| 190 // bar.dart. |
| 191 resourceProvider.newFolder('/foo'); |
| 192 resourceProvider.newFolder('/bar'); |
| 193 File foo = resourceProvider.newFile('/foo/foo.dart', 'library lib;'); |
| 194 Source fooSource = foo.createSource(); |
| 195 File bar = resourceProvider.newFile('/bar/bar.dart', 'library lib;'); |
| 196 Source barSource = bar.createSource(); |
| 197 server.setAnalysisRoots('0', ['/foo', '/bar'], [], {}); |
| 198 return pumpEventQueue(40).then((_) { |
| 199 expect(server.statusAnalyzing, isFalse); |
| 200 // Make sure getAnalysisContext returns the proper context for each. |
| 201 AnalysisContext fooContext = |
| 202 server.getAnalysisContextForSource(fooSource); |
| 203 expect(fooContext, isNotNull); |
| 204 AnalysisContext barContext = |
| 205 server.getAnalysisContextForSource(barSource); |
| 206 expect(barContext, isNotNull); |
| 207 expect(fooContext, isNot(same(barContext))); |
| 208 expect(fooContext.getKindOf(fooSource), SourceKind.LIBRARY); |
| 209 expect(fooContext.getKindOf(barSource), SourceKind.UNKNOWN); |
| 210 expect(barContext.getKindOf(fooSource), SourceKind.UNKNOWN); |
| 211 expect(barContext.getKindOf(barSource), SourceKind.LIBRARY); |
| 212 }); |
| 213 } |
| 214 |
| 111 Future test_prioritySourcesChangedEvent() { | 215 Future test_prioritySourcesChangedEvent() { |
| 112 resourceProvider.newFolder('/foo'); | 216 resourceProvider.newFolder('/foo'); |
| 113 | 217 |
| 114 int eventCount = 0; | 218 int eventCount = 0; |
| 115 Source firstSource = null; | 219 Source firstSource = null; |
| 116 server.onPriorityChange.listen((PriorityChangeEvent event) { | 220 server.onPriorityChange.listen((PriorityChangeEvent event) { |
| 117 ++eventCount; | 221 ++eventCount; |
| 118 firstSource = event.firstSource; | 222 firstSource = event.firstSource; |
| 119 }); | 223 }); |
| 120 | 224 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 @override | 319 @override |
| 216 Response handleRequest(Request request) { | 320 Response handleRequest(Request request) { |
| 217 if (request.method == 'echo') { | 321 if (request.method == 'echo') { |
| 218 return new Response(request.id, result: { | 322 return new Response(request.id, result: { |
| 219 'echo': true | 323 'echo': true |
| 220 }); | 324 }); |
| 221 } | 325 } |
| 222 return null; | 326 return null; |
| 223 } | 327 } |
| 224 } | 328 } |
| OLD | NEW |