Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 unittest; | 5 library unittest; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:isolate'; | |
| 10 | 9 |
| 11 import 'package:matcher/matcher.dart' | 10 import 'src/configuration.dart'; |
| 12 show | 11 import 'src/expect.dart'; |
| 13 DefaultFailureHandler, | |
| 14 configureExpectFailureHandler, | |
| 15 TestFailure, | |
| 16 wrapAsync; | |
| 17 export 'package:matcher/matcher.dart'; | |
| 18 | |
| 19 import 'src/utils.dart'; | 12 import 'src/utils.dart'; |
| 20 | 13 |
| 21 import 'src/configuration.dart'; | 14 export 'package:matcher/matcher.dart' |
| 15 hide | |
| 16 completes, | |
| 17 completion, | |
| 18 ErrorFormatter, | |
| 19 expect, | |
| 20 fail, | |
| 21 prints, | |
| 22 TestFailure, | |
| 23 Throws, | |
| 24 throws, | |
| 25 throwsA, | |
| 26 throwsArgumentError, | |
| 27 throwsConcurrentModificationError, | |
| 28 throwsCyclicInitializationError, | |
| 29 throwsException, | |
| 30 throwsFormatException, | |
| 31 throwsNoSuchMethodError, | |
| 32 throwsNullThrownError, | |
| 33 throwsRangeError, | |
| 34 throwsStateError, | |
| 35 throwsUnimplementedError, | |
| 36 throwsUnsupportedError; | |
| 37 | |
| 22 export 'src/configuration.dart'; | 38 export 'src/configuration.dart'; |
| 39 export 'src/expect.dart'; | |
| 40 export 'src/simple_configuration.dart'; | |
| 41 export 'src/future_matchers.dart'; | |
| 42 export 'src/prints_matcher.dart'; | |
| 43 export 'src/throws_matcher.dart'; | |
| 44 export 'src/throws_matchers.dart'; | |
| 23 | 45 |
| 24 part 'src/simple_configuration.dart'; | |
| 25 part 'src/group_context.dart'; | 46 part 'src/group_context.dart'; |
| 26 part 'src/spread_args_helper.dart'; | 47 part 'src/spread_args_helper.dart'; |
| 27 part 'src/test_case.dart'; | 48 part 'src/test_case.dart'; |
| 28 part 'src/test_environment.dart'; | 49 part 'src/test_environment.dart'; |
| 29 | 50 |
| 30 const Symbol _UNITTEST_ENVIRONMENT = #unittest.environment; | 51 const Symbol _UNITTEST_ENVIRONMENT = #unittest.environment; |
| 31 | 52 |
| 32 final _TestEnvironment _defaultEnvironment = new _TestEnvironment(); | 53 final _TestEnvironment _defaultEnvironment = new _TestEnvironment(); |
| 33 | 54 |
| 34 /** | 55 /** |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 /// Lazily initializes the test library if not already initialized. | 424 /// Lazily initializes the test library if not already initialized. |
| 404 void ensureInitialized() { | 425 void ensureInitialized() { |
| 405 _ensureInitialized(true); | 426 _ensureInitialized(true); |
| 406 } | 427 } |
| 407 | 428 |
| 408 void _ensureInitialized(bool configAutoStart) { | 429 void _ensureInitialized(bool configAutoStart) { |
| 409 if (_environment.initialized) { | 430 if (_environment.initialized) { |
| 410 return; | 431 return; |
| 411 } | 432 } |
| 412 _environment.initialized = true; | 433 _environment.initialized = true; |
| 413 // Hook our async guard into the matcher library. | |
| 414 wrapAsync = (f, [id]) => expectAsync(f, id: id); | |
| 415 | 434 |
| 416 _environment.uncaughtErrorMessage = null; | 435 _environment.uncaughtErrorMessage = null; |
| 417 | 436 |
| 418 unittestConfiguration.onInit(); | 437 unittestConfiguration.onInit(); |
| 419 | 438 |
| 420 if (configAutoStart && _config.autoStart) { | 439 if (configAutoStart && _config.autoStart) { |
| 421 // Immediately queue the suite up. It will run after a timeout (i.e. after | 440 // Immediately queue the suite up. It will run after a timeout (i.e. after |
| 422 // main() has returned). | 441 // main() has returned). |
| 423 scheduleMicrotask(runTests); | 442 scheduleMicrotask(runTests); |
| 424 } | 443 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 /// | 492 /// |
| 474 /// This allows for multiple invocations of the unittest library in the same | 493 /// This allows for multiple invocations of the unittest library in the same |
| 475 /// application instance. | 494 /// application instance. |
| 476 /// This is useful when, for example, creating a test runner application which | 495 /// This is useful when, for example, creating a test runner application which |
| 477 /// needs to create a new pristine test environment on each invocation to run | 496 /// needs to create a new pristine test environment on each invocation to run |
| 478 /// a given set of test. | 497 /// a given set of test. |
| 479 dynamic withTestEnvironment(callback()) { | 498 dynamic withTestEnvironment(callback()) { |
| 480 return runZoned(callback, | 499 return runZoned(callback, |
| 481 zoneValues: {_UNITTEST_ENVIRONMENT: new _TestEnvironment()}); | 500 zoneValues: {_UNITTEST_ENVIRONMENT: new _TestEnvironment()}); |
| 482 } | 501 } |
| 502 | |
| 503 /// This Function is used by certain Matchers to catch certain exceptions. | |
|
nweiz
2015/01/26 22:44:10
"Function" -> "function"
kevmoo
2015/01/27 00:11:30
Done.
| |
| 504 /// | |
| 505 /// Some matchers, like those for Futures and exception testing, | |
| 506 /// can fail in asynchronous sections, and throw exceptions. | |
| 507 /// A user of this library will typically want to catch and handle | |
| 508 /// such exceptions. The [wrapAsync] property is a function that | |
| 509 /// can wrap callbacks used by these Matchers so that they can be | |
| 510 /// used safely. For example, the unittest library will set this | |
| 511 /// to be `expectAsync`. By default this is an identity function. | |
| 512 Function wrapAsync = (Function f, [id]) => f; | |
|
nweiz
2015/01/26 22:44:10
Since this is now defined in unittest, why doesn't
kevmoo
2015/01/27 00:11:30
Done.
| |
| OLD | NEW |