| OLD | NEW |
| 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:pathos/path.dart' as path; | 8 import 'package:pathos/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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 d.file('name.txt', 'subcontents') | 284 d.file('name.txt', 'subcontents') |
| 285 ]), | 285 ]), |
| 286 d.file('name.txt', 'contents') | 286 d.file('name.txt', 'contents') |
| 287 ]); | 287 ]); |
| 288 | 288 |
| 289 expect(byteStreamToString(dir.load('subdir/name.txt')), | 289 expect(byteStreamToString(dir.load('subdir/name.txt')), |
| 290 completion(equals('subcontents'))); | 290 completion(equals('subcontents'))); |
| 291 }); | 291 }); |
| 292 }); | 292 }); |
| 293 | 293 |
| 294 expectTestsPass("directory().read() fails", () { | |
| 295 test('test', () { | |
| 296 var dir = d.dir('dir', [d.file('name.txt', 'contents')]); | |
| 297 expect(dir.read().toList(), | |
| 298 throwsA(equals("Can't read the contents of 'dir': is a directory."))); | |
| 299 }); | |
| 300 }); | |
| 301 | |
| 302 expectTestsPass("directory().load() fails to load a nested directory", () { | 294 expectTestsPass("directory().load() fails to load a nested directory", () { |
| 303 test('test', () { | 295 test('test', () { |
| 304 var dir = d.dir('dir', [ | 296 var dir = d.dir('dir', [ |
| 305 d.dir('subdir', [ | 297 d.dir('subdir', [ |
| 306 d.file('name.txt', 'subcontents') | 298 d.file('name.txt', 'subcontents') |
| 307 ]), | 299 ]), |
| 308 d.file('name.txt', 'contents') | 300 d.file('name.txt', 'contents') |
| 309 ]); | 301 ]); |
| 310 | 302 |
| 311 expect(dir.load('subdir').toList(), | 303 expect(dir.load('subdir').toList(), |
| 312 throwsA(equals("Can't read the contents of 'subdir': is a " | 304 throwsA(equals("Couldn't find a readable entry named 'subdir' within " |
| 313 "directory."))); | 305 "'dir'."))); |
| 314 }); | 306 }); |
| 315 }); | 307 }); |
| 316 | 308 |
| 317 expectTestsPass("directory().load() fails to load an absolute path", () { | 309 expectTestsPass("directory().load() fails to load an absolute path", () { |
| 318 test('test', () { | 310 test('test', () { |
| 319 var dir = d.dir('dir', [d.file('name.txt', 'contents')]); | 311 var dir = d.dir('dir', [d.file('name.txt', 'contents')]); |
| 320 | 312 |
| 321 expect(dir.load('/name.txt').toList(), | 313 expect(dir.load('/name.txt').toList(), throwsArgumentError); |
| 322 throwsA(equals("Can't load absolute path '/name.txt'."))); | |
| 323 }); | 314 }); |
| 324 }); | 315 }); |
| 325 | 316 |
| 326 expectTestsPass("directory().load() fails to load '.', '..', or ''", () { | 317 expectTestsPass("directory().load() fails to load '.', '..', or ''", () { |
| 327 test('test', () { | 318 test('test', () { |
| 328 var dir = d.dir('dir', [d.file('name.txt', 'contents')]); | 319 var dir = d.dir('dir', [d.file('name.txt', 'contents')]); |
| 329 | 320 |
| 330 expect(dir.load('.').toList(), | 321 expect(dir.load('.').toList(), throwsArgumentError); |
| 331 throwsA(equals("Can't load '.' from within 'dir'."))); | |
| 332 | 322 |
| 333 expect(dir.load('..').toList(), | 323 expect(dir.load('..').toList(), throwsArgumentError); |
| 334 throwsA(equals("Can't load '..' from within 'dir'."))); | |
| 335 | 324 |
| 336 expect(dir.load('').toList(), | 325 expect(dir.load('').toList(), throwsArgumentError); |
| 337 throwsA(equals("Can't load '' from within 'dir'."))); | |
| 338 }); | 326 }); |
| 339 }); | 327 }); |
| 340 | 328 |
| 341 expectTestsPass("directory().load() fails to load a file that doesn't exist", | 329 expectTestsPass("directory().load() fails to load a file that doesn't exist", |
| 342 () { | 330 () { |
| 343 test('test', () { | 331 test('test', () { |
| 344 var dir = d.dir('dir', [d.file('name.txt', 'contents')]); | 332 var dir = d.dir('dir', [d.file('name.txt', 'contents')]); |
| 345 | 333 |
| 346 expect(dir.load('not-name.txt').toList(), | 334 expect(dir.load('not-name.txt').toList(), |
| 347 throwsA(equals("Couldn't find an entry named 'not-name.txt' within " | 335 throwsA(equals("Couldn't find a readable entry named 'not-name.txt' " |
| 348 "'dir'."))); | 336 "within 'dir'."))); |
| 349 }); | 337 }); |
| 350 }); | 338 }); |
| 351 | 339 |
| 352 expectTestsPass("directory().load() fails to load a file that exists " | 340 expectTestsPass("directory().load() fails to load a file that exists " |
| 353 "multiple times", () { | 341 "multiple times", () { |
| 354 test('test', () { | 342 test('test', () { |
| 355 var dir = d.dir('dir', [ | 343 var dir = d.dir('dir', [ |
| 356 d.file('name.txt', 'contents'), | 344 d.file('name.txt', 'contents'), |
| 357 d.file('name.txt', 'contents') | 345 d.file('name.txt', 'contents') |
| 358 ]); | 346 ]); |
| 359 | 347 |
| 360 expect(dir.load('name.txt').toList(), | 348 expect(dir.load('name.txt').toList(), |
| 361 throwsA(equals("Found multiple entries named 'name.txt' within " | 349 throwsA(equals("Found multiple readable entries named 'name.txt' " |
| 362 "'dir'."))); | 350 "within 'dir'."))); |
| 363 }); | 351 }); |
| 364 }); | 352 }); |
| 365 | 353 |
| 354 expectTestsPass("directory().load() loads a file next to a subdirectory with " |
| 355 "the same name", () { |
| 356 test('test', () { |
| 357 var dir = d.dir('dir', [ |
| 358 d.file('name', 'contents'), |
| 359 d.dir('name', [d.file('subfile', 'contents')]) |
| 360 ]); |
| 361 |
| 362 expect(byteStreamToString(dir.load('name')), |
| 363 completion(equals('contents'))); |
| 364 }); |
| 365 }); |
| 366 |
| 366 expectTestsPass("directory().describe() lists the contents of the directory", | 367 expectTestsPass("directory().describe() lists the contents of the directory", |
| 367 () { | 368 () { |
| 368 test('test', () { | 369 test('test', () { |
| 369 var dir = d.dir('dir', [ | 370 var dir = d.dir('dir', [ |
| 370 d.file('file1.txt', 'contents1'), | 371 d.file('file1.txt', 'contents1'), |
| 371 d.file('file2.txt', 'contents2') | 372 d.file('file2.txt', 'contents2') |
| 372 ]); | 373 ]); |
| 373 | 374 |
| 374 expect(dir.describe(), equals( | 375 expect(dir.describe(), equals( |
| 375 "dir\n" | 376 "dir\n" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 405 }); | 406 }); |
| 406 }); | 407 }); |
| 407 | 408 |
| 408 expectTestsPass("directory().describe() with no contents returns the " | 409 expectTestsPass("directory().describe() with no contents returns the " |
| 409 "directory name", () { | 410 "directory name", () { |
| 410 test('test', () { | 411 test('test', () { |
| 411 expect(d.dir('dir').describe(), equals('dir')); | 412 expect(d.dir('dir').describe(), equals('dir')); |
| 412 }); | 413 }); |
| 413 }); | 414 }); |
| 414 } | 415 } |
| OLD | NEW |