Chromium Code Reviews| 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:pathos/path.dart' as path; | |
| 9 import 'package:scheduled_test/descriptor.dart' as d; | |
| 10 import 'package:scheduled_test/scheduled_test.dart'; | |
| 11 | |
| 12 import '../metatest.dart'; | |
| 13 import 'utils.dart'; | |
| 14 | |
| 15 void main() { | |
| 16 metaSetUp(() { | |
| 17 // TODO(nweiz): We used to only increase the timeout to 10s for the Windows | |
| 18 // bots, but the Linux and Mac bots have started taking upwards of 5s when | |
| 19 // running pumpEventQueue, so we're increasing the timeout across the board | |
| 20 // (see issue 9248). | |
| 21 currentSchedule.timeout = new Duration(seconds: 10); | |
| 22 }); | |
|
Bob Nystrom
2013/04/02 22:03:17
How about moving this into a separate function in
nweiz
2013/04/02 22:38:44
Done.
| |
| 23 | |
| 24 expectTestsPass("async().create() forwards to file().create", () { | |
| 25 test('test', () { | |
| 26 scheduleSandbox(); | |
| 27 | |
| 28 d.async(pumpEventQueue().then((_) { | |
| 29 return d.file('name.txt', 'contents'); | |
| 30 })).create(); | |
| 31 | |
| 32 d.file('name.txt', 'contents').validate(); | |
| 33 }); | |
| 34 }); | |
| 35 | |
| 36 expectTestsPass("async().create() forwards to directory().create", () { | |
| 37 test('test', () { | |
| 38 scheduleSandbox(); | |
| 39 | |
| 40 d.async(pumpEventQueue().then((_) { | |
| 41 return d.dir('dir', [ | |
| 42 d.file('file1.txt', 'contents1'), | |
| 43 d.file('file2.txt', 'contents2') | |
| 44 ]); | |
| 45 })).create(); | |
| 46 | |
| 47 d.dir('dir', [ | |
| 48 d.file('file1.txt', 'contents1'), | |
| 49 d.file('file2.txt', 'contents2') | |
| 50 ]).validate(); | |
| 51 }); | |
| 52 }); | |
| 53 | |
| 54 expectTestsPass("async().validate() forwards to file().validate", () { | |
| 55 test('test', () { | |
| 56 scheduleSandbox(); | |
| 57 | |
| 58 d.file('name.txt', 'contents').create(); | |
| 59 | |
| 60 d.async(pumpEventQueue().then((_) { | |
| 61 return d.file('name.txt', 'contents'); | |
| 62 })).validate(); | |
| 63 }); | |
| 64 }); | |
| 65 | |
| 66 expectTestsPass("async().validate() fails if file().validate fails", () { | |
| 67 var errors; | |
| 68 test('test 1', () { | |
| 69 scheduleSandbox(); | |
| 70 | |
| 71 currentSchedule.onException.schedule(() { | |
| 72 errors = currentSchedule.errors; | |
| 73 }); | |
| 74 | |
| 75 d.async(pumpEventQueue().then((_) { | |
| 76 return d.file('name.txt', 'contents'); | |
| 77 })).validate(); | |
| 78 }); | |
| 79 | |
| 80 test('test 2', () { | |
| 81 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
| 82 expect(errors.length, equals(1)); | |
| 83 expect(errors.first.error, | |
| 84 matches(r"^File not found: '[^']+[\\/]name\.txt'\.$")); | |
| 85 }); | |
| 86 }, passing: ['test 2']); | |
| 87 | |
| 88 expectTestsPass("async().validate() forwards to directory().validate", () { | |
| 89 test('test', () { | |
| 90 scheduleSandbox(); | |
| 91 | |
| 92 d.dir('dir', [ | |
| 93 d.file('file1.txt', 'contents1'), | |
| 94 d.file('file2.txt', 'contents2') | |
| 95 ]).create(); | |
| 96 | |
| 97 d.async(pumpEventQueue().then((_) { | |
| 98 return d.dir('dir', [ | |
| 99 d.file('file1.txt', 'contents1'), | |
| 100 d.file('file2.txt', 'contents2') | |
| 101 ]); | |
| 102 })).validate(); | |
| 103 }); | |
| 104 }); | |
| 105 | |
| 106 expectTestsPass("async().create() fails if directory().create fails", () { | |
| 107 var errors; | |
| 108 test('test 1', () { | |
| 109 scheduleSandbox(); | |
| 110 | |
| 111 currentSchedule.onException.schedule(() { | |
| 112 errors = currentSchedule.errors; | |
| 113 }); | |
| 114 | |
| 115 d.async(pumpEventQueue().then((_) { | |
| 116 return d.dir('dir', [ | |
| 117 d.file('file1.txt', 'contents1'), | |
| 118 d.file('file2.txt', 'contents2') | |
| 119 ]); | |
| 120 })).validate(); | |
| 121 }); | |
| 122 | |
| 123 test('test 2', () { | |
| 124 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
| 125 expect(errors.length, equals(1)); | |
| 126 expect(errors.first.error, | |
| 127 matches(r"^Directory not found: '[^']+[\\/]dir'\.$")); | |
| 128 }); | |
| 129 }, passing: ['test 2']); | |
| 130 | |
| 131 expectTestsPass("async().load() fails", () { | |
| 132 test('test', () { | |
| 133 scheduleSandbox(); | |
| 134 | |
| 135 expect(d.async(new Future.immediate(d.file('name.txt'))) | |
| 136 .load('path').toList(), | |
| 137 throwsA(equals("AsyncDescriptors don't support load()."))); | |
| 138 }); | |
| 139 }); | |
| 140 | |
| 141 expectTestsPass("async().read() fails", () { | |
| 142 test('test', () { | |
| 143 scheduleSandbox(); | |
| 144 | |
| 145 expect(d.async(new Future.immediate(d.file('name.txt'))).read().toList(), | |
| 146 throwsA(equals("AsyncDescriptors don't support read()."))); | |
| 147 }); | |
| 148 }); | |
| 149 } | |
| OLD | NEW |