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.integration.analysis; | 5 library test.integration.analysis; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 import 'dart:convert'; | 9 import 'dart:convert'; |
10 import 'dart:io'; | 10 import 'dart:io'; |
11 | 11 |
12 import 'package:analysis_server/src/constants.dart'; | 12 import 'package:analysis_server/src/constants.dart'; |
13 import 'package:analysis_server/src/protocol.dart'; | 13 import 'package:analysis_server/src/protocol.dart'; |
14 import 'package:path/path.dart'; | 14 import 'package:path/path.dart'; |
15 import 'package:unittest/unittest.dart'; | 15 import 'package:unittest/unittest.dart'; |
16 | 16 |
17 import 'integration_test_methods.dart'; | 17 import 'integration_test_methods.dart'; |
18 import 'protocol_matchers.dart'; | 18 import 'protocol_matchers.dart'; |
19 | 19 |
20 const Matcher isBool = const isInstanceOf<bool>('bool'); | 20 const Matcher isBool = const isInstanceOf<bool>('bool'); |
21 | 21 |
22 const Matcher isInt = const isInstanceOf<int>('int'); | 22 const Matcher isInt = const isInstanceOf<int>('int'); |
23 | 23 |
24 const Matcher isNotification = const MatchesJsonObject('notification', const { | 24 const Matcher isNotification = const MatchesJsonObject( |
25 'event': isString | 25 'notification', const {'event': isString}, |
26 }, optionalFields: const {'params': isMap}); | 26 optionalFields: const {'params': isMap}); |
27 | 27 |
28 const Matcher isObject = isMap; | 28 const Matcher isObject = isMap; |
29 | 29 |
30 final Matcher isResponse = new MatchesJsonObject('response', {'id': isString}, | 30 final Matcher isResponse = new MatchesJsonObject('response', {'id': isString}, |
31 optionalFields: {'result': anything, 'error': isRequestError}); | 31 optionalFields: {'result': anything, 'error': isRequestError}); |
32 | 32 |
33 const Matcher isString = const isInstanceOf<String>('String'); | 33 const Matcher isString = const isInstanceOf<String>('String'); |
34 | 34 |
35 Matcher isListOf(Matcher elementMatcher) => new _ListOf(elementMatcher); | 35 Matcher isListOf(Matcher elementMatcher) => new _ListOf(elementMatcher); |
36 | 36 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 }); | 147 }); |
148 Completer serverConnected = new Completer(); | 148 Completer serverConnected = new Completer(); |
149 onServerConnected.listen((_) { | 149 onServerConnected.listen((_) { |
150 expect(serverConnected.isCompleted, isFalse); | 150 expect(serverConnected.isCompleted, isFalse); |
151 serverConnected.complete(); | 151 serverConnected.complete(); |
152 }); | 152 }); |
153 onServerError.listen((ServerErrorParams params) { | 153 onServerError.listen((ServerErrorParams params) { |
154 // A server error should never happen during an integration test. | 154 // A server error should never happen during an integration test. |
155 fail('${params.message}\n${params.stackTrace}'); | 155 fail('${params.message}\n${params.stackTrace}'); |
156 }); | 156 }); |
157 return server.start().then((_) { | 157 return startServer().then((_) { |
158 server.listenToOutput(dispatchNotification); | 158 server.listenToOutput(dispatchNotification); |
159 server.exitCode.then((_) { | 159 server.exitCode.then((_) { |
160 skipShutdown = true; | 160 skipShutdown = true; |
161 }); | 161 }); |
162 return serverConnected.future; | 162 return serverConnected.future; |
163 }); | 163 }); |
164 } | 164 } |
165 | 165 |
166 /** | 166 /** |
167 * Convert the given [relativePath] to an absolute path, by interpreting it | 167 * Convert the given [relativePath] to an absolute path, by interpreting it |
(...skipping 13 matching lines...) Expand all Loading... |
181 Future standardAnalysisSetup({bool subscribeStatus: true}) { | 181 Future standardAnalysisSetup({bool subscribeStatus: true}) { |
182 List<Future> futures = <Future>[]; | 182 List<Future> futures = <Future>[]; |
183 if (subscribeStatus) { | 183 if (subscribeStatus) { |
184 futures.add(sendServerSetSubscriptions([ServerService.STATUS])); | 184 futures.add(sendServerSetSubscriptions([ServerService.STATUS])); |
185 } | 185 } |
186 futures.add(sendAnalysisSetAnalysisRoots([sourceDirectory.path], [])); | 186 futures.add(sendAnalysisSetAnalysisRoots([sourceDirectory.path], [])); |
187 return Future.wait(futures); | 187 return Future.wait(futures); |
188 } | 188 } |
189 | 189 |
190 /** | 190 /** |
| 191 * Start [server]. |
| 192 */ |
| 193 Future startServer() => server.start(); |
| 194 |
| 195 /** |
191 * After every test, the server is stopped and [sourceDirectory] is deleted. | 196 * After every test, the server is stopped and [sourceDirectory] is deleted. |
192 */ | 197 */ |
193 Future tearDown() { | 198 Future tearDown() { |
194 return _shutdownIfNeeded().then((_) { | 199 return _shutdownIfNeeded().then((_) { |
195 sourceDirectory.deleteSync(recursive: true); | 200 sourceDirectory.deleteSync(recursive: true); |
196 }); | 201 }); |
197 } | 202 } |
198 | 203 |
199 /** | 204 /** |
200 * Write a source file with the given absolute [pathname] and [contents]. | 205 * Write a source file with the given absolute [pathname] and [contents]. |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 _process.stdin.add(UTF8.encoder.convert("${line}\n")); | 582 _process.stdin.add(UTF8.encoder.convert("${line}\n")); |
578 return completer.future; | 583 return completer.future; |
579 } | 584 } |
580 | 585 |
581 /** | 586 /** |
582 * Start the server. If [debugServer] is `true`, the server will be started | 587 * Start the server. If [debugServer] is `true`, the server will be started |
583 * with "--debug", allowing a debugger to be attached. If [profileServer] is | 588 * with "--debug", allowing a debugger to be attached. If [profileServer] is |
584 * `true`, the server will be started with "--observe" and | 589 * `true`, the server will be started with "--observe" and |
585 * "--pause-isolates-on-exit", allowing the observatory to be used. | 590 * "--pause-isolates-on-exit", allowing the observatory to be used. |
586 */ | 591 */ |
587 Future start({bool debugServer: false, int diagnosticPort, bool profileServer:
false}) { | 592 Future start({bool debugServer: false, int diagnosticPort, |
| 593 bool profileServer: false, bool useAnalysisHighlight2: false}) { |
588 if (_process != null) { | 594 if (_process != null) { |
589 throw new Exception('Process already started'); | 595 throw new Exception('Process already started'); |
590 } | 596 } |
591 _time.start(); | 597 _time.start(); |
592 String dartBinary = Platform.executable; | 598 String dartBinary = Platform.executable; |
593 String rootDir = | 599 String rootDir = |
594 findRoot(Platform.script.toFilePath(windows: Platform.isWindows)); | 600 findRoot(Platform.script.toFilePath(windows: Platform.isWindows)); |
595 String serverPath = normalize(join(rootDir, 'bin', 'server.dart')); | 601 String serverPath = normalize(join(rootDir, 'bin', 'server.dart')); |
596 List<String> arguments = []; | 602 List<String> arguments = []; |
597 if (debugServer) { | 603 if (debugServer) { |
598 arguments.add('--debug'); | 604 arguments.add('--debug'); |
599 } | 605 } |
600 if (profileServer) { | 606 if (profileServer) { |
601 arguments.add('--observe'); | 607 arguments.add('--observe'); |
602 arguments.add('--pause-isolates-on-exit'); | 608 arguments.add('--pause-isolates-on-exit'); |
603 } | 609 } |
604 if (Platform.packageRoot.isNotEmpty) { | 610 if (Platform.packageRoot.isNotEmpty) { |
605 arguments.add('--package-root=${Platform.packageRoot}'); | 611 arguments.add('--package-root=${Platform.packageRoot}'); |
606 } | 612 } |
607 arguments.add('--checked'); | 613 arguments.add('--checked'); |
608 arguments.add(serverPath); | 614 arguments.add(serverPath); |
609 if (diagnosticPort != null) { | 615 if (diagnosticPort != null) { |
610 arguments.add('--port'); | 616 arguments.add('--port'); |
611 arguments.add(diagnosticPort.toString()); | 617 arguments.add(diagnosticPort.toString()); |
612 } | 618 } |
| 619 if (useAnalysisHighlight2) { |
| 620 arguments.add('--useAnalysisHighlight2'); |
| 621 } |
613 return Process.start(dartBinary, arguments).then((Process process) { | 622 return Process.start(dartBinary, arguments).then((Process process) { |
614 _process = process; | 623 _process = process; |
615 process.exitCode.then((int code) { | 624 process.exitCode.then((int code) { |
616 _recordStdio('TERMINATED WITH EXIT CODE $code'); | 625 _recordStdio('TERMINATED WITH EXIT CODE $code'); |
617 if (code != 0) { | 626 if (code != 0) { |
618 _badDataFromServer(); | 627 _badDataFromServer(); |
619 } | 628 } |
620 }); | 629 }); |
621 }); | 630 }); |
622 } | 631 } |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 void populateMismatches(item, List<MismatchDescriber> mismatches); | 869 void populateMismatches(item, List<MismatchDescriber> mismatches); |
861 | 870 |
862 /** | 871 /** |
863 * Create a [MismatchDescriber] describing a mismatch with a simple string. | 872 * Create a [MismatchDescriber] describing a mismatch with a simple string. |
864 */ | 873 */ |
865 MismatchDescriber simpleDescription(String description) => | 874 MismatchDescriber simpleDescription(String description) => |
866 (Description mismatchDescription) { | 875 (Description mismatchDescription) { |
867 mismatchDescription.add(description); | 876 mismatchDescription.add(description); |
868 }; | 877 }; |
869 } | 878 } |
OLD | NEW |