Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Unified Diff: pkg/scheduled_test/lib/scheduled_test.dart

Issue 179993007: Make scheduled_test play nicer with plain unittest tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/scheduled_test/test/unittest_compatibility_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/scheduled_test/lib/scheduled_test.dart
diff --git a/pkg/scheduled_test/lib/scheduled_test.dart b/pkg/scheduled_test/lib/scheduled_test.dart
index 671305440ac3c20453318ceb189dbade4cc32b17..b6ba30d7e2d9513c6b8aabf8da510d93d0c750ed 100644
--- a/pkg/scheduled_test/lib/scheduled_test.dart
+++ b/pkg/scheduled_test/lib/scheduled_test.dart
@@ -228,7 +228,7 @@ void solo_test(String description, void body()) =>
_test(description, body, unittest.solo_test);
void _test(String description, void body(), Function testFn) {
- _ensureInitialized();
+ unittest.ensureInitialized();
_ensureSetUpForTopLevel();
testFn(description, () {
var completer = new Completer();
@@ -260,7 +260,7 @@ bool _inGroup = false;
/// Creates a new named group of tests. This has the same semantics as
/// [unittest.group].
void group(String description, void body()) {
- _ensureInitialized();
+ unittest.ensureInitialized();
_ensureSetUpForTopLevel();
unittest.group(description, () {
var wasInGroup = _inGroup;
@@ -316,11 +316,22 @@ void _ensureSetUpForTopLevel() {
void _setUpScheduledTest([void setUpFn()]) {
if (!_inGroup) {
_setUpForTopLevel = true;
+ var oldWrapAsync = unittest.wrapAsync;
unittest.setUp(() {
if (currentSchedule != null) {
throw new StateError('There seems to be another scheduled test '
'still running.');
}
+
+ unittest.wrapAsync = (f, [description]) {
+ // It's possible that this setup is run before a vanilla unittest test
+ // if [unittest.test] is run in the same context as
+ // [scheduled_test.test]. In that case, [currentSchedule] will never be
+ // set and we should forward to the [unittest.wrapAsync].
+ if (currentSchedule == null) return oldWrapAsync(f, description);
+ return currentSchedule.wrapAsync(f, description);
+ };
+
if (_setUpFn != null) {
var parentFn = _setUpFn;
_setUpFn = () { parentFn(); setUpFn(); };
@@ -330,6 +341,7 @@ void _setUpScheduledTest([void setUpFn()]) {
});
unittest.tearDown(() {
+ unittest.wrapAsync = oldWrapAsync;
_currentSchedule = null;
_setUpFn = null;
});
@@ -345,20 +357,6 @@ void _setUpScheduledTest([void setUpFn()]) {
}
}
-/// Ensures that the global configuration for `scheduled_test` has been
-/// initialized.
-void _ensureInitialized() {
- unittest.ensureInitialized();
- unittest.wrapAsync = (f, [description]) {
- if (currentSchedule == null) {
- throw new StateError("Unexpected call to wrapAsync with no current "
- "schedule.");
- }
-
- return currentSchedule.wrapAsync(f, description);
- };
-}
-
/// Like [wrapAsync], this ensures that the current task queue waits for
/// out-of-band asynchronous code, and that errors raised in that code are
/// handled correctly. However, [wrapFuture] wraps a [Future] chain rather than
« no previous file with comments | « no previous file | pkg/scheduled_test/test/unittest_compatibility_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698