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

Unified Diff: tests/lib/unittest/unittest_test.dart

Issue 10584045: Unit tests for the unit test library. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/unittest/unittest_test.dart
===================================================================
--- tests/lib/unittest/unittest_test.dart (revision 0)
+++ tests/lib/unittest/unittest_test.dart (revision 0)
@@ -0,0 +1,159 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// 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.
+
+#library('unittestTest');
+#import('dart:isolate');
+#import('../../../lib/unittest/unittest.dart');
+
+var tests;
+var expected;
+var actual;
+var _testconfig;
+
+_defer(void fn()) {
+ // Exploit isolate ports as a platform-independent mechanism to queue a
+ // message at the end of the event loop. Stolen from unittest.dart.
+ final port = new ReceivePort();
+ port.receive((msg, reply) {
+ fn();
+ port.close();
+ });
+ port.toSendPort().send(null, null);
+}
+
+class TestConfiguration extends Configuration {
+ int x = 0;
+ String setup = '';
+ String teardown = '';
+ SendPort _port;
+
+ TestConfiguration(this._port);
+
+ void onDone(int passed, int failed, int errors, List<TestCase> results,
+ String uncaughtError) {
+ var result = '$passed:$failed:$errors:${results.length}:${x}:'
+ '${setup}:${teardown}:$uncaughtError';
eub 2012/06/21 00:09:42 $uncaughtError unused here?
gram 2012/06/21 16:48:16 Currently, as I did not find anything that trigger
+ for (var i = 0; i < results.length; i++) {
+ result = '$result:${results[i].description}:'
+ '${collapseWhitespace(results[i].message)}';
+ }
+ _port.send(result);
+ }
+}
+
+callback() {
eub 2012/06/21 00:09:42 I'm missing where this is used.
gram 2012/06/21 16:48:16 I went through many iterations (before isolates an
+ if (++_testconfig.x < 10) {
+ _defer(callback);
+ }
+}
+
+runTest() {
+ port.receive((testName, sendport) {
+ configure(_testconfig = new TestConfiguration(sendport));
+ if (testName == 'single correct test') {
+ test(testName, () => expect(2 + 3, equals(5)));
+ } else if (testName == 'single failing test') {
+ test(testName, () => expect(2 + 2, equals(5)));
+ } else if (testName == 'exception test') {
+ test(testName, () { throw new Exception('fail'); });
+ } else if (testName == 'group name test') {
+ group('a', () {
+ test('a', () {});
+ group('b', () {
+ test('b', () {});
+ });
+ });
+ } else if (testName == 'setup test') {
+ group('a', () {
+ setUp(() { _testconfig.setup = 'setup'; });
+ test(testName, () {});
+ });
+ } else if (testName == 'teardown test') {
+ group('a', () {
+ tearDown(() { _testconfig.teardown = 'teardown'; });
+ test(testName, () {});
+ });
+ } else if (testName == 'setup and teardown test') {
+ group('a', () {
+ setUp(() { _testconfig.setup = 'setup'; });
+ tearDown(() { _testconfig.teardown = 'teardown'; });
+ test(testName, () {});
+ });
+ } else if (testName == 'correct callback test') {
+ test(testName,
+ () =>_defer(expectAsync0((){ ++_testconfig.x;})));
+ } else if (testName == 'excess callback test') {
+ test(testName, () {
+ var _callback = expectAsync0((){ ++_testconfig.x;});
+ _defer(_callback);
+ _defer(_callback);
+ });
+ } else if (testName == 'completion test') {
+ test(testName, () {
+ var _callback;
+ _callback = expectAsyncUntil0(() {
+ if (++_testconfig.x < 10) {
+ _defer(_callback);
+ }
+ },
+ () => (_testconfig.x == 10));
+ _defer(_callback);
+ });
+ } else if (testName == 'setup and teardown test') {
eub 2012/06/21 00:09:42 Duplicate 'setup and teardown test'.
gram 2012/06/21 16:48:16 Done.
+ group('a', () {
+ setUp(() { _testconfig.setup = 'setup'; });
+ tearDown(() { _testconfig.teardown = 'teardown'; });
+ test(testName, () {});
+ });
+ }
+ });
+}
+
+void nextTest(int testNum) {
+ SendPort sport = spawnFunction(runTest);
+ sport.call(tests[testNum]).then((msg) {
+ actual.add(msg);
+ if (actual.length == expected.length) {
+ for (var i = 0; i < tests.length; i++) {
+ test(tests[i], () => expect(actual[i], equals(expected[i])));
+ }
+ } else {
+ nextTest(testNum+1);
+ }
+ });
+}
+
+main() {
+ tests = [
+ 'single correct test',
+ 'single failing test',
+ 'exception test',
+ 'group name test',
+ 'setup test',
+ 'teardown test',
+ 'setup and teardown test',
+ 'correct callback test',
+ 'excess callback test',
+ 'completion test'
+ ];
+
+ expected = [
+ '1:0:0:1:0:::null:single correct test:',
eub 2012/06/21 00:09:42 Comment w/ structure reference. passed : failed :
+ '0:1:0:1:0:::null:single failing test:Expected: <5> but: was <4>',
eub 2012/06/21 00:09:42 BTW, might like a helper to construct these string
+ '0:1:0:1:0:::null:exception test:Caught Exception: fail',
+ '2:0:0:2:0:::null:a a::a b b:',
+ '1:0:0:1:0:setup::null:a setup test:',
+ '1:0:0:1:0::teardown:null:a teardown test:',
+ '1:0:0:1:0:setup:teardown:null:a setup and teardown test:',
+ '1:0:0:1:1:::null:correct callback test:',
+ '0:0:1:1:1:::null:excess callback test:'
+ 'Callback called more times than expected (2 > 1)',
+ '1:0:0:1:10:::null:completion test:'
+ ];
+
+ actual = [];
+
+ nextTest(0);
+}
+
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698