Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: pkg/scheduled_test/test/descriptor/directory_test.dart

Issue 24276010: Change package scheduled_test to throw TestFailures rather than strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Also in async_test.dart Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:io'; 6 import 'dart:io';
7 7
8 import 'package:path/path.dart' as path; 8 import 'package:path/path.dart' as path;
9 import 'package:scheduled_test/descriptor.dart' as d; 9 import 'package:scheduled_test/descriptor.dart' as d;
10 import 'package:scheduled_test/scheduled_test.dart'; 10 import 'package:scheduled_test/scheduled_test.dart';
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 d.dir('subdir', [ 118 d.dir('subdir', [
119 d.file('subfile1.txt', 'subcontents1'), 119 d.file('subfile1.txt', 'subcontents1'),
120 d.file('subfile2.txt', 'subcontents2') 120 d.file('subfile2.txt', 'subcontents2')
121 ]), 121 ]),
122 d.file('file1.txt', 'contents1'), 122 d.file('file1.txt', 'contents1'),
123 d.file('file2.txt', 'contents2') 123 d.file('file2.txt', 'contents2')
124 ]).validate(); 124 ]).validate();
125 }); 125 });
126 126
127 test('test 2', () { 127 test('test 2', () {
128 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); 128 expect(errors.single, new isInstanceOf<ScheduleError>());
129 expect(errors.length, equals(1)); 129 expect(errors.single.error.toString(),
130 expect(errors.first.error.toString(),
131 matches(r"^Directory not found: '[^']+[\\/]dir[\\/]subdir'\.$")); 130 matches(r"^Directory not found: '[^']+[\\/]dir[\\/]subdir'\.$"));
132 }); 131 });
133 }, passing: ['test 2']); 132 }, passing: ['test 2']);
134 133
135 expectTestsPass("directory().validate() fails if a file isn't found", () { 134 expectTestsPass("directory().validate() fails if a file isn't found", () {
136 var errors; 135 var errors;
137 test('test 1', () { 136 test('test 1', () {
138 scheduleSandbox(); 137 scheduleSandbox();
139 138
140 currentSchedule.onException.schedule(() { 139 currentSchedule.onException.schedule(() {
(...skipping 19 matching lines...) Expand all
160 d.dir('subdir', [ 159 d.dir('subdir', [
161 d.file('subfile1.txt', 'subcontents1'), 160 d.file('subfile1.txt', 'subcontents1'),
162 d.file('subfile2.txt', 'subcontents2') 161 d.file('subfile2.txt', 'subcontents2')
163 ]), 162 ]),
164 d.file('file1.txt', 'contents1'), 163 d.file('file1.txt', 'contents1'),
165 d.file('file2.txt', 'contents2') 164 d.file('file2.txt', 'contents2')
166 ]).validate(); 165 ]).validate();
167 }); 166 });
168 167
169 test('test 2', () { 168 test('test 2', () {
170 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); 169 expect(errors.single, new isInstanceOf<ScheduleError>());
171 expect(errors.length, equals(1)); 170 expect(errors.single.error.toString(),
172 expect(errors.first.error.toString(),
173 matches(r"^File not found: '[^']+[\\/]dir[\\/]file2\.txt'\.$")); 171 matches(r"^File not found: '[^']+[\\/]dir[\\/]file2\.txt'\.$"));
174 }); 172 });
175 }, passing: ['test 2']); 173 }, passing: ['test 2']);
176 174
177 expectTestsPass("directory().validate() fails if multiple children aren't " 175 expectTestsPass("directory().validate() fails if multiple children aren't "
178 "found or have the wrong contents", () { 176 "found or have the wrong contents", () {
179 var errors; 177 var errors;
180 test('test 1', () { 178 test('test 1', () {
181 scheduleSandbox(); 179 scheduleSandbox();
182 180
(...skipping 18 matching lines...) Expand all
201 d.dir('subdir', [ 199 d.dir('subdir', [
202 d.file('subfile1.txt', 'subcontents1'), 200 d.file('subfile1.txt', 'subcontents1'),
203 d.file('subfile2.txt', 'subcontents2') 201 d.file('subfile2.txt', 'subcontents2')
204 ]), 202 ]),
205 d.file('file1.txt', 'contents1'), 203 d.file('file1.txt', 'contents1'),
206 d.file('file2.txt', 'contents2') 204 d.file('file2.txt', 'contents2')
207 ]).validate(); 205 ]).validate();
208 }); 206 });
209 207
210 test('test 2', () { 208 test('test 2', () {
211 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); 209 expect(errors.single, new isInstanceOf<ScheduleError>());
212 expect(errors.length, equals(1)); 210 expect(errors.single.error.toString(), matches(
213 expect(errors.first.error.toString(), matches(
214 r"^\* File not found: '[^']+[\\/]dir[\\/]subdir[\\/]subfile1\.txt'\." 211 r"^\* File not found: '[^']+[\\/]dir[\\/]subdir[\\/]subfile1\.txt'\."
215 r"\n" 212 r"\n"
216 r"\* File 'subfile2\.txt' should contain:\n" 213 r"\* File 'subfile2\.txt' should contain:\n"
217 r" \| subcontents2\n" 214 r" \| subcontents2\n"
218 r" but actually contained:\n" 215 r" but actually contained:\n"
219 r" X subwrongtents2\n" 216 r" X subwrongtents2\n"
220 r"\* File not found: '[^']+[\\/]dir[\\/]file2\.txt'\.$")); 217 r"\* File not found: '[^']+[\\/]dir[\\/]file2\.txt'\.$"));
221 }); 218 });
222 }, passing: ['test 2']); 219 }, passing: ['test 2']);
223 220
(...skipping 28 matching lines...) Expand all
252 d.dir('subdir', [ 249 d.dir('subdir', [
253 d.file('subfile1.txt', 'subcontents1'), 250 d.file('subfile1.txt', 'subcontents1'),
254 d.file('subfile2.txt', 'subcontents2') 251 d.file('subfile2.txt', 'subcontents2')
255 ]), 252 ]),
256 d.file('file1.txt', 'contents1'), 253 d.file('file1.txt', 'contents1'),
257 d.file('file2.txt', 'contents2') 254 d.file('file2.txt', 'contents2')
258 ]).validate(); 255 ]).validate();
259 }); 256 });
260 257
261 test('test 2', () { 258 test('test 2', () {
262 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); 259 expect(errors.single, new isInstanceOf<ScheduleError>());
263 expect(errors.map((e) => e.error.toString()), equals([ 260 expect(errors.single.error.toString(), equals(
264 "File 'subfile1.txt' should contain:\n" 261 "File 'subfile1.txt' should contain:\n"
265 "| subcontents1\n" 262 "| subcontents1\n"
266 "but actually contained:\n" 263 "but actually contained:\n"
267 "X wrongtents1" 264 "X wrongtents1"));
268 ]));
269 }); 265 });
270 }, passing: ['test 2']); 266 }, passing: ['test 2']);
271 267
272 expectTestsPass("directory().load() loads a file", () { 268 expectTestsPass("directory().load() loads a file", () {
273 test('test', () { 269 test('test', () {
274 var dir = d.dir('dir', [d.file('name.txt', 'contents')]); 270 var dir = d.dir('dir', [d.file('name.txt', 'contents')]);
275 expect(byteStreamToString(dir.load('name.txt')), 271 expect(byteStreamToString(dir.load('name.txt')),
276 completion(equals('contents'))); 272 completion(equals('contents')));
277 }); 273 });
278 }); 274 });
(...skipping 14 matching lines...) Expand all
293 289
294 expectTestsPass("directory().load() fails to load a nested directory", () { 290 expectTestsPass("directory().load() fails to load a nested directory", () {
295 test('test', () { 291 test('test', () {
296 var dir = d.dir('dir', [ 292 var dir = d.dir('dir', [
297 d.dir('subdir', [ 293 d.dir('subdir', [
298 d.file('name.txt', 'subcontents') 294 d.file('name.txt', 'subcontents')
299 ]), 295 ]),
300 d.file('name.txt', 'contents') 296 d.file('name.txt', 'contents')
301 ]); 297 ]);
302 298
303 expect(dir.load('subdir').toList(), 299 expect(dir.load('subdir').toList(), throwsA(predicate(
304 throwsA(equals("Couldn't find a readable entry named 'subdir' within " 300 (x) => x.toString() == "Couldn't find a readable entry named "
305 "'dir'."))); 301 "'subdir' within 'dir'.")));
306 }); 302 });
307 }); 303 });
308 304
309 expectTestsPass("directory().load() fails to load an absolute path", () { 305 expectTestsPass("directory().load() fails to load an absolute path", () {
310 test('test', () { 306 test('test', () {
311 var dir = d.dir('dir', [d.file('name.txt', 'contents')]); 307 var dir = d.dir('dir', [d.file('name.txt', 'contents')]);
312 308
313 expect(dir.load('/name.txt').toList(), throwsArgumentError); 309 expect(dir.load('/name.txt').toList(), throwsArgumentError);
314 }); 310 });
315 }); 311 });
316 312
317 expectTestsPass("directory().load() fails to load '.', '..', or ''", () { 313 expectTestsPass("directory().load() fails to load '.', '..', or ''", () {
318 test('test', () { 314 test('test', () {
319 var dir = d.dir('dir', [d.file('name.txt', 'contents')]); 315 var dir = d.dir('dir', [d.file('name.txt', 'contents')]);
320 316
321 expect(dir.load('.').toList(), throwsArgumentError); 317 expect(dir.load('.').toList(), throwsArgumentError);
322 318
323 expect(dir.load('..').toList(), throwsArgumentError); 319 expect(dir.load('..').toList(), throwsArgumentError);
324 320
325 expect(dir.load('').toList(), throwsArgumentError); 321 expect(dir.load('').toList(), throwsArgumentError);
326 }); 322 });
327 }); 323 });
328 324
329 expectTestsPass("directory().load() fails to load a file that doesn't exist", 325 expectTestsPass("directory().load() fails to load a file that doesn't exist",
330 () { 326 () {
331 test('test', () { 327 test('test', () {
332 var dir = d.dir('dir', [d.file('name.txt', 'contents')]); 328 var dir = d.dir('dir', [d.file('name.txt', 'contents')]);
333 329
334 expect(dir.load('not-name.txt').toList(), 330 expect(dir.load('not-name.txt').toList(), throwsA(predicate(
335 throwsA(equals("Couldn't find a readable entry named 'not-name.txt' " 331 (x) => x.toString() == "Couldn't find a readable entry named "
336 "within 'dir'."))); 332 "'not-name.txt' within 'dir'.")));
337 }); 333 });
338 }); 334 });
339 335
340 expectTestsPass("directory().load() fails to load a file that exists " 336 expectTestsPass("directory().load() fails to load a file that exists "
341 "multiple times", () { 337 "multiple times", () {
342 test('test', () { 338 test('test', () {
343 var dir = d.dir('dir', [ 339 var dir = d.dir('dir', [
344 d.file('name.txt', 'contents'), 340 d.file('name.txt', 'contents'),
345 d.file('name.txt', 'contents') 341 d.file('name.txt', 'contents')
346 ]); 342 ]);
347 343
348 expect(dir.load('name.txt').toList(), 344 expect(dir.load('name.txt').toList(), throwsA(predicate(
349 throwsA(equals("Found multiple readable entries named 'name.txt' " 345 (x) => x.toString() == "Found multiple readable entries named "
350 "within 'dir'."))); 346 "'name.txt' within 'dir'.")));
351 }); 347 });
352 }); 348 });
353 349
354 expectTestsPass("directory().load() loads a file next to a subdirectory with " 350 expectTestsPass("directory().load() loads a file next to a subdirectory with "
355 "the same name", () { 351 "the same name", () {
356 test('test', () { 352 test('test', () {
357 var dir = d.dir('dir', [ 353 var dir = d.dir('dir', [
358 d.file('name', 'contents'), 354 d.file('name', 'contents'),
359 d.dir('name', [d.file('subfile', 'contents')]) 355 d.dir('name', [d.file('subfile', 'contents')])
360 ]); 356 ]);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 "'-- file2.txt")); 401 "'-- file2.txt"));
406 }); 402 });
407 }); 403 });
408 404
409 expectTestsPass("directory().describe() with no contents returns the " 405 expectTestsPass("directory().describe() with no contents returns the "
410 "directory name", () { 406 "directory name", () {
411 test('test', () { 407 test('test', () {
412 expect(d.dir('dir').describe(), equals('dir')); 408 expect(d.dir('dir').describe(), equals('dir'));
413 }); 409 });
414 }); 410 });
415 } 411 }
OLDNEW
« no previous file with comments | « pkg/scheduled_test/test/descriptor/async_test.dart ('k') | pkg/scheduled_test/test/descriptor/file_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698