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 String sandbox; |
| 16 |
| 17 void main() { |
| 18 setUpTimeout(); |
| 19 |
| 20 expectTestsPass("pattern().validate() succeeds if there's a file matching " |
| 21 "the pattern and the child entry", () { |
| 22 test('test', () { |
| 23 scheduleSandbox(); |
| 24 |
| 25 d.file('foo', 'blap').create(); |
| 26 |
| 27 d.filePattern(new RegExp(r'f..'), 'blap').validate(); |
| 28 }); |
| 29 }); |
| 30 |
| 31 expectTestsPass("pattern().validate() succeeds if there's a dir matching " |
| 32 "the pattern and the child entry", () { |
| 33 test('test', () { |
| 34 scheduleSandbox(); |
| 35 |
| 36 d.dir('foo', [ |
| 37 d.file('bar', 'baz') |
| 38 ]).create(); |
| 39 |
| 40 d.dirPattern(new RegExp(r'f..'), [ |
| 41 d.file('bar', 'baz') |
| 42 ]).validate(); |
| 43 }); |
| 44 }); |
| 45 |
| 46 expectTestsPass("pattern().validate() succeeds if there's multiple files " |
| 47 "matching the pattern but only one matching the child entry", () { |
| 48 test('test', () { |
| 49 scheduleSandbox(); |
| 50 |
| 51 d.file('foo', 'blap').create(); |
| 52 d.file('fee', 'blak').create(); |
| 53 d.file('faa', 'blut').create(); |
| 54 |
| 55 d.filePattern(new RegExp(r'f..'), 'blap').validate(); |
| 56 }); |
| 57 }); |
| 58 |
| 59 expectTestsPass("pattern().validate() fails if there's no file matching the " |
| 60 "pattern", () { |
| 61 var errors; |
| 62 test('test 1', () { |
| 63 scheduleSandbox(); |
| 64 |
| 65 currentSchedule.onException.schedule(() { |
| 66 errors = currentSchedule.errors; |
| 67 }); |
| 68 |
| 69 d.filePattern(new RegExp(r'f..'), 'bar').validate(); |
| 70 }); |
| 71 |
| 72 test('test 2', () { |
| 73 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
| 74 expect(errors.length, equals(1)); |
| 75 expect(errors.first.error, |
| 76 matches(r"^No entry found in '[^']+' matching /f\.\./\.$")); |
| 77 }); |
| 78 }, passing: ['test 2']); |
| 79 |
| 80 expectTestsPass("pattern().validate() fails if there's a file matching the " |
| 81 "pattern but not the entry", () { |
| 82 var errors; |
| 83 test('test 1', () { |
| 84 scheduleSandbox(); |
| 85 |
| 86 currentSchedule.onException.schedule(() { |
| 87 errors = currentSchedule.errors; |
| 88 }); |
| 89 |
| 90 d.file('foo', 'bap').create(); |
| 91 d.filePattern(new RegExp(r'f..'), 'bar').validate(); |
| 92 }); |
| 93 |
| 94 test('test 2', () { |
| 95 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
| 96 expect(errors.length, equals(1)); |
| 97 expect(errors.first.error, |
| 98 matches(r"^Caught error\n" |
| 99 r"| File 'foo' should contain:\n" |
| 100 r"| | bar\n" |
| 101 r"| but actually contained:\n" |
| 102 r"| X bap\n" |
| 103 r"while validating\n" |
| 104 r"| foo$")); |
| 105 }); |
| 106 }, passing: ['test 2']); |
| 107 |
| 108 expectTestsPass("pattern().validate() fails if there's a dir matching the " |
| 109 "pattern but not the entry", () { |
| 110 var errors; |
| 111 test('test 1', () { |
| 112 scheduleSandbox(); |
| 113 |
| 114 currentSchedule.onException.schedule(() { |
| 115 errors = currentSchedule.errors; |
| 116 }); |
| 117 |
| 118 d.dir('foo', [ |
| 119 d.file('bar', 'bap') |
| 120 ]).create(); |
| 121 |
| 122 d.dirPattern(new RegExp(r'f..'), [ |
| 123 d.file('bar', 'baz') |
| 124 ]).validate(); |
| 125 }); |
| 126 |
| 127 test('test 2', () { |
| 128 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
| 129 expect(errors.length, equals(1)); |
| 130 expect(errors.first.error, |
| 131 matches(r"^Caught error\n" |
| 132 r"| File 'bar' should contain:\n" |
| 133 r"| | baz\n" |
| 134 r"| but actually contained:\n" |
| 135 r"| X bap" |
| 136 r"while validating\n" |
| 137 r"| foo\n" |
| 138 r"| '-- bar$")); |
| 139 }); |
| 140 }, passing: ['test 2']); |
| 141 |
| 142 expectTestsPass("pattern().validate() fails if there's multiple files " |
| 143 "matching the pattern and the child entry", () { |
| 144 var errors; |
| 145 test('test 1', () { |
| 146 scheduleSandbox(); |
| 147 |
| 148 currentSchedule.onException.schedule(() { |
| 149 errors = currentSchedule.errors; |
| 150 }); |
| 151 |
| 152 d.file('foo', 'bar').create(); |
| 153 d.file('fee', 'bar').create(); |
| 154 d.file('faa', 'bar').create(); |
| 155 d.filePattern(new RegExp(r'f..'), 'bar').validate(); |
| 156 }); |
| 157 |
| 158 test('test 2', () { |
| 159 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
| 160 expect(errors.length, equals(1)); |
| 161 expect(errors.first.error, matches( |
| 162 r"^Multiple valid entries found in '[^']+' matching " |
| 163 r"\/f\.\./:\n" |
| 164 r"\* faa\n" |
| 165 r"\* fee\n" |
| 166 r"\* foo$")); |
| 167 }); |
| 168 }, passing: ['test 2']); |
| 169 } |
OLD | NEW |