| 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 library test.runner.vm.isolate_listener; | 5 library test.runner.vm.isolate_listener; |
| 6 | 6 |
| 7 import 'dart:isolate'; | 7 import 'dart:isolate'; |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 | 9 |
| 10 import 'package:stack_trace/stack_trace.dart'; | 10 import 'package:stack_trace/stack_trace.dart'; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 "root": _serializeGroup(_suite.group) | 110 "root": _serializeGroup(_suite.group) |
| 111 }); | 111 }); |
| 112 } | 112 } |
| 113 | 113 |
| 114 /// Serializes [group] into an Isolate-safe map. | 114 /// Serializes [group] into an Isolate-safe map. |
| 115 Map _serializeGroup(Group group) { | 115 Map _serializeGroup(Group group) { |
| 116 return { | 116 return { |
| 117 "type": "group", | 117 "type": "group", |
| 118 "name": group.name, | 118 "name": group.name, |
| 119 "metadata": group.metadata.serialize(), | 119 "metadata": group.metadata.serialize(), |
| 120 "setUpAll": _serializeTest(group.setUpAll), |
| 121 "tearDownAll": _serializeTest(group.tearDownAll), |
| 120 "entries": group.entries.map((entry) { | 122 "entries": group.entries.map((entry) { |
| 121 if (entry is Group) return _serializeGroup(entry); | 123 return entry is Group ? _serializeGroup(entry) : _serializeTest(entry); |
| 124 }).toList() |
| 125 }; |
| 126 } |
| 122 | 127 |
| 123 var test = entry as Test; | 128 /// Serializes [test] into a JSON-safe map. |
| 124 var receivePort = new ReceivePort(); | 129 /// |
| 125 receivePort.listen((message) { | 130 /// Returns `null` if [test] is `null`. |
| 126 assert(message['command'] == 'run'); | 131 Map _serializeTest(Test test) { |
| 127 _runTest(test, message['reply']); | 132 if (test == null) return null; |
| 128 }); | |
| 129 | 133 |
| 130 return { | 134 var receivePort = new ReceivePort(); |
| 131 "type": "test", | 135 receivePort.listen((message) { |
| 132 "name": test.name, | 136 assert(message['command'] == 'run'); |
| 133 "metadata": test.metadata.serialize(), | 137 _runTest(test, message['reply']); |
| 134 "sendPort": receivePort.sendPort | 138 }); |
| 135 }; | 139 |
| 136 }).toList() | 140 return { |
| 141 "type": "test", |
| 142 "name": test.name, |
| 143 "metadata": test.metadata.serialize(), |
| 144 "sendPort": receivePort.sendPort |
| 137 }; | 145 }; |
| 138 } | 146 } |
| 139 | 147 |
| 140 /// Runs [test] and sends the results across [sendPort]. | 148 /// Runs [test] and sends the results across [sendPort]. |
| 141 void _runTest(Test test, SendPort sendPort) { | 149 void _runTest(Test test, SendPort sendPort) { |
| 142 var liveTest = test.load(_suite); | 150 var liveTest = test.load(_suite); |
| 143 | 151 |
| 144 var receivePort = new ReceivePort(); | 152 var receivePort = new ReceivePort(); |
| 145 sendPort.send({"type": "started", "reply": receivePort.sendPort}); | 153 sendPort.send({"type": "started", "reply": receivePort.sendPort}); |
| 146 | 154 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 165 asyncError.error, asyncError.stackTrace) | 173 asyncError.error, asyncError.stackTrace) |
| 166 }); | 174 }); |
| 167 }); | 175 }); |
| 168 | 176 |
| 169 liveTest.onPrint.listen((line) => | 177 liveTest.onPrint.listen((line) => |
| 170 sendPort.send({"type": "print", "line": line})); | 178 sendPort.send({"type": "print", "line": line})); |
| 171 | 179 |
| 172 liveTest.run().then((_) => sendPort.send({"type": "complete"})); | 180 liveTest.run().then((_) => sendPort.send({"type": "complete"})); |
| 173 } | 181 } |
| 174 } | 182 } |
| OLD | NEW |