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

Unified Diff: lib/unittest/shared.dart

Issue 10031022: step 1 in making unittest platform independent. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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
Index: lib/unittest/shared.dart
diff --git a/lib/unittest/shared.dart b/lib/unittest/shared.dart
index 56923021565821db5392d78b712f11406aecee19..cba8e2aa6fbecfffad03d0a47215167b4459d921 100644
--- a/lib/unittest/shared.dart
+++ b/lib/unittest/shared.dart
@@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+Configuration _config = null;
+
/**
* Description text of the current test group. If multiple groups are nested,
* this will contain all of their text concatenated.
@@ -17,9 +19,6 @@ List<TestCase> _tests;
*/
Function _testRunner;
-/** Whether this is run within dartium layout tests. */
-bool _isLayoutTest = false;
-
/** Current test being executed. */
int _currentTest = 0;
@@ -86,21 +85,6 @@ void asyncTest(String spec, int callbacks, TestFunction body) {
}
}
-void serialInvokeAsync(List closures) {
- final length = closures.length;
- if (length > 0) {
- int i = 0;
- void invokeNext() {
- closures[i]();
- i++;
- if (i < length) {
- window.setTimeout(invokeNext, 0);
- }
- }
- window.setTimeout(invokeNext, 0);
- }
-}
-
/**
* Creates a new named group of tests. Calls to group() or test() within the
* body of the function passed to this will inherit this group's description.
@@ -148,15 +132,24 @@ void callbackDone() {
}
}
-void forLayoutTests() {
- _isLayoutTest = true;
+/** Runs [callback] at the end of the event loop. */
+_defer(void callback()) {
+ // Exploit isolate ports as a platform-independent mechanism to queue a
+ // message at the end of the event loop.
+ // TODO(sigmund): expose this functionality somewhere in our libraries.
+ final port = new ReceivePort();
+ port.receive((msg, reply) {
+ callback();
+ port.close();
+ });
+ port.toSendPort().send(null, null);
}
/** Runs all queued tests, one at a time. */
_runTests() {
- _platformStartTests();
+ _config.onStart();
- _platformDefer(() {
+ _defer(() {
assert (_currentTest == 0);
_testRunner();
});
@@ -226,7 +219,7 @@ _completeTests() {
}
}
- _platformCompleteTests(testsPassed_, testsFailed_, testsErrors_);
+ _config.onDone(testsPassed_, testsFailed_, testsErrors_, _tests);
}
String _fullSpec(String spec) {
@@ -245,11 +238,14 @@ _ensureInitialized() {
_state = _READY;
_testRunner = _nextBatch;
- _platformInitialize();
+ if (_config == null) {
+ _config = _defaultConfig();
+ }
+ _config.onInit();
// Immediately queue the suite up. It will run after a timeout (i.e. after
// main() has returned).
- _platformDefer(_runTests);
+ _defer(_runTests);
}
/**

Powered by Google App Engine
This is Rietveld 408576698