OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 'package:stream_channel/stream_channel.dart'; | 5 import 'package:stream_channel/stream_channel.dart'; |
6 | 6 |
7 import '../backend/group.dart'; | 7 import '../backend/group.dart'; |
8 import '../backend/live_test.dart'; | 8 import '../backend/live_test.dart'; |
9 import '../backend/live_test_controller.dart'; | 9 import '../backend/live_test_controller.dart'; |
10 import '../backend/metadata.dart'; | 10 import '../backend/metadata.dart'; |
11 import '../backend/operating_system.dart'; | 11 import '../backend/operating_system.dart'; |
12 import '../backend/state.dart'; | 12 import '../backend/state.dart'; |
13 import '../backend/suite.dart'; | 13 import '../backend/suite.dart'; |
14 import '../backend/test.dart'; | 14 import '../backend/test.dart'; |
15 import '../backend/test_platform.dart'; | 15 import '../backend/test_platform.dart'; |
16 import '../utils.dart'; | 16 import '../utils.dart'; |
17 import '../util/remote_exception.dart'; | 17 import '../util/remote_exception.dart'; |
18 | 18 |
| 19 typedef StackTrace _MapTrace(StackTrace trace); |
| 20 |
19 /// A test running remotely, controlled by a stream channel. | 21 /// A test running remotely, controlled by a stream channel. |
20 class RunnerTest extends Test { | 22 class RunnerTest extends Test { |
21 final String name; | 23 final String name; |
22 final Metadata metadata; | 24 final Metadata metadata; |
23 | 25 |
24 /// The channel used to communicate with the test's [IframeListener]. | 26 /// The channel used to communicate with the test's [IframeListener]. |
25 final MultiChannel _channel; | 27 final MultiChannel _channel; |
26 | 28 |
27 RunnerTest(this.name, this.metadata, this._channel); | 29 /// The function used to reformat errors' stack traces. |
| 30 final _MapTrace _mapTrace; |
| 31 |
| 32 RunnerTest(this.name, this.metadata, this._channel, this._mapTrace); |
28 | 33 |
29 LiveTest load(Suite suite, {Iterable<Group> groups}) { | 34 LiveTest load(Suite suite, {Iterable<Group> groups}) { |
30 var controller; | 35 var controller; |
31 var testChannel; | 36 var testChannel; |
32 controller = new LiveTestController(suite, this, () { | 37 controller = new LiveTestController(suite, this, () { |
33 controller.setState(const State(Status.running, Result.success)); | 38 controller.setState(const State(Status.running, Result.success)); |
34 | 39 |
35 testChannel = _channel.virtualChannel(); | 40 testChannel = _channel.virtualChannel(); |
36 _channel.sink.add({ | 41 _channel.sink.add({ |
37 'command': 'run', | 42 'command': 'run', |
38 'channel': testChannel.id | 43 'channel': testChannel.id |
39 }); | 44 }); |
40 | 45 |
41 testChannel.stream.listen((message) { | 46 testChannel.stream.listen((message) { |
42 if (message['type'] == 'error') { | 47 if (message['type'] == 'error') { |
43 var asyncError = RemoteException.deserialize(message['error']); | 48 var asyncError = RemoteException.deserialize(message['error']); |
44 | 49 |
45 var stackTrace = asyncError.stackTrace; | 50 var stackTrace = _mapTrace(asyncError.stackTrace); |
46 controller.addError(asyncError.error, stackTrace); | 51 controller.addError(asyncError.error, stackTrace); |
47 } else if (message['type'] == 'state-change') { | 52 } else if (message['type'] == 'state-change') { |
48 controller.setState( | 53 controller.setState( |
49 new State( | 54 new State( |
50 new Status.parse(message['status']), | 55 new Status.parse(message['status']), |
51 new Result.parse(message['result']))); | 56 new Result.parse(message['result']))); |
52 } else if (message['type'] == 'print') { | 57 } else if (message['type'] == 'print') { |
53 controller.print(message['line']); | 58 controller.print(message['line']); |
54 } else { | 59 } else { |
55 assert(message['type'] == 'complete'); | 60 assert(message['type'] == 'complete'); |
(...skipping 20 matching lines...) Expand all Loading... |
76 await controller.completer.future; | 81 await controller.completer.future; |
77 testChannel.sink.close(); | 82 testChannel.sink.close(); |
78 }); | 83 }); |
79 }, groups: groups); | 84 }, groups: groups); |
80 return controller.liveTest; | 85 return controller.liveTest; |
81 } | 86 } |
82 | 87 |
83 Test forPlatform(TestPlatform platform, {OperatingSystem os}) { | 88 Test forPlatform(TestPlatform platform, {OperatingSystem os}) { |
84 if (!metadata.testOn.evaluate(platform, os: os)) return null; | 89 if (!metadata.testOn.evaluate(platform, os: os)) return null; |
85 return new RunnerTest( | 90 return new RunnerTest( |
86 name, metadata.forPlatform(platform, os: os), _channel); | 91 name, metadata.forPlatform(platform, os: os), _channel, _mapTrace); |
87 } | 92 } |
88 } | 93 } |
OLD | NEW |