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 setUpTimeout(); |
| 17 |
| 18 expectTestsPass("async().create() forwards to file().create", () { |
| 19 test('test', () { |
| 20 scheduleSandbox(); |
| 21 |
| 22 d.async(pumpEventQueue().then((_) { |
| 23 return d.file('name.txt', 'contents'); |
| 24 })).create(); |
| 25 |
| 26 d.file('name.txt', 'contents').validate(); |
| 27 }); |
| 28 }); |
| 29 |
| 30 expectTestsPass("async().create() forwards to directory().create", () { |
| 31 test('test', () { |
| 32 scheduleSandbox(); |
| 33 |
| 34 d.async(pumpEventQueue().then((_) { |
| 35 return d.dir('dir', [ |
| 36 d.file('file1.txt', 'contents1'), |
| 37 d.file('file2.txt', 'contents2') |
| 38 ]); |
| 39 })).create(); |
| 40 |
| 41 d.dir('dir', [ |
| 42 d.file('file1.txt', 'contents1'), |
| 43 d.file('file2.txt', 'contents2') |
| 44 ]).validate(); |
| 45 }); |
| 46 }); |
| 47 |
| 48 expectTestsPass("async().validate() forwards to file().validate", () { |
| 49 test('test', () { |
| 50 scheduleSandbox(); |
| 51 |
| 52 d.file('name.txt', 'contents').create(); |
| 53 |
| 54 d.async(pumpEventQueue().then((_) { |
| 55 return d.file('name.txt', 'contents'); |
| 56 })).validate(); |
| 57 }); |
| 58 }); |
| 59 |
| 60 expectTestsPass("async().validate() fails if file().validate fails", () { |
| 61 var errors; |
| 62 test('test 1', () { |
| 63 scheduleSandbox(); |
| 64 |
| 65 currentSchedule.onException.schedule(() { |
| 66 errors = currentSchedule.errors; |
| 67 }); |
| 68 |
| 69 d.async(pumpEventQueue().then((_) { |
| 70 return d.file('name.txt', 'contents'); |
| 71 })).validate(); |
| 72 }); |
| 73 |
| 74 test('test 2', () { |
| 75 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
| 76 expect(errors.length, equals(1)); |
| 77 expect(errors.first.error, |
| 78 matches(r"^File not found: '[^']+[\\/]name\.txt'\.$")); |
| 79 }); |
| 80 }, passing: ['test 2']); |
| 81 |
| 82 expectTestsPass("async().validate() forwards to directory().validate", () { |
| 83 test('test', () { |
| 84 scheduleSandbox(); |
| 85 |
| 86 d.dir('dir', [ |
| 87 d.file('file1.txt', 'contents1'), |
| 88 d.file('file2.txt', 'contents2') |
| 89 ]).create(); |
| 90 |
| 91 d.async(pumpEventQueue().then((_) { |
| 92 return d.dir('dir', [ |
| 93 d.file('file1.txt', 'contents1'), |
| 94 d.file('file2.txt', 'contents2') |
| 95 ]); |
| 96 })).validate(); |
| 97 }); |
| 98 }); |
| 99 |
| 100 expectTestsPass("async().create() fails if directory().create fails", () { |
| 101 var errors; |
| 102 test('test 1', () { |
| 103 scheduleSandbox(); |
| 104 |
| 105 currentSchedule.onException.schedule(() { |
| 106 errors = currentSchedule.errors; |
| 107 }); |
| 108 |
| 109 d.async(pumpEventQueue().then((_) { |
| 110 return d.dir('dir', [ |
| 111 d.file('file1.txt', 'contents1'), |
| 112 d.file('file2.txt', 'contents2') |
| 113 ]); |
| 114 })).validate(); |
| 115 }); |
| 116 |
| 117 test('test 2', () { |
| 118 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
| 119 expect(errors.length, equals(1)); |
| 120 expect(errors.first.error, |
| 121 matches(r"^Directory not found: '[^']+[\\/]dir'\.$")); |
| 122 }); |
| 123 }, passing: ['test 2']); |
| 124 |
| 125 expectTestsPass("async().load() fails", () { |
| 126 test('test', () { |
| 127 scheduleSandbox(); |
| 128 |
| 129 expect(d.async(new Future.immediate(d.file('name.txt'))) |
| 130 .load('path').toList(), |
| 131 throwsA(equals("AsyncDescriptors don't support load()."))); |
| 132 }); |
| 133 }); |
| 134 |
| 135 expectTestsPass("async().read() fails", () { |
| 136 test('test', () { |
| 137 scheduleSandbox(); |
| 138 |
| 139 expect(d.async(new Future.immediate(d.file('name.txt'))).read().toList(), |
| 140 throwsA(equals("AsyncDescriptors don't support read()."))); |
| 141 }); |
| 142 }); |
| 143 } |
OLD | NEW |