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

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

Issue 13973021: Retrying the setUp/tearDown chaining change. This is the same as r21819 but with a change to schedu… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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/set_up_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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 }); 251 });
252 } 252 }
253 253
254 /// Whether or not the tests currently being defined are in a group. This is 254 /// Whether or not the tests currently being defined are in a group. This is
255 /// only true when defining tests, not when executing them. 255 /// only true when defining tests, not when executing them.
256 bool _inGroup = false; 256 bool _inGroup = false;
257 257
258 /// Creates a new named group of tests. This has the same semantics as 258 /// Creates a new named group of tests. This has the same semantics as
259 /// [unittest.group]. 259 /// [unittest.group].
260 void group(String description, void body()) { 260 void group(String description, void body()) {
261 _ensureInitialized();
262 _ensureSetUpForTopLevel();
261 unittest.group(description, () { 263 unittest.group(description, () {
262 var wasInGroup = _inGroup; 264 var wasInGroup = _inGroup;
263 _inGroup = true; 265 _inGroup = true;
264 _setUpScheduledTest();
265 body(); 266 body();
266 _inGroup = wasInGroup; 267 _inGroup = wasInGroup;
267 }); 268 });
268 } 269 }
269 270
270 /// Schedules a task, [fn], to run asynchronously as part of the main task queue 271 /// Schedules a task, [fn], to run asynchronously as part of the main task queue
271 /// of [currentSchedule]. Tasks will be run in the order they're scheduled. If 272 /// of [currentSchedule]. Tasks will be run in the order they're scheduled. If
272 /// [fn] returns a [Future], tasks after it won't be run until that [Future] 273 /// [fn] returns a [Future], tasks after it won't be run until that [Future]
273 /// completes. 274 /// completes.
274 /// 275 ///
(...skipping 29 matching lines...) Expand all
304 /// If we're in the top-level scope (that is, not in any [group]s) and 305 /// If we're in the top-level scope (that is, not in any [group]s) and
305 /// [unittest.setUp] hasn't been called yet, call it. 306 /// [unittest.setUp] hasn't been called yet, call it.
306 void _ensureSetUpForTopLevel() { 307 void _ensureSetUpForTopLevel() {
307 if (_inGroup || _setUpForTopLevel) return; 308 if (_inGroup || _setUpForTopLevel) return;
308 _setUpScheduledTest(); 309 _setUpScheduledTest();
309 } 310 }
310 311
311 /// Registers callbacks for [unittest.setUp] and [unittest.tearDown] that set up 312 /// Registers callbacks for [unittest.setUp] and [unittest.tearDown] that set up
312 /// and tear down the scheduled test infrastructure. 313 /// and tear down the scheduled test infrastructure.
313 void _setUpScheduledTest([void setUpFn()]) { 314 void _setUpScheduledTest([void setUpFn()]) {
314 if (!_inGroup) _setUpForTopLevel = true; 315 if (!_inGroup) {
315 316 _setUpForTopLevel = true;
316 unittest.setUp(() { 317 unittest.setUp(() {
317 if (currentSchedule != null) { 318 if (currentSchedule != null) {
318 throw new StateError('There seems to be another scheduled test ' 319 throw new StateError('There seems to be another scheduled test '
319 'still running.'); 320 'still running.');
320 } 321 }
321 _currentSchedule = new Schedule(); 322 _currentSchedule = new Schedule();
322 _setUpFn = setUpFn; 323 if (_setUpFn != null) {
323 }); 324 var parentFn = _setUpFn;
324 325 _setUpFn = () { parentFn(); setUpFn(); };
325 unittest.tearDown(() { 326 } else {
326 _currentSchedule = null; 327 _setUpFn = setUpFn;
327 }); 328 }
329 });
330
331 unittest.tearDown(() {
332 _currentSchedule = null;
333 _setUpFn = null;
334 });
335 } else {
336 unittest.setUp(() {
337 if (currentSchedule == null) {
338 throw new StateError('No schedule allocated.');
339 } else if (_setUpFn != null) {
340 var parentFn = _setUpFn;
341 _setUpFn = () { parentFn(); setUpFn(); };
342 } else {
343 _setUpFn = setUpFn;
344 }
345 });
346 }
328 } 347 }
329 348
330 /// Ensures that the global configuration for `scheduled_test` has been 349 /// Ensures that the global configuration for `scheduled_test` has been
331 /// initialized. 350 /// initialized.
332 void _ensureInitialized() { 351 void _ensureInitialized() {
333 unittest.ensureInitialized(); 352 unittest.ensureInitialized();
334 unittest.wrapAsync = (f, [description]) { 353 unittest.wrapAsync = (f, [description]) {
335 if (currentSchedule == null) { 354 if (currentSchedule == null) {
336 throw new StateError("Unexpected call to wrapAsync with no current " 355 throw new StateError("Unexpected call to wrapAsync with no current "
337 "schedule."); 356 "schedule.");
(...skipping 20 matching lines...) Expand all
358 377
359 return currentSchedule.wrapFuture(future, description); 378 return currentSchedule.wrapFuture(future, description);
360 } 379 }
361 380
362 // TODO(nweiz): re-export these once issue 9535 is fixed. 381 // TODO(nweiz): re-export these once issue 9535 is fixed.
363 unittest.Configuration get unittestConfiguration => 382 unittest.Configuration get unittestConfiguration =>
364 unittest.unittestConfiguration; 383 unittest.unittestConfiguration;
365 void set unittestConfiguration(unittest.Configuration value) { 384 void set unittestConfiguration(unittest.Configuration value) {
366 unittest.unittestConfiguration = value; 385 unittest.unittestConfiguration = value;
367 } 386 }
OLDNEW
« no previous file with comments | « no previous file | pkg/scheduled_test/test/scheduled_test/set_up_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698