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'; |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 if (new File(path).existsSync()) return _loader.loadFile(path); | 237 if (new File(path).existsSync()) return _loader.loadFile(path); |
238 | 238 |
239 return new Stream.fromIterable([ | 239 return new Stream.fromIterable([ |
240 new LoadSuite.forLoadException( | 240 new LoadSuite.forLoadException( |
241 new LoadException(path, 'Does not exist.')) | 241 new LoadException(path, 'Does not exist.')) |
242 ]); | 242 ]); |
243 })).map((loadSuite) { | 243 })).map((loadSuite) { |
244 return loadSuite.changeSuite((suite) { | 244 return loadSuite.changeSuite((suite) { |
245 _warnForUnknownTags(suite); | 245 _warnForUnknownTags(suite); |
246 | 246 |
247 return suite.filter((test) { | 247 return _shardSuite(suite.filter((test) { |
248 // Skip any tests that don't match all the given patterns. | 248 // Skip any tests that don't match all the given patterns. |
249 if (!_config.patterns.every(test.name.contains)) { | 249 if (!_config.patterns.every(test.name.contains)) { |
250 return false; | 250 return false; |
251 } | 251 } |
252 | 252 |
253 // If the user provided tags, skip tests that don't match all of them. | 253 // If the user provided tags, skip tests that don't match all of them. |
254 if (!_config.includeTags.evaluate(test.metadata.tags)) return false; | 254 if (!_config.includeTags.evaluate(test.metadata.tags)) return false; |
255 | 255 |
256 // Skip tests that do match any tags the user wants to exclude. | 256 // Skip tests that do match any tags the user wants to exclude. |
257 if (_config.excludeTags.evaluate(test.metadata.tags)) return false; | 257 if (_config.excludeTags.evaluate(test.metadata.tags)) return false; |
258 | 258 |
259 return true; | 259 return true; |
260 }); | 260 })); |
261 }); | 261 }); |
262 }); | 262 }); |
263 } | 263 } |
264 | 264 |
265 /// Prints a warning for any unknown tags referenced in [suite] or its | 265 /// Prints a warning for any unknown tags referenced in [suite] or its |
266 /// children. | 266 /// children. |
267 void _warnForUnknownTags(Suite suite) { | 267 void _warnForUnknownTags(Suite suite) { |
268 if (_tagWarningSuites.contains(suite.path)) return; | 268 if (_tagWarningSuites.contains(suite.path)) return; |
269 _tagWarningSuites.add(suite.path); | 269 _tagWarningSuites.add(suite.path); |
270 | 270 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 return unknownTags; | 330 return unknownTags; |
331 } | 331 } |
332 | 332 |
333 /// Returns a human-readable description of [entry], including its type. | 333 /// Returns a human-readable description of [entry], including its type. |
334 String _entryDescription(GroupEntry entry) { | 334 String _entryDescription(GroupEntry entry) { |
335 if (entry is Test) return 'the test "${entry.name}"'; | 335 if (entry is Test) return 'the test "${entry.name}"'; |
336 if (entry.name != null) return 'the group "${entry.name}"'; | 336 if (entry.name != null) return 'the group "${entry.name}"'; |
337 return 'the suite itself'; | 337 return 'the suite itself'; |
338 } | 338 } |
339 | 339 |
| 340 /// If sharding is enabled, filters [suite] to only include the tests that |
| 341 /// should be run in this shard. |
| 342 /// |
| 343 /// We just take a slice of the tests in each suite corresponding to the shard |
| 344 /// index. This makes the tests pretty tests across shards, and since the |
| 345 /// tests are continuous, makes us more likely to be able to re-use |
| 346 /// `setUpAll()` logic. |
| 347 Suite _shardSuite(Suite suite) { |
| 348 if (_config.totalShards == null) return suite; |
| 349 |
| 350 var shardSize = suite.group.testCount / _config.totalShards; |
| 351 var shardStart = (shardSize * _config.shardIndex).round(); |
| 352 var shardEnd = (shardSize * (_config.shardIndex + 1)).round(); |
| 353 |
| 354 var count = -1; |
| 355 var filtered = suite.filter((test) { |
| 356 count++; |
| 357 return count >= shardStart && count < shardEnd; |
| 358 }); |
| 359 |
| 360 return filtered; |
| 361 } |
| 362 |
340 /// Loads each suite in [suites] in order, pausing after load for platforms | 363 /// Loads each suite in [suites] in order, pausing after load for platforms |
341 /// that support debugging. | 364 /// that support debugging. |
342 Future<bool> _loadThenPause(Stream<LoadSuite> suites) async { | 365 Future<bool> _loadThenPause(Stream<LoadSuite> suites) async { |
343 if (_config.platforms.contains(TestPlatform.vm)) { | 366 if (_config.platforms.contains(TestPlatform.vm)) { |
344 warn("Debugging is currently unsupported on the Dart VM.", | 367 warn("Debugging is currently unsupported on the Dart VM.", |
345 color: _config.color); | 368 color: _config.color); |
346 } | 369 } |
347 | 370 |
348 _suiteSubscription = suites.asyncMap((loadSuite) async { | 371 _suiteSubscription = suites.asyncMap((loadSuite) async { |
349 _debugOperation = debug(_config, _engine, _reporter, loadSuite); | 372 _debugOperation = debug(_config, _engine, _reporter, loadSuite); |
350 await _debugOperation.valueOrCancellation(); | 373 await _debugOperation.valueOrCancellation(); |
351 }).listen(null); | 374 }).listen(null); |
352 | 375 |
353 var results = await Future.wait([ | 376 var results = await Future.wait([ |
354 _suiteSubscription.asFuture().then((_) => _engine.suiteSink.close()), | 377 _suiteSubscription.asFuture().then((_) => _engine.suiteSink.close()), |
355 _engine.run() | 378 _engine.run() |
356 ]); | 379 ]); |
357 return results.last; | 380 return results.last; |
358 } | 381 } |
359 } | 382 } |
OLD | NEW |