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 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:io'; | 6 import 'dart:io'; |
7 | 7 |
8 import 'package:async/async.dart'; | 8 import 'package:async/async.dart'; |
9 | 9 |
10 import 'backend/group.dart'; | 10 import 'backend/group.dart'; |
11 import 'backend/group_entry.dart'; | 11 import 'backend/group_entry.dart'; |
| 12 import 'backend/operating_system.dart'; |
| 13 import 'backend/platform_selector.dart'; |
12 import 'backend/suite.dart'; | 14 import 'backend/suite.dart'; |
13 import 'backend/test.dart'; | 15 import 'backend/test.dart'; |
14 import 'backend/test_platform.dart'; | 16 import 'backend/test_platform.dart'; |
15 import 'runner/application_exception.dart'; | 17 import 'runner/application_exception.dart'; |
16 import 'runner/configuration.dart'; | 18 import 'runner/configuration.dart'; |
17 import 'runner/debugger.dart'; | 19 import 'runner/debugger.dart'; |
18 import 'runner/engine.dart'; | 20 import 'runner/engine.dart'; |
19 import 'runner/load_exception.dart'; | 21 import 'runner/load_exception.dart'; |
20 import 'runner/load_suite.dart'; | 22 import 'runner/load_suite.dart'; |
21 import 'runner/loader.dart'; | 23 import 'runner/loader.dart'; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 100 |
99 /// Starts the runner. | 101 /// Starts the runner. |
100 /// | 102 /// |
101 /// This starts running tests and printing their progress. It returns whether | 103 /// This starts running tests and printing their progress. It returns whether |
102 /// or not they ran successfully. | 104 /// or not they ran successfully. |
103 Future<bool> run() async { | 105 Future<bool> run() async { |
104 if (_closed) { | 106 if (_closed) { |
105 throw new StateError("run() may not be called on a closed Runner."); | 107 throw new StateError("run() may not be called on a closed Runner."); |
106 } | 108 } |
107 | 109 |
| 110 _warnForUnsupportedPlatforms(); |
| 111 |
108 var suites = _loadSuites(); | 112 var suites = _loadSuites(); |
109 | 113 |
110 var success; | 114 var success; |
111 if (_config.pauseAfterLoad) { | 115 if (_config.pauseAfterLoad) { |
112 success = await _loadThenPause(suites); | 116 success = await _loadThenPause(suites); |
113 } else { | 117 } else { |
114 _suiteSubscription = suites.listen(_engine.suiteSink.add); | 118 _suiteSubscription = suites.listen(_engine.suiteSink.add); |
115 var results = await Future.wait([ | 119 var results = await Future.wait([ |
116 _suiteSubscription.asFuture().then((_) => _engine.suiteSink.close()), | 120 _suiteSubscription.asFuture().then((_) => _engine.suiteSink.close()), |
117 _engine.run() | 121 _engine.run() |
(...skipping 14 matching lines...) Expand all Loading... |
132 message += '"${_config.pattern}".'; | 136 message += '"${_config.pattern}".'; |
133 } | 137 } |
134 throw new ApplicationException(message); | 138 throw new ApplicationException(message); |
135 } | 139 } |
136 | 140 |
137 // Explicitly check "== true" here because [Engine.run] can return `null` | 141 // Explicitly check "== true" here because [Engine.run] can return `null` |
138 // if the engine was closed prematurely. | 142 // if the engine was closed prematurely. |
139 return success == true; | 143 return success == true; |
140 } | 144 } |
141 | 145 |
| 146 /// Emits a warning if the user is trying to run on a platform that's |
| 147 /// unsupported for the entire package. |
| 148 void _warnForUnsupportedPlatforms() { |
| 149 if (_config.testOn == PlatformSelector.all) return; |
| 150 |
| 151 var unsupportedPlatforms = _config.platforms.where((platform) { |
| 152 return !_config.testOn.evaluate(platform, os: currentOS); |
| 153 }).toList(); |
| 154 if (unsupportedPlatforms.isEmpty) return; |
| 155 |
| 156 // Human-readable names for all unsupported platforms. |
| 157 var unsupportedNames = []; |
| 158 |
| 159 // If the user tried to run on one or moe unsupported browsers, figure out |
| 160 // whether we should warn about the individual browsers or whether all |
| 161 // browsers are unsupported. |
| 162 var unsupportedBrowsers = unsupportedPlatforms |
| 163 .where((platform) => platform.isBrowser); |
| 164 if (unsupportedBrowsers.isNotEmpty) { |
| 165 var supportsAnyBrowser = TestPlatform.all |
| 166 .where((platform) => platform.isBrowser) |
| 167 .any((platform) => _config.testOn.evaluate(platform)); |
| 168 |
| 169 if (supportsAnyBrowser) { |
| 170 unsupportedNames.addAll( |
| 171 unsupportedBrowsers.map((platform) => platform.name)); |
| 172 } else { |
| 173 unsupportedNames.add("browsers"); |
| 174 } |
| 175 } |
| 176 |
| 177 // If the user tried to run on the VM and it's not supported, figure out if |
| 178 // that's because of the current OS or whether the VM is unsupported. |
| 179 if (unsupportedPlatforms.contains(TestPlatform.vm)) { |
| 180 var supportsAnyOS = OperatingSystem.all.any((os) => |
| 181 _config.testOn.evaluate(TestPlatform.vm, os: os)); |
| 182 |
| 183 if (supportsAnyOS) { |
| 184 unsupportedNames.add(currentOS.name); |
| 185 } else { |
| 186 unsupportedNames.add("the Dart VM"); |
| 187 } |
| 188 } |
| 189 |
| 190 warn("this package doesn't support running tests on " + |
| 191 toSentence(unsupportedNames, conjunction: "or") + "."); |
| 192 } |
| 193 |
142 /// Closes the runner. | 194 /// Closes the runner. |
143 /// | 195 /// |
144 /// This stops any future test suites from running. It will wait for any | 196 /// This stops any future test suites from running. It will wait for any |
145 /// currently-running VM tests, in case they have stuff to clean up on the | 197 /// currently-running VM tests, in case they have stuff to clean up on the |
146 /// filesystem. | 198 /// filesystem. |
147 Future close() => _closeMemo.runOnce(() async { | 199 Future close() => _closeMemo.runOnce(() async { |
148 var timer; | 200 var timer; |
149 if (!_engine.isIdle) { | 201 if (!_engine.isIdle) { |
150 // Wait a bit to print this message, since printing it eagerly looks weird | 202 // Wait a bit to print this message, since printing it eagerly looks weird |
151 // if the tests then finish immediately. | 203 // if the tests then finish immediately. |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 await _debugOperation.valueOrCancellation(); | 353 await _debugOperation.valueOrCancellation(); |
302 }).listen(null); | 354 }).listen(null); |
303 | 355 |
304 var results = await Future.wait([ | 356 var results = await Future.wait([ |
305 _suiteSubscription.asFuture().then((_) => _engine.suiteSink.close()), | 357 _suiteSubscription.asFuture().then((_) => _engine.suiteSink.close()), |
306 _engine.run() | 358 _engine.run() |
307 ]); | 359 ]); |
308 return results.last; | 360 return results.last; |
309 } | 361 } |
310 } | 362 } |
OLD | NEW |