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

Side by Side Diff: pkg/scheduled_test/lib/scheduled_test.dart

Issue 154403006: Properly handle top-levled errors in scheduled_test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: small change Created 6 years, 10 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
« no previous file with comments | « no previous file | pkg/scheduled_test/test/scheduled_test/unhandled_error_test.dart » ('j') | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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(nweiz): Add support for calling [schedule] while the schedule is already 5 // TODO(nweiz): Add support for calling [schedule] while the schedule is already
6 // running. 6 // running.
7 // TODO(nweiz): Port the non-Pub-specific scheduled test libraries from Pub. 7 // TODO(nweiz): Port the non-Pub-specific scheduled test libraries from Pub.
8 /// A package for writing readable tests of asynchronous behavior. 8 /// A package for writing readable tests of asynchronous behavior.
9 /// 9 ///
10 /// ## Installing ## 10 /// ## Installing ##
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 _ensureInitialized(); 231 _ensureInitialized();
232 _ensureSetUpForTopLevel(); 232 _ensureSetUpForTopLevel();
233 testFn(description, () { 233 testFn(description, () {
234 var completer = new Completer(); 234 var completer = new Completer();
235 235
236 Chain.capture(() { 236 Chain.capture(() {
237 _currentSchedule = new Schedule(); 237 _currentSchedule = new Schedule();
238 return currentSchedule.run(() { 238 return currentSchedule.run(() {
239 if (_setUpFn != null) _setUpFn(); 239 if (_setUpFn != null) _setUpFn();
240 body(); 240 body();
241 }).catchError((error, stackTrace) {
242 if (error is ScheduleError) {
243 assert(error.schedule.errors.contains(error));
244 assert(error.schedule == currentSchedule);
245 unittest.registerException(error.schedule.errorString());
246 } else {
247 unittest.registerException(error, new Chain.forTrace(stackTrace));
248 }
241 }).then(completer.complete); 249 }).then(completer.complete);
242 }, onError: (e, chain) { 250 }, onError: (error, chain) => currentSchedule.signalError(error, chain));
243 if (e is ScheduleError) {
244 assert(e.schedule.errors.contains(e));
245 assert(e.schedule == currentSchedule);
246 unittest.registerException(e.schedule.errorString());
247 } else {
248 unittest.registerException(e, chain);
249 }
250 completer.complete();
251 });
252 251
253 return completer.future; 252 return completer.future;
254 }); 253 });
255 } 254 }
256 255
257 /// Whether or not the tests currently being defined are in a group. This is 256 /// Whether or not the tests currently being defined are in a group. This is
258 /// only true when defining tests, not when executing them. 257 /// only true when defining tests, not when executing them.
259 bool _inGroup = false; 258 bool _inGroup = false;
260 259
261 /// Creates a new named group of tests. This has the same semantics as 260 /// Creates a new named group of tests. This has the same semantics as
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 /// [description] provides an optional description of the future, which is 369 /// [description] provides an optional description of the future, which is
371 /// used when generating error messages. 370 /// used when generating error messages.
372 Future wrapFuture(Future future, [String description]) { 371 Future wrapFuture(Future future, [String description]) {
373 if (currentSchedule == null) { 372 if (currentSchedule == null) {
374 throw new StateError("Unexpected call to wrapFuture with no current " 373 throw new StateError("Unexpected call to wrapFuture with no current "
375 "schedule."); 374 "schedule.");
376 } 375 }
377 376
378 return currentSchedule.wrapFuture(future, description); 377 return currentSchedule.wrapFuture(future, description);
379 } 378 }
OLDNEW
« no previous file with comments | « no previous file | pkg/scheduled_test/test/scheduled_test/unhandled_error_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698