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

Unified Diff: pkg/unittest/test/unittest_test.dart

Issue 13463005: pkg/unittest: clean up unittest tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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: pkg/unittest/test/unittest_test.dart
diff --git a/pkg/unittest/test/unittest_test.dart b/pkg/unittest/test/unittest_test.dart
index 7f62c503cf542d84348c78d4fcfb0ebb6aefeb81..9621d92a7d08f0f6ac6787695417c688ac5c9bcb 100644
--- a/pkg/unittest/test/unittest_test.dart
+++ b/pkg/unittest/test/unittest_test.dart
@@ -14,10 +14,6 @@ import 'dart:isolate';
import 'dart:async';
import 'package:unittest/unittest.dart';
-var tests; // array of test names
-var expected; // array of test expected results (from buildStatusString)
-var actual; // actual test results (from buildStatusString in config.onDone)
-
Future _defer(void fn()) {
return new Future.of(fn);
}
@@ -71,7 +67,7 @@ class TestConfiguration extends Configuration {
}
runTest() {
- port.receive((testName, sendport) {
+ port.receive((String testName, sendport) {
var _testconfig= new TestConfiguration(sendport);
unittestConfiguration = _testconfig;
@@ -303,63 +299,34 @@ runTest() {
});
}
-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].trim(), 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',
- 'async exception test',
- 'late exception test',
- 'middle exception test',
- 'async setup/teardown test',
- 'test returning future',
- 'test returning future using Timer',
- 'testCases immutable'
- ];
-
- expected = [
- buildStatusString(1, 0, 0, tests[0]),
- buildStatusString(0, 1, 0, tests[1],
+ var tests = {
+ 'single correct test': buildStatusString(1, 0, 0, 'single correct test'),
+ 'single failing test': buildStatusString(0, 1, 0, 'single failing test',
message: 'Expected: <5> but: was <4>.'),
- buildStatusString(0, 1, 0, tests[2], message: 'Caught Exception: Fail.'),
- buildStatusString(2, 0, 0, 'a a::a b b'),
- buildStatusString(1, 0, 0, 'a ${tests[4]}', count: 0, setup: 'setup'),
- buildStatusString(1, 0, 0, 'a ${tests[5]}', count: 0, setup: '',
+ 'exception test': buildStatusString(0, 1, 0, 'exception test',
+ message: 'Caught Exception: Fail.'),
+ 'group name test': buildStatusString(2, 0, 0, 'a a::a b b'),
+ 'setup test': buildStatusString(1, 0, 0, 'a setup test',
+ count: 0, setup: 'setup'),
+ 'teardown test': buildStatusString(1, 0, 0, 'a teardown test',
+ count: 0, setup: '', teardown: 'teardown'),
+ 'setup and teardown test': buildStatusString(1, 0, 0,
+ 'a setup and teardown test', count: 0, setup: 'setup',
teardown: 'teardown'),
- buildStatusString(1, 0, 0, 'a ${tests[6]}', count: 0,
- setup: 'setup', teardown: 'teardown'),
- buildStatusString(1, 0, 0, tests[7], count: 1),
- buildStatusString(0, 1, 0, tests[8], count: 1,
- message: 'Callback called more times than expected (1).'),
- buildStatusString(1, 0, 0, tests[9], count: 10),
- buildStatusString(0, 1, 0, tests[10], message: 'Caught error!'),
- buildStatusString(1, 0, 1, 'testOne',
+ 'correct callback test': buildStatusString(1, 0, 0, 'correct callback test',
+ count: 1),
+ 'excess callback test': buildStatusString(0, 1, 0, 'excess callback test',
+ count: 1, message: 'Callback called more times than expected (1).'),
+ 'completion test': buildStatusString(1, 0, 0, 'completion test', count: 10),
+ 'async exception test': buildStatusString(0, 1, 0, 'async exception test',
+ message: 'Caught error!'),
+ 'late exception test': buildStatusString(1, 0, 1, 'testOne',
message: 'Callback called (2) after test case testOne has already '
'been marked as pass.:testTwo:'),
- buildStatusString(2, 1, 0,
+ 'middle exception test': buildStatusString(2, 1, 0,
'testOne::testTwo:Expected: false but: was <true>.:testThree'),
- buildStatusString(2, 0, 3,
+ 'async setup/teardown test': buildStatusString(2, 0, 3,
'good setup/good teardown foo1::'
'good setup/bad teardown foo2:good setup/bad teardown '
'foo2: Test teardown failed: Failed to complete tearDown:'
@@ -368,25 +335,28 @@ main() {
'bad setup/bad teardown foo4:bad setup/bad teardown '
'foo4: Test teardown failed: Failed to complete tearDown:'
'post groups'),
- buildStatusString(2, 4, 0,
+ 'test returning future': buildStatusString(2, 4, 0,
'successful::'
'error1:Callback called more times than expected (1).:'
'fail1:Expected: <false> but: was <true>.:'
'error2:Callback called more times than expected (1).:'
'fail2:failure:'
'foo5'),
- buildStatusString(2, 4, 0,
+ 'test returning future using Timer': buildStatusString(2, 4, 0,
'successful::'
'fail1:Expected: <false> but: was <true>.:'
'error1:Callback called more times than expected (1).:'
'fail2:failure:'
'error2:Callback called more times than expected (1).:'
'foo6'),
- buildStatusString(1, 0, 0, 'testCases immutable'),
- ];
-
- actual = [];
+ 'testCases immutable':
+ buildStatusString(1, 0, 0, 'testCases immutable'),
+ };
- nextTest(0);
+ tests.forEach((String name, String expected) {
+ test(name, () => spawnFunction(runTest)
+ .call(name)
+ .then((String msg) => expect(msg.trim(), equals(expected))));
+ });
}
« 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