| 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 'package:scheduled_test/scheduled_test.dart'; | |
| 6 | |
| 7 import 'package:metatest/metatest.dart'; | |
| 8 import '../utils.dart'; | |
| 9 | |
| 10 void main() => initTests(_test); | |
| 11 | |
| 12 void _test(message) { | |
| 13 initMetatest(message); | |
| 14 | |
| 15 setUpTimeout(); | |
| 16 | |
| 17 expectTestsPass('the onComplete queue is run if a test is successful', () { | |
| 18 var onCompleteRun = false; | |
| 19 test('test 1', () { | |
| 20 currentSchedule.onComplete.schedule(() { | |
| 21 onCompleteRun = true; | |
| 22 }); | |
| 23 | |
| 24 schedule(() => expect('foo', equals('foo'))); | |
| 25 }); | |
| 26 | |
| 27 test('test 2', () { | |
| 28 expect(onCompleteRun, isTrue); | |
| 29 }); | |
| 30 }); | |
| 31 | |
| 32 expectTestsPass('the onComplete queue is run after an out-of-band callback', | |
| 33 () { | |
| 34 var outOfBandRun = false; | |
| 35 test('test1', () { | |
| 36 currentSchedule.onComplete.schedule(() { | |
| 37 expect(outOfBandRun, isTrue); | |
| 38 }); | |
| 39 | |
| 40 pumpEventQueue().then(wrapAsync((_) { | |
| 41 outOfBandRun = true; | |
| 42 })); | |
| 43 }); | |
| 44 }); | |
| 45 | |
| 46 expectTestsPass('the onComplete queue is run after an out-of-band callback ' | |
| 47 'and waits for another out-of-band callback', () { | |
| 48 var outOfBand1Run = false; | |
| 49 var outOfBand2Run = false; | |
| 50 test('test1', () { | |
| 51 currentSchedule.onComplete.schedule(() { | |
| 52 expect(outOfBand1Run, isTrue); | |
| 53 | |
| 54 pumpEventQueue().then(wrapAsync((_) { | |
| 55 outOfBand2Run = true; | |
| 56 })); | |
| 57 }); | |
| 58 | |
| 59 pumpEventQueue().then(wrapAsync((_) { | |
| 60 outOfBand1Run = true; | |
| 61 })); | |
| 62 }); | |
| 63 | |
| 64 test('test2', () => expect(outOfBand2Run, isTrue)); | |
| 65 }); | |
| 66 | |
| 67 expectTestsFail('an out-of-band callback in the onComplete queue blocks the ' | |
| 68 'test', () { | |
| 69 test('test', () { | |
| 70 currentSchedule.onComplete.schedule(() { | |
| 71 pumpEventQueue().then(wrapAsync((_) => expect('foo', equals('bar')))); | |
| 72 }); | |
| 73 }); | |
| 74 }); | |
| 75 | |
| 76 expectTestsPass('an out-of-band callback blocks onComplete even with an ' | |
| 77 'unrelated error', () { | |
| 78 var outOfBandRun = false; | |
| 79 var outOfBandSetInOnComplete = false; | |
| 80 test('test 1', () { | |
| 81 currentSchedule.onComplete.schedule(() { | |
| 82 outOfBandSetInOnComplete = outOfBandRun; | |
| 83 }); | |
| 84 | |
| 85 pumpEventQueue().then(wrapAsync((_) { | |
| 86 outOfBandRun = true; | |
| 87 })); | |
| 88 | |
| 89 schedule(() => expect('foo', equals('bar'))); | |
| 90 }); | |
| 91 | |
| 92 test('test 2', () => expect(outOfBandSetInOnComplete, isTrue)); | |
| 93 }, passing: ['test 2']); | |
| 94 | |
| 95 expectTestsPass('the onComplete queue is run after an asynchronous error', | |
| 96 () { | |
| 97 var onCompleteRun = false; | |
| 98 test('test 1', () { | |
| 99 currentSchedule.onComplete.schedule(() { | |
| 100 onCompleteRun = true; | |
| 101 }); | |
| 102 | |
| 103 schedule(() => expect('foo', equals('bar'))); | |
| 104 }); | |
| 105 | |
| 106 test('test 2', () { | |
| 107 expect(onCompleteRun, isTrue); | |
| 108 }); | |
| 109 }, passing: ['test 2']); | |
| 110 | |
| 111 expectTestsPass('the onComplete queue is run after a synchronous error', () { | |
| 112 var onCompleteRun = false; | |
| 113 test('test 1', () { | |
| 114 currentSchedule.onComplete.schedule(() { | |
| 115 onCompleteRun = true; | |
| 116 }); | |
| 117 | |
| 118 throw 'error'; | |
| 119 }); | |
| 120 | |
| 121 test('test 2', () { | |
| 122 expect(onCompleteRun, isTrue); | |
| 123 }); | |
| 124 }, passing: ['test 2']); | |
| 125 | |
| 126 expectTestsPass('the onComplete queue is run after an out-of-band error', () { | |
| 127 var onCompleteRun = false; | |
| 128 test('test 1', () { | |
| 129 currentSchedule.onComplete.schedule(() { | |
| 130 onCompleteRun = true; | |
| 131 }); | |
| 132 | |
| 133 pumpEventQueue().then(wrapAsync((_) => expect('foo', equals('bar')))); | |
| 134 }); | |
| 135 | |
| 136 test('test 2', () { | |
| 137 expect(onCompleteRun, isTrue); | |
| 138 }); | |
| 139 }, passing: ['test 2']); | |
| 140 | |
| 141 expectTestsPass('onComplete tasks can be scheduled during normal tasks', () { | |
| 142 var onCompleteRun = false; | |
| 143 test('test 1', () { | |
| 144 schedule(() { | |
| 145 currentSchedule.onComplete.schedule(() { | |
| 146 onCompleteRun = true; | |
| 147 }); | |
| 148 }); | |
| 149 }); | |
| 150 | |
| 151 test('test 2', () { | |
| 152 expect(onCompleteRun, isTrue); | |
| 153 }); | |
| 154 }); | |
| 155 | |
| 156 expectTestsFail('failures in onComplete cause test failures', () { | |
| 157 test('test', () { | |
| 158 currentSchedule.onComplete.schedule(() { | |
| 159 expect('foo', equals('bar')); | |
| 160 }); | |
| 161 }); | |
| 162 }); | |
| 163 } | |
| OLD | NEW |