mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
pkg/unittest: clean up unittest tests
No longer trying to align values and indices across three arrays Review URL: https://codereview.chromium.org//13463005 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@20792 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
4bcca7342b
commit
f614719ed8
1 changed files with 33 additions and 63 deletions
|
@ -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'),
|
||||
];
|
||||
'testCases immutable':
|
||||
buildStatusString(1, 0, 0, 'testCases immutable'),
|
||||
};
|
||||
|
||||
actual = [];
|
||||
|
||||
nextTest(0);
|
||||
tests.forEach((String name, String expected) {
|
||||
test(name, () => spawnFunction(runTest)
|
||||
.call(name)
|
||||
.then((String msg) => expect(msg.trim(), equals(expected))));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue