OLD | NEW |
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. |
11 | 11 |
12 library unittestTest; | 12 library unittestTest; |
13 import 'dart:isolate'; | 13 import 'dart:isolate'; |
14 import 'dart:async'; | 14 import 'dart:async'; |
15 import 'package:unittest/unittest.dart'; | 15 import 'package:unittest/unittest.dart'; |
16 | 16 |
17 Future _defer(void fn()) { | 17 Future _defer(void fn()) { |
18 return new Future.of(fn); | 18 return new Future.sync(fn); |
19 } | 19 } |
20 | 20 |
21 String buildStatusString(int passed, int failed, int errors, | 21 String buildStatusString(int passed, int failed, int errors, |
22 var results, | 22 var results, |
23 {int count: 0, | 23 {int count: 0, |
24 String setup: '', String teardown: '', | 24 String setup: '', String teardown: '', |
25 String uncaughtError: null, | 25 String uncaughtError: null, |
26 String message: ''}) { | 26 String message: ''}) { |
27 var totalTests = 0; | 27 var totalTests = 0; |
28 var testDetails = new StringBuffer(); | 28 var testDetails = new StringBuffer(); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 test('testThree', () { | 147 test('testThree', () { |
148 var done = expectAsync0((){}); | 148 var done = expectAsync0((){}); |
149 _defer(() { | 149 _defer(() { |
150 expect(true, isTrue); | 150 expect(true, isTrue); |
151 done(); | 151 done(); |
152 }); | 152 }); |
153 }); | 153 }); |
154 } else if (testName == 'async setup/teardown test') { | 154 } else if (testName == 'async setup/teardown test') { |
155 group('good setup/good teardown', () { | 155 group('good setup/good teardown', () { |
156 setUp(() { | 156 setUp(() { |
157 return new Future.immediate(0); | 157 return new Future.value(0); |
158 }); | 158 }); |
159 tearDown(() { | 159 tearDown(() { |
160 return new Future.immediate(0); | 160 return new Future.value(0); |
161 }); | 161 }); |
162 test('foo1', (){}); | 162 test('foo1', (){}); |
163 }); | 163 }); |
164 group('good setup/bad teardown', () { | 164 group('good setup/bad teardown', () { |
165 setUp(() { | 165 setUp(() { |
166 return new Future.immediate(0); | 166 return new Future.value(0); |
167 }); | 167 }); |
168 tearDown(() { | 168 tearDown(() { |
169 return new Future.immediateError("Failed to complete tearDown"); | 169 return new Future.error("Failed to complete tearDown"); |
170 }); | 170 }); |
171 test('foo2', (){}); | 171 test('foo2', (){}); |
172 }); | 172 }); |
173 group('bad setup/good teardown', () { | 173 group('bad setup/good teardown', () { |
174 setUp(() { | 174 setUp(() { |
175 return new Future.immediateError("Failed to complete setUp"); | 175 return new Future.error("Failed to complete setUp"); |
176 }); | 176 }); |
177 tearDown(() { | 177 tearDown(() { |
178 return new Future.immediate(0); | 178 return new Future.value(0); |
179 }); | 179 }); |
180 test('foo3', (){}); | 180 test('foo3', (){}); |
181 }); | 181 }); |
182 group('bad setup/bad teardown', () { | 182 group('bad setup/bad teardown', () { |
183 setUp(() { | 183 setUp(() { |
184 return new Future.immediateError("Failed to complete setUp"); | 184 return new Future.error("Failed to complete setUp"); |
185 }); | 185 }); |
186 tearDown(() { | 186 tearDown(() { |
187 return new Future.immediateError("Failed to complete tearDown"); | 187 return new Future.error("Failed to complete tearDown"); |
188 }); | 188 }); |
189 test('foo4', (){}); | 189 test('foo4', (){}); |
190 }); | 190 }); |
191 // The next test is just to make sure we make steady progress | 191 // The next test is just to make sure we make steady progress |
192 // through the tests. | 192 // through the tests. |
193 test('post groups', () {}); | 193 test('post groups', () {}); |
194 } else if (testName == 'test returning future') { | 194 } else if (testName == 'test returning future') { |
195 test("successful", () { | 195 test("successful", () { |
196 return _defer(() { | 196 return _defer(() { |
197 expect(true, true); | 197 expect(true, true); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 'runTests without tests': buildStatusString(0, 0, 0, null) | 358 'runTests without tests': buildStatusString(0, 0, 0, null) |
359 }; | 359 }; |
360 | 360 |
361 tests.forEach((String name, String expected) { | 361 tests.forEach((String name, String expected) { |
362 test(name, () => spawnFunction(runTest) | 362 test(name, () => spawnFunction(runTest) |
363 .call(name) | 363 .call(name) |
364 .then((String msg) => expect(msg.trim(), equals(expected)))); | 364 .then((String msg) => expect(msg.trim(), equals(expected)))); |
365 }); | 365 }); |
366 } | 366 } |
367 | 367 |
OLD | NEW |