| 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'; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 // Matchers for data types defined in the analysis server API | 142 // Matchers for data types defined in the analysis server API |
| 143 // ========================================================== | 143 // ========================================================== |
| 144 // TODO(paulberry): add more matchers. | 144 // TODO(paulberry): add more matchers. |
| 145 | 145 |
| 146 // Matchers common to all domains | 146 // Matchers common to all domains |
| 147 // ------------------------------ | 147 // ------------------------------ |
| 148 | 148 |
| 149 const Matcher isResultResponse = const MatchesJsonObject('result response', | 149 const Matcher isResponse = const MatchesJsonObject('response', |
| 150 const { | 150 const { |
| 151 'id': isString | 151 'id': isString |
| 152 }, optionalFields: const { | 152 }, optionalFields: const { |
| 153 'result': anything | 153 'result': anything, |
| 154 'error': isError |
| 154 }); | 155 }); |
| 155 | 156 |
| 156 const Matcher isError = const MatchesJsonObject('Error', const { | 157 const Matcher isError = const MatchesJsonObject('Error', const { |
| 157 // TODO(paulberry): once we decide what the set of permitted error codes are, | 158 // TODO(paulberry): once we decide what the set of permitted error codes are, |
| 158 // add validation for 'code'. | 159 // add validation for 'code'. |
| 159 'code': anything, | 160 'code': anything, |
| 160 'message': isString | 161 'message': isString |
| 161 }, optionalFields: const { | 162 }, optionalFields: const { |
| 162 // TODO(paulberry): API spec says that 'data' is required, but sometimes we | 163 // TODO(paulberry): API spec says that 'data' is required, but sometimes we |
| 163 // don't see it (example: error "Expected parameter subscriptions to be a | 164 // don't see it (example: error "Expected parameter subscriptions to be a |
| 164 // string list map" in response to a malformed "analysis.setSubscriptions" | 165 // string list map" in response to a malformed "analysis.setSubscriptions" |
| 165 // command). | 166 // command). |
| 166 'data': anything | 167 'data': anything |
| 167 }); | 168 }); |
| 168 | 169 |
| 169 const Matcher isErrorResponse = const MatchesJsonObject('error response', const | |
| 170 { | |
| 171 'id': isString, | |
| 172 'error': isError | |
| 173 }); | |
| 174 | |
| 175 const Matcher isNotification = const MatchesJsonObject('notification', const { | 170 const Matcher isNotification = const MatchesJsonObject('notification', const { |
| 176 'event': isString | 171 'event': isString |
| 177 }, optionalFields: const { | 172 }, optionalFields: const { |
| 178 'params': isMap | 173 'params': isMap |
| 179 }); | 174 }); |
| 180 | 175 |
| 181 // Matchers for specific responses and notifications | 176 // Matchers for specific responses and notifications |
| 182 // ------------------------------------------------- | 177 // ------------------------------------------------- |
| 183 | 178 |
| 184 // server.getVersion | 179 // server.getVersion |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 Completer completer = server._pendingCommands[id]; | 517 Completer completer = server._pendingCommands[id]; |
| 523 if (completer == null) { | 518 if (completer == null) { |
| 524 fail('Unexpected response from server: id=$id'); | 519 fail('Unexpected response from server: id=$id'); |
| 525 } else { | 520 } else { |
| 526 server._pendingCommands.remove(id); | 521 server._pendingCommands.remove(id); |
| 527 } | 522 } |
| 528 if (messageAsMap.containsKey('error')) { | 523 if (messageAsMap.containsKey('error')) { |
| 529 // TODO(paulberry): propagate the error info to the completer. | 524 // TODO(paulberry): propagate the error info to the completer. |
| 530 completer.completeError(new UnimplementedError( | 525 completer.completeError(new UnimplementedError( |
| 531 'Server responded with an error')); | 526 'Server responded with an error')); |
| 532 // Check that the message is well-formed. We do this after calling | |
| 533 // completer.completeError() so that we don't stall the test in the | |
| 534 // event of an error. | |
| 535 expect(message, isErrorResponse); | |
| 536 } else { | 527 } else { |
| 537 completer.complete(messageAsMap['result']); | 528 completer.complete(messageAsMap['result']); |
| 538 // Check that the message is well-formed. We do this after calling | |
| 539 // completer.complete() so that we don't stall the test in the | |
| 540 // event of an error. | |
| 541 expect(message, isResultResponse); | |
| 542 } | 529 } |
| 530 // Check that the message is well-formed. We do this after calling |
| 531 // completer.complete() or completer.completeError() so that we don't |
| 532 // stall the test in the event of an error. |
| 533 expect(message, isResponse); |
| 543 } else { | 534 } else { |
| 544 // Message is a notification. It should have an event and possibly | 535 // Message is a notification. It should have an event and possibly |
| 545 // params. | 536 // params. |
| 546 expect(messageAsMap, contains('event')); | 537 expect(messageAsMap, contains('event')); |
| 547 expect(messageAsMap['event'], isString); | 538 expect(messageAsMap['event'], isString); |
| 548 String event = messageAsMap['event']; | 539 String event = messageAsMap['event']; |
| 549 StreamController notificationController = | 540 StreamController notificationController = |
| 550 server._notificationControllers[event]; | 541 server._notificationControllers[event]; |
| 551 if (notificationController != null) { | 542 if (notificationController != null) { |
| 552 notificationController.add(messageAsMap['params']); | 543 notificationController.add(messageAsMap['params']); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 * Record a message that was exchanged with the server, and print it out if | 606 * Record a message that was exchanged with the server, and print it out if |
| 616 * [debugStdio] has been called. | 607 * [debugStdio] has been called. |
| 617 */ | 608 */ |
| 618 void _recordStdio(String line) { | 609 void _recordStdio(String line) { |
| 619 if (_debuggingStdio) { | 610 if (_debuggingStdio) { |
| 620 print(line); | 611 print(line); |
| 621 } | 612 } |
| 622 _recordedStdio.add(line); | 613 _recordedStdio.add(line); |
| 623 } | 614 } |
| 624 } | 615 } |
| OLD | NEW |