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

Side by Side Diff: tests/lib/unittest/unittest_test.dart

Issue 10834098: Fix issue 4227 - unittest.dart silently consumes exceptions when expectAsync is active. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« lib/unittest/unittest.dart ('K') | « lib/unittest/unittest.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // TODO(gram): 5 // TODO(gram):
6 // Unfortunately I can't seem to test anything that involves timeouts, e.g. 6 // Unfortunately I can't seem to test anything that involves timeouts, e.g.
7 // insufficient callbacks, because the timeout is controlled externally 7 // insufficient callbacks, because the timeout is controlled externally
8 // (test.dart?), and we would need to use a shorter timeout for the inner tests 8 // (test.dart?), and we would need to use a shorter timeout for the inner tests
9 // so the outer timeout doesn't fire. So I removed all such tests. 9 // so the outer timeout doesn't fire. So I removed all such tests.
10 // I'd like to revisit this at some point. 10 // I'd like to revisit this at some point.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 test(testName, () { 116 test(testName, () {
117 var _callback; 117 var _callback;
118 _callback = expectAsyncUntil0(() { 118 _callback = expectAsyncUntil0(() {
119 if (++_testconfig.count < 10) { 119 if (++_testconfig.count < 10) {
120 _defer(_callback); 120 _defer(_callback);
121 } 121 }
122 }, 122 },
123 () => (_testconfig.count == 10)); 123 () => (_testconfig.count == 10));
124 _defer(_callback); 124 _defer(_callback);
125 }); 125 });
126 } else if (testName == 'async exception test') {
127 test(testName, () {
128 expectAsync0(() {});
129 _defer(() => guardAsync(() { throw "error!"; }));
130 });
126 } 131 }
127 }); 132 });
128 } 133 }
129 134
130 void nextTest(int testNum) { 135 void nextTest(int testNum) {
131 SendPort sport = spawnFunction(runTest); 136 SendPort sport = spawnFunction(runTest);
132 sport.call(tests[testNum]).then((msg) { 137 sport.call(tests[testNum]).then((msg) {
133 actual.add(msg); 138 actual.add(msg);
134 if (actual.length == expected.length) { 139 if (actual.length == expected.length) {
135 for (var i = 0; i < tests.length; i++) { 140 for (var i = 0; i < tests.length; i++) {
136 test(tests[i], () => expect(actual[i].trim(), equals(expected[i]))); 141 test(tests[i], () => expect(actual[i].trim(), equals(expected[i])));
137 } 142 }
138 } else { 143 } else {
139 nextTest(testNum+1); 144 nextTest(testNum+1);
140 } 145 }
141 }); 146 });
142 } 147 }
143 148
144 main() { 149 main() {
145 tests = [ 150 tests = [
146 'single correct test', 151 'single correct test',
147 'single failing test', 152 'single failing test',
148 'exception test', 153 'exception test',
149 'group name test', 154 'group name test',
150 'setup test', 155 'setup test',
151 'teardown test', 156 'teardown test',
152 'setup and teardown test', 157 'setup and teardown test',
153 'correct callback test', 158 'correct callback test',
154 'excess callback test', 159 'excess callback test',
155 'completion test' 160 'completion test',
161 'async exception test'
156 ]; 162 ];
157 163
158 expected = [ 164 expected = [
159 buildStatusString(1, 0, 0, tests[0]), 165 buildStatusString(1, 0, 0, tests[0]),
160 buildStatusString(0, 1, 0, tests[1], 166 buildStatusString(0, 1, 0, tests[1],
161 message: 'Expected: <5> but: was <4>.'), 167 message: 'Expected: <5> but: was <4>.'),
162 buildStatusString(0, 1, 0, tests[2], message: 'Caught Exception: Fail.'), 168 buildStatusString(0, 1, 0, tests[2], message: 'Caught Exception: Fail.'),
163 buildStatusString(2, 0, 0, 'a a::a b b'), 169 buildStatusString(2, 0, 0, 'a a::a b b'),
164 buildStatusString(1, 0, 0, 'a ${tests[4]}', 0, 'setup'), 170 buildStatusString(1, 0, 0, 'a ${tests[4]}', 0, 'setup'),
165 buildStatusString(1, 0, 0, 'a ${tests[5]}', 0, '', 'teardown'), 171 buildStatusString(1, 0, 0, 'a ${tests[5]}', 0, '', 'teardown'),
166 buildStatusString(1, 0, 0, 'a ${tests[6]}', 0, 172 buildStatusString(1, 0, 0, 'a ${tests[6]}', 0,
167 'setup', 'teardown'), 173 'setup', 'teardown'),
168 buildStatusString(1, 0, 0, tests[7], 1), 174 buildStatusString(1, 0, 0, tests[7], 1),
169 buildStatusString(0, 0, 1, tests[8], 1, 175 buildStatusString(0, 0, 1, tests[8], 1,
170 message: 'Callback called more times than expected (2 > 1).'), 176 message: 'Callback called more times than expected (2 > 1).'),
171 buildStatusString(1, 0, 0, tests[9], 10) 177 buildStatusString(1, 0, 0, tests[9], 10),
178 buildStatusString(0, 0, 1, tests[10], message: 'Caught error!'),
172 ]; 179 ];
173 180
174 actual = []; 181 actual = [];
175 182
176 nextTest(0); 183 nextTest(0);
177 } 184 }
178 185
OLDNEW
« lib/unittest/unittest.dart ('K') | « lib/unittest/unittest.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698