OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'dart:async'; |
| 6 import 'dart:io'; |
| 7 |
| 8 import 'package:scheduled_test/scheduled_test.dart'; |
| 9 import 'package:scheduled_test/src/mock_clock.dart' as mock_clock; |
| 10 |
| 11 import '../metatest.dart'; |
| 12 import '../utils.dart'; |
| 13 |
| 14 void main() { |
| 15 setUpTimeout(); |
| 16 |
| 17 expectTestsFail('an out-of-band failure in wrapFuture is handled', () { |
| 18 mock_clock.mock().run(); |
| 19 test('test', () { |
| 20 schedule(() { |
| 21 wrapFuture(sleep(1).then((_) => expect('foo', equals('bar')))); |
| 22 }); |
| 23 schedule(() => sleep(2)); |
| 24 }); |
| 25 }); |
| 26 |
| 27 expectTestsFail('an out-of-band failure in wrapFuture that finishes after ' |
| 28 'the schedule is handled', () { |
| 29 mock_clock.mock().run(); |
| 30 test('test', () { |
| 31 schedule(() { |
| 32 wrapFuture(sleep(2).then((_) => expect('foo', equals('bar')))); |
| 33 }); |
| 34 schedule(() => sleep(1)); |
| 35 }); |
| 36 }); |
| 37 |
| 38 expectTestsPass("wrapFuture should return the value of the wrapped future", |
| 39 () { |
| 40 test('test', () { |
| 41 schedule(() { |
| 42 expect(wrapFuture(pumpEventQueue().then((_) => 'foo')), |
| 43 completion(equals('foo'))); |
| 44 }); |
| 45 }); |
| 46 }); |
| 47 |
| 48 expectTestsPass("wrapFuture should pass through the error of the wrapped " |
| 49 "future", () { |
| 50 var error; |
| 51 test('test 1', () { |
| 52 schedule(() { |
| 53 wrapFuture(pumpEventQueue().then((_) { |
| 54 throw 'error'; |
| 55 })).catchError(wrapAsync((e) { |
| 56 error = e.error; |
| 57 })); |
| 58 }); |
| 59 }); |
| 60 |
| 61 test('test 2', () { |
| 62 expect(error, equals('error')); |
| 63 }); |
| 64 }, passing: ['test 2']); |
| 65 |
| 66 expectTestsPass("scheduled blocks whose return values are passed to " |
| 67 "wrapFuture should report exceptions once", () { |
| 68 var errors; |
| 69 test('test 1', () { |
| 70 currentSchedule.onException.schedule(() { |
| 71 errors = currentSchedule.errors; |
| 72 }); |
| 73 |
| 74 wrapFuture(schedule(() { |
| 75 throw 'error'; |
| 76 })); |
| 77 }); |
| 78 |
| 79 test('test 2', () { |
| 80 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
| 81 expect(errors.map((e) => e.error), equals(['error'])); |
| 82 }); |
| 83 }, passing: ['test 2']); |
| 84 } |
OLD | NEW |