| 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; | 5 library test.runner; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:async/async.dart'; | 10 import 'package:async/async.dart'; |
| 11 | 11 |
| 12 import 'backend/test_platform.dart'; | 12 import 'backend/test_platform.dart'; |
| 13 import 'runner/application_exception.dart'; | 13 import 'runner/application_exception.dart'; |
| 14 import 'runner/configuration.dart'; | 14 import 'runner/configuration.dart'; |
| 15 import 'runner/engine.dart'; | 15 import 'runner/engine.dart'; |
| 16 import 'runner/load_exception.dart'; | 16 import 'runner/load_exception.dart'; |
| 17 import 'runner/load_suite.dart'; | 17 import 'runner/load_suite.dart'; |
| 18 import 'runner/loader.dart'; | 18 import 'runner/loader.dart'; |
| 19 import 'runner/reporter.dart'; | 19 import 'runner/reporter.dart'; |
| 20 import 'runner/reporter/compact.dart'; | 20 import 'runner/reporter/compact.dart'; |
| 21 import 'runner/reporter/expanded.dart'; | 21 import 'runner/reporter/expanded.dart'; |
| 22 import 'runner/runner_suite.dart'; | 22 import 'runner/runner_suite.dart'; |
| 23 import 'util/io.dart'; | 23 import 'util/io.dart'; |
| 24 import 'utils.dart'; | 24 import 'utils.dart'; |
| 25 | 25 |
| 26 /// The set of platforms for which debug flags are (currently) not supported. | |
| 27 final _debugUnsupportedPlatforms = new Set.from( | |
| 28 [TestPlatform.vm, TestPlatform.phantomJS]); | |
| 29 | |
| 30 /// A class that loads and runs tests based on a [Configuration]. | 26 /// A class that loads and runs tests based on a [Configuration]. |
| 31 /// | 27 /// |
| 32 /// This maintains a [Loader] and an [Engine] and passes test suites from one to | 28 /// This maintains a [Loader] and an [Engine] and passes test suites from one to |
| 33 /// the other, as well as printing out tests with a [CompactReporter] or an | 29 /// the other, as well as printing out tests with a [CompactReporter] or an |
| 34 /// [ExpandedReporter]. | 30 /// [ExpandedReporter]. |
| 35 class Runner { | 31 class Runner { |
| 36 /// The configuration for the runner. | 32 /// The configuration for the runner. |
| 37 final Configuration _config; | 33 final Configuration _config; |
| 38 | 34 |
| 39 /// The loader that loads the test suites from the filesystem. | 35 /// The loader that loads the test suites from the filesystem. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 if (_config.pattern == null) return suite; | 161 if (_config.pattern == null) return suite; |
| 166 return suite.change(tests: suite.tests.where((test) => | 162 return suite.change(tests: suite.tests.where((test) => |
| 167 test.name.contains(_config.pattern))); | 163 test.name.contains(_config.pattern))); |
| 168 }); | 164 }); |
| 169 }); | 165 }); |
| 170 } | 166 } |
| 171 | 167 |
| 172 /// Loads each suite in [suites] in order, pausing after load for platforms | 168 /// Loads each suite in [suites] in order, pausing after load for platforms |
| 173 /// that support debugging. | 169 /// that support debugging. |
| 174 Future<bool> _loadThenPause(Stream<LoadSuite> suites) async { | 170 Future<bool> _loadThenPause(Stream<LoadSuite> suites) async { |
| 175 var unsupportedPlatforms = _config.platforms | 171 if (_config.platforms.contains(TestPlatform.vm)) { |
| 176 .where(_debugUnsupportedPlatforms.contains) | 172 warn("Debugging is currently unsupported on the Dart VM.", |
| 177 .map((platform) => | |
| 178 platform == TestPlatform.vm ? "the Dart VM" : platform.name) | |
| 179 .toList(); | |
| 180 | |
| 181 if (unsupportedPlatforms.isNotEmpty) { | |
| 182 warn( | |
| 183 wordWrap("Debugging is currently unsupported on " | |
| 184 "${toSentence(unsupportedPlatforms)}."), | |
| 185 color: _config.color); | 173 color: _config.color); |
| 186 } | 174 } |
| 187 | 175 |
| 188 _suiteSubscription = suites.asyncMap((loadSuite) async { | 176 _suiteSubscription = suites.asyncMap((loadSuite) async { |
| 189 // Make the underlying suite null so that the engine doesn't start running | 177 // Make the underlying suite null so that the engine doesn't start running |
| 190 // it immediately. | 178 // it immediately. |
| 191 _engine.suiteSink.add(loadSuite.changeSuite((_) => null)); | 179 _engine.suiteSink.add(loadSuite.changeSuite((_) => null)); |
| 192 | 180 |
| 193 var suite = await loadSuite.suite; | 181 var suite = await loadSuite.suite; |
| 194 if (suite == null) return; | 182 if (suite == null) return; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 207 return results.last; | 195 return results.last; |
| 208 } | 196 } |
| 209 | 197 |
| 210 /// Pauses the engine and the reporter so that the user can set breakpoints as | 198 /// Pauses the engine and the reporter so that the user can set breakpoints as |
| 211 /// necessary. | 199 /// necessary. |
| 212 /// | 200 /// |
| 213 /// This is a no-op for test suites that aren't on platforms where debugging | 201 /// This is a no-op for test suites that aren't on platforms where debugging |
| 214 /// is supported. | 202 /// is supported. |
| 215 Future _pause(RunnerSuite suite) async { | 203 Future _pause(RunnerSuite suite) async { |
| 216 if (suite.platform == null) return; | 204 if (suite.platform == null) return; |
| 217 if (_debugUnsupportedPlatforms.contains(suite.platform)) return; | 205 if (suite.platform == TestPlatform.vm) return; |
| 218 | 206 |
| 219 try { | 207 try { |
| 220 _reporter.pause(); | 208 _reporter.pause(); |
| 221 | 209 |
| 222 var bold = _config.color ? '\u001b[1m' : ''; | 210 var bold = _config.color ? '\u001b[1m' : ''; |
| 223 var yellow = _config.color ? '\u001b[33m' : ''; | 211 var yellow = _config.color ? '\u001b[33m' : ''; |
| 224 var noColor = _config.color ? '\u001b[0m' : ''; | 212 var noColor = _config.color ? '\u001b[0m' : ''; |
| 225 print(''); | 213 print(''); |
| 226 | 214 |
| 227 if (suite.platform.isDartVM) { | 215 if (suite.platform.isDartVM) { |
| 228 var url = suite.environment.observatoryUrl; | 216 var url = suite.environment.observatoryUrl; |
| 229 if (url == null) { | 217 if (url == null) { |
| 230 print("${yellow}Observatory URL not found. Make sure you're using " | 218 print("${yellow}Observatory URL not found. Make sure you're using " |
| 231 "${suite.platform.name} 1.11 or later.$noColor"); | 219 "${suite.platform.name} 1.11 or later.$noColor"); |
| 232 } else { | 220 } else { |
| 233 print("Observatory URL: $bold$url$noColor"); | 221 print("Observatory URL: $bold$url$noColor"); |
| 234 } | 222 } |
| 235 } | 223 } |
| 236 | 224 |
| 237 if (suite.platform == TestPlatform.contentShell) { | 225 if (suite.platform.isHeadless) { |
| 238 var url = suite.environment.remoteDebuggerUrl; | 226 var url = suite.environment.remoteDebuggerUrl; |
| 239 if (url == null) { | 227 if (url == null) { |
| 240 print("${yellow}Remote debugger URL not found.$noColor"); | 228 print("${yellow}Remote debugger URL not found.$noColor"); |
| 241 } else { | 229 } else { |
| 242 print("Remote debugger URL: $bold$url$noColor"); | 230 print("Remote debugger URL: $bold$url$noColor"); |
| 243 } | 231 } |
| 244 } | 232 } |
| 245 | 233 |
| 246 var buffer = new StringBuffer( | 234 var buffer = new StringBuffer( |
| 247 "${bold}The test runner is paused.${noColor} "); | 235 "${bold}The test runner is paused.${noColor} "); |
| 248 if (!suite.platform.isHeadless) { | 236 if (!suite.platform.isHeadless) { |
| 249 buffer.write("Open the dev console in ${suite.platform} "); | 237 buffer.write("Open the dev console in ${suite.platform} "); |
| 250 if (suite.platform.isDartVM) buffer.write("or "); | |
| 251 } else { | 238 } else { |
| 252 buffer.write("Open "); | 239 buffer.write("Open the remote debugger "); |
| 253 if (suite.platform == TestPlatform.contentShell) { | |
| 254 buffer.write("the remote debugger or "); | |
| 255 } | |
| 256 } | 240 } |
| 257 if (suite.platform.isDartVM) buffer.write("the Observatory "); | 241 if (suite.platform.isDartVM) buffer.write("or the Observatory "); |
| 258 | 242 |
| 259 buffer.write("and set breakpoints. Once you're finished, return to this " | 243 buffer.write("and set breakpoints. Once you're finished, return to this " |
| 260 "terminal and press Enter."); | 244 "terminal and press Enter."); |
| 261 | 245 |
| 262 print(wordWrap(buffer.toString())); | 246 print(wordWrap(buffer.toString())); |
| 263 | 247 |
| 264 await inCompletionOrder([ | 248 await inCompletionOrder([ |
| 265 suite.environment.displayPause(), | 249 suite.environment.displayPause(), |
| 266 cancelableNext(stdinLines) | 250 cancelableNext(stdinLines) |
| 267 ]).first; | 251 ]).first; |
| 268 } finally { | 252 } finally { |
| 269 _reporter.resume(); | 253 _reporter.resume(); |
| 270 } | 254 } |
| 271 } | 255 } |
| 272 } | 256 } |
| OLD | NEW |