| 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 library descriptor_test; | 5 library descriptor_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import '../../../pkg/pathos/lib/path.dart' as path; | 10 import '../../../pkg/pathos/lib/path.dart' as path; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 d.file('name.txt', 'contents2').create(); | 39 d.file('name.txt', 'contents2').create(); |
| 40 | 40 |
| 41 schedule(() { | 41 schedule(() { |
| 42 expect(new File(path.join(sandbox, 'name.txt')).readAsString(), | 42 expect(new File(path.join(sandbox, 'name.txt')).readAsString(), |
| 43 completion(equals('contents2'))); | 43 completion(equals('contents2'))); |
| 44 }); | 44 }); |
| 45 }); | 45 }); |
| 46 }); | 46 }); |
| 47 | 47 |
| 48 expectTestsPass('file().create() with a RegExp name fails', () { | |
| 49 var errors; | |
| 50 test('test 1', () { | |
| 51 scheduleSandbox(); | |
| 52 | |
| 53 currentSchedule.onException.schedule(() { | |
| 54 errors = currentSchedule.errors; | |
| 55 }); | |
| 56 | |
| 57 d.file(new RegExp(r'name\.txt'), 'contents').create(); | |
| 58 }); | |
| 59 | |
| 60 test('test 2', () { | |
| 61 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
| 62 expect(errors.map((e) => e.error), equals([ | |
| 63 r"Pattern /name\.txt/ must be a string." | |
| 64 ]), verbose: true); | |
| 65 }); | |
| 66 }, passing: ['test 2']); | |
| 67 | |
| 68 expectTestsPass('file().validate() completes successfully if the filesystem ' | 48 expectTestsPass('file().validate() completes successfully if the filesystem ' |
| 69 'matches the descriptor', () { | 49 'matches the descriptor', () { |
| 70 test('test', () { | 50 test('test', () { |
| 71 scheduleSandbox(); | 51 scheduleSandbox(); |
| 72 | 52 |
| 73 schedule(() { | 53 schedule(() { |
| 74 return new File(path.join(sandbox, 'name.txt')) | 54 return new File(path.join(sandbox, 'name.txt')) |
| 75 .writeAsString('contents'); | 55 .writeAsString('contents'); |
| 76 }); | 56 }); |
| 77 | 57 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 }); | 101 }); |
| 122 | 102 |
| 123 test('test 2', () { | 103 test('test 2', () { |
| 124 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | 104 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
| 125 expect(errors.length, equals(1)); | 105 expect(errors.length, equals(1)); |
| 126 expect(errors.first.error, | 106 expect(errors.first.error, |
| 127 matches(r"^File not found: '[^']+[\\/]name\.txt'\.$")); | 107 matches(r"^File not found: '[^']+[\\/]name\.txt'\.$")); |
| 128 }); | 108 }); |
| 129 }, passing: ['test 2']); | 109 }, passing: ['test 2']); |
| 130 | 110 |
| 131 expectTestsPass('file().validate() with a RegExp completes successfully if ' | |
| 132 'the filesystem matches the descriptor', () { | |
| 133 test('test', () { | |
| 134 scheduleSandbox(); | |
| 135 | |
| 136 schedule(() { | |
| 137 return new File(path.join(sandbox, 'name.txt')) | |
| 138 .writeAsString('contents'); | |
| 139 }); | |
| 140 | |
| 141 d.file(new RegExp(r'na..\.txt'), 'contents').validate(); | |
| 142 }); | |
| 143 }); | |
| 144 | |
| 145 expectTestsPass("file().validate() with a RegExp fails if there's a file " | |
| 146 "with the wrong contents", () { | |
| 147 var errors; | |
| 148 test('test 1', () { | |
| 149 scheduleSandbox(); | |
| 150 | |
| 151 currentSchedule.onException.schedule(() { | |
| 152 errors = currentSchedule.errors; | |
| 153 }); | |
| 154 | |
| 155 schedule(() { | |
| 156 return new File(path.join(sandbox, 'name.txt')) | |
| 157 .writeAsString('some\nwrongtents'); | |
| 158 }); | |
| 159 | |
| 160 d.file(new RegExp(r'na..\.txt'), 'some\ncontents\nand stuff').validate(); | |
| 161 }); | |
| 162 | |
| 163 test('test 2', () { | |
| 164 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
| 165 expect(errors.map((e) => e.error), equals([ | |
| 166 "File 'name.txt' (matching /na..\\.txt/) should contain:\n" | |
| 167 "| some\n" | |
| 168 "| contents\n" | |
| 169 "| and stuff\n" | |
| 170 "but actually contained:\n" | |
| 171 "| some\n" | |
| 172 "X wrongtents\n" | |
| 173 "? and stuff" | |
| 174 ]), verbose: true); | |
| 175 }); | |
| 176 }, passing: ['test 2']); | |
| 177 | |
| 178 expectTestsPass("file().validate() with a RegExp fails if there's no " | |
| 179 "file", () { | |
| 180 var errors; | |
| 181 test('test 1', () { | |
| 182 scheduleSandbox(); | |
| 183 | |
| 184 currentSchedule.onException.schedule(() { | |
| 185 errors = currentSchedule.errors; | |
| 186 }); | |
| 187 | |
| 188 d.file(new RegExp(r'na..\.txt'), 'contents').validate(); | |
| 189 }); | |
| 190 | |
| 191 test('test 2', () { | |
| 192 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
| 193 expect(errors.length, equals(1)); | |
| 194 expect(errors.first.error, | |
| 195 matches(r"^No entry found in '[^']+' matching /na\.\.\\\.txt/\.$")); | |
| 196 }); | |
| 197 }, passing: ['test 2']); | |
| 198 | |
| 199 expectTestsPass("file().validate() with a RegExp fails if there are multiple " | |
| 200 "matching files", () { | |
| 201 var errors; | |
| 202 test('test 1', () { | |
| 203 scheduleSandbox(); | |
| 204 | |
| 205 currentSchedule.onException.schedule(() { | |
| 206 errors = currentSchedule.errors; | |
| 207 }); | |
| 208 | |
| 209 schedule(() { | |
| 210 return Future.wait([ | |
| 211 new File(path.join(sandbox, 'name.txt')).writeAsString('contents'), | |
| 212 new File(path.join(sandbox, 'nape.txt')).writeAsString('contents'), | |
| 213 new File(path.join(sandbox, 'nail.txt')).writeAsString('contents') | |
| 214 ]); | |
| 215 }); | |
| 216 | |
| 217 d.file(new RegExp(r'na..\.txt'), 'contents').validate(); | |
| 218 }); | |
| 219 | |
| 220 test('test 2', () { | |
| 221 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
| 222 expect(errors.length, equals(1)); | |
| 223 expect(errors.first.error, | |
| 224 matches( | |
| 225 r"^Multiple entries found in '[^']+' matching /na\.\.\\\.txt/:\n" | |
| 226 r"\* .*[\\/]nail\.txt\n" | |
| 227 r"\* .*[\\/]name\.txt\n" | |
| 228 r"\* .*[\\/]nape\.txt")); | |
| 229 }); | |
| 230 }, passing: ['test 2']); | |
| 231 | |
| 232 expectTestsPass("file().read() returns the contents of the file as a stream", | 111 expectTestsPass("file().read() returns the contents of the file as a stream", |
| 233 () { | 112 () { |
| 234 test('test', () { | 113 test('test', () { |
| 235 expect(byteStreamToString(d.file('name.txt', 'contents').read()), | 114 expect(byteStreamToString(d.file('name.txt', 'contents').read()), |
| 236 completion(equals('contents'))); | 115 completion(equals('contents'))); |
| 237 }); | 116 }); |
| 238 }); | 117 }); |
| 239 | 118 |
| 240 expectTestsPass("file().load() throws an error", () { | 119 expectTestsPass("file().load() throws an error", () { |
| 241 test('test', () { | 120 test('test', () { |
| 242 expect(d.file('name.txt', 'contents').load('path').toList(), | 121 expect(d.file('name.txt', 'contents').load('path').toList(), |
| 243 throwsA(equals("Can't load 'path' from within 'name.txt': not a " | 122 throwsA(equals("Can't load 'path' from within 'name.txt': not a " |
| 244 "directory."))); | 123 "directory."))); |
| 245 }); | 124 }); |
| 246 }); | 125 }); |
| 247 | 126 |
| 248 expectTestsPass("file().describe() returns the filename", () { | 127 expectTestsPass("file().describe() returns the filename", () { |
| 249 test('test', () { | 128 test('test', () { |
| 250 expect(d.file('name.txt', 'contents').describe(), equals('name.txt')); | 129 expect(d.file('name.txt', 'contents').describe(), equals('name.txt')); |
| 251 }); | 130 }); |
| 252 }); | 131 }); |
| 253 | 132 |
| 254 expectTestsPass("file().describe() with a RegExp describes the file", () { | |
| 255 test('test', () { | |
| 256 expect(d.file(new RegExp(r'na..\.txt'), 'contents').describe(), | |
| 257 equals(r'file matching /na..\.txt/')); | |
| 258 }); | |
| 259 }); | |
| 260 | |
| 261 expectTestsPass('binaryFile().create() creates a file', () { | 133 expectTestsPass('binaryFile().create() creates a file', () { |
| 262 test('test', () { | 134 test('test', () { |
| 263 scheduleSandbox(); | 135 scheduleSandbox(); |
| 264 | 136 |
| 265 d.binaryFile('name.bin', [1, 2, 3, 4, 5]).create(); | 137 d.binaryFile('name.bin', [1, 2, 3, 4, 5]).create(); |
| 266 | 138 |
| 267 schedule(() { | 139 schedule(() { |
| 268 expect(new File(path.join(sandbox, 'name.bin')).readAsBytes(), | 140 expect(new File(path.join(sandbox, 'name.bin')).readAsBytes(), |
| 269 completion(equals([1, 2, 3, 4, 5]))); | 141 completion(equals([1, 2, 3, 4, 5]))); |
| 270 }); | 142 }); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 d.dir('dir').create(); | 220 d.dir('dir').create(); |
| 349 d.dir('dir', [d.file('name.txt', 'contents')]).create(); | 221 d.dir('dir', [d.file('name.txt', 'contents')]).create(); |
| 350 | 222 |
| 351 schedule(() { | 223 schedule(() { |
| 352 expect(new File(path.join(sandbox, 'dir', 'name.txt')).readAsString(), | 224 expect(new File(path.join(sandbox, 'dir', 'name.txt')).readAsString(), |
| 353 completion(equals('contents'))); | 225 completion(equals('contents'))); |
| 354 }); | 226 }); |
| 355 }); | 227 }); |
| 356 }); | 228 }); |
| 357 | 229 |
| 358 expectTestsPass("directory().create() with a RegExp name fails", () { | |
| 359 var errors; | |
| 360 test('test 1', () { | |
| 361 scheduleSandbox(); | |
| 362 | |
| 363 currentSchedule.onException.schedule(() { | |
| 364 errors = currentSchedule.errors; | |
| 365 }); | |
| 366 | |
| 367 d.dir(new RegExp('dir')).create(); | |
| 368 }); | |
| 369 | |
| 370 test('test 2', () { | |
| 371 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
| 372 expect(errors.map((e) => e.error), equals([ | |
| 373 "Pattern /dir/ must be a string." | |
| 374 ]), verbose: true); | |
| 375 }); | |
| 376 }, passing: ['test 2']); | |
| 377 | |
| 378 expectTestsPass("directory().validate() completes successfully if the " | 230 expectTestsPass("directory().validate() completes successfully if the " |
| 379 "filesystem matches the descriptor", () { | 231 "filesystem matches the descriptor", () { |
| 380 test('test', () { | 232 test('test', () { |
| 381 scheduleSandbox(); | 233 scheduleSandbox(); |
| 382 | 234 |
| 383 schedule(() { | 235 schedule(() { |
| 384 var dirPath = path.join(sandbox, 'dir'); | 236 var dirPath = path.join(sandbox, 'dir'); |
| 385 var subdirPath = path.join(dirPath, 'subdir'); | 237 var subdirPath = path.join(dirPath, 'subdir'); |
| 386 return new Directory(subdirPath).create(recursive: true).then((_) { | 238 return new Directory(subdirPath).create(recursive: true).then((_) { |
| 387 return Future.wait([ | 239 return Future.wait([ |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | 383 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
| 532 expect(errors.map((e) => e.error), equals([ | 384 expect(errors.map((e) => e.error), equals([ |
| 533 "File 'subfile1.txt' should contain:\n" | 385 "File 'subfile1.txt' should contain:\n" |
| 534 "| subcontents1\n" | 386 "| subcontents1\n" |
| 535 "but actually contained:\n" | 387 "but actually contained:\n" |
| 536 "X wrongtents1" | 388 "X wrongtents1" |
| 537 ])); | 389 ])); |
| 538 }); | 390 }); |
| 539 }, passing: ['test 2']); | 391 }, passing: ['test 2']); |
| 540 | 392 |
| 541 expectTestsPass("directory().validate() with a RegExp completes successfully " | |
| 542 "if the filesystem matches the descriptor", () { | |
| 543 test('test', () { | |
| 544 scheduleSandbox(); | |
| 545 | |
| 546 schedule(() { | |
| 547 var dirPath = path.join(sandbox, 'dir'); | |
| 548 var subdirPath = path.join(dirPath, 'subdir'); | |
| 549 return new Directory(subdirPath).create(recursive: true).then((_) { | |
| 550 return Future.wait([ | |
| 551 new File(path.join(dirPath, 'file1.txt')) | |
| 552 .writeAsString('contents1'), | |
| 553 new File(path.join(dirPath, 'file2.txt')) | |
| 554 .writeAsString('contents2'), | |
| 555 new File(path.join(subdirPath, 'subfile1.txt')) | |
| 556 .writeAsString('subcontents1'), | |
| 557 new File(path.join(subdirPath, 'subfile2.txt')) | |
| 558 .writeAsString('subcontents2') | |
| 559 ]); | |
| 560 }); | |
| 561 }); | |
| 562 | |
| 563 d.dir(new RegExp('d.r'), [ | |
| 564 d.dir('subdir', [ | |
| 565 d.file('subfile1.txt', 'subcontents1'), | |
| 566 d.file('subfile2.txt', 'subcontents2') | |
| 567 ]), | |
| 568 d.file('file1.txt', 'contents1'), | |
| 569 d.file('file2.txt', 'contents2') | |
| 570 ]).validate(); | |
| 571 }); | |
| 572 }); | |
| 573 | |
| 574 expectTestsPass("directory().validate() with a RegExp fails if there's a dir " | |
| 575 "with the wrong contents", () { | |
| 576 var errors; | |
| 577 test('test 1', () { | |
| 578 scheduleSandbox(); | |
| 579 | |
| 580 currentSchedule.onException.schedule(() { | |
| 581 errors = currentSchedule.errors; | |
| 582 }); | |
| 583 | |
| 584 schedule(() { | |
| 585 var dirPath = path.join(sandbox, 'dir'); | |
| 586 var subdirPath = path.join(dirPath, 'subdir'); | |
| 587 return new Directory(subdirPath).create(recursive: true).then((_) { | |
| 588 return Future.wait([ | |
| 589 new File(path.join(dirPath, 'file1.txt')) | |
| 590 .writeAsString('contents1'), | |
| 591 new File(path.join(subdirPath, 'subfile1.txt')) | |
| 592 .writeAsString('subcontents1'), | |
| 593 new File(path.join(subdirPath, 'subfile2.txt')) | |
| 594 .writeAsString('subcontents2') | |
| 595 ]); | |
| 596 }); | |
| 597 }); | |
| 598 | |
| 599 d.dir(new RegExp('d.r'), [ | |
| 600 d.dir('subdir', [ | |
| 601 d.file('subfile1.txt', 'subcontents1'), | |
| 602 d.file('subfile2.txt', 'subcontents2') | |
| 603 ]), | |
| 604 d.file('file1.txt', 'contents1'), | |
| 605 d.file('file2.txt', 'contents2') | |
| 606 ]).validate(); | |
| 607 }); | |
| 608 | |
| 609 test('test 2', () { | |
| 610 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
| 611 expect(errors.length, equals(1)); | |
| 612 expect(errors.first.error, | |
| 613 matches(r"^File not found: '[^']+[\\/]dir[\\/]file2\.txt'\.$")); | |
| 614 }); | |
| 615 }, passing: ['test 2']); | |
| 616 | |
| 617 expectTestsPass("directory().validate() with a RegExp fails if there's no " | |
| 618 "dir", () { | |
| 619 var errors; | |
| 620 test('test 1', () { | |
| 621 scheduleSandbox(); | |
| 622 | |
| 623 currentSchedule.onException.schedule(() { | |
| 624 errors = currentSchedule.errors; | |
| 625 }); | |
| 626 | |
| 627 d.dir(new RegExp('d.r'), [ | |
| 628 d.dir('subdir', [ | |
| 629 d.file('subfile1.txt', 'subcontents1'), | |
| 630 d.file('subfile2.txt', 'subcontents2') | |
| 631 ]), | |
| 632 d.file('file1.txt', 'contents1'), | |
| 633 d.file('file2.txt', 'contents2') | |
| 634 ]).validate(); | |
| 635 }); | |
| 636 | |
| 637 test('test 2', () { | |
| 638 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
| 639 expect(errors.length, equals(1)); | |
| 640 expect(errors.first.error, | |
| 641 matches(r"^No entry found in '[^']+' matching /d\.r/\.$")); | |
| 642 }); | |
| 643 }, passing: ['test 2']); | |
| 644 | |
| 645 expectTestsPass("directory().validate() with a RegExp fails if there are " | |
| 646 "multiple matching dirs", () { | |
| 647 var errors; | |
| 648 test('test 1', () { | |
| 649 scheduleSandbox(); | |
| 650 | |
| 651 currentSchedule.onException.schedule(() { | |
| 652 errors = currentSchedule.errors; | |
| 653 }); | |
| 654 | |
| 655 schedule(() { | |
| 656 return Future.wait(['dir', 'dar', 'dor'].map((dir) { | |
| 657 var dirPath = path.join(sandbox, dir); | |
| 658 var subdirPath = path.join(dirPath, 'subdir'); | |
| 659 return new Directory(subdirPath).create(recursive: true).then((_) { | |
| 660 return Future.wait([ | |
| 661 new File(path.join(dirPath, 'file1.txt')) | |
| 662 .writeAsString('contents1'), | |
| 663 new File(path.join(dirPath, 'file2.txt')) | |
| 664 .writeAsString('contents2'), | |
| 665 new File(path.join(subdirPath, 'subfile1.txt')) | |
| 666 .writeAsString('subcontents1'), | |
| 667 new File(path.join(subdirPath, 'subfile2.txt')) | |
| 668 .writeAsString('subcontents2') | |
| 669 ]); | |
| 670 }); | |
| 671 })); | |
| 672 }); | |
| 673 | |
| 674 d.dir(new RegExp('d.r'), [ | |
| 675 d.dir('subdir', [ | |
| 676 d.file('subfile1.txt', 'subcontents1'), | |
| 677 d.file('subfile2.txt', 'subcontents2') | |
| 678 ]), | |
| 679 d.file('file1.txt', 'contents1'), | |
| 680 d.file('file2.txt', 'contents2') | |
| 681 ]).validate(); | |
| 682 }); | |
| 683 | |
| 684 test('test 2', () { | |
| 685 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
| 686 expect(errors.length, equals(1)); | |
| 687 expect(errors.first.error, | |
| 688 matches( | |
| 689 r"^Multiple entries found in '[^']+' matching /d\.r/:\n" | |
| 690 r"\* .*[\\/]dar\n" | |
| 691 r"\* .*[\\/]dir\n" | |
| 692 r"\* .*[\\/]dor")); | |
| 693 }); | |
| 694 }, passing: ['test 2']); | |
| 695 | |
| 696 expectTestsPass("directory().load() loads a file", () { | 393 expectTestsPass("directory().load() loads a file", () { |
| 697 test('test', () { | 394 test('test', () { |
| 698 var dir = d.dir('dir', [d.file('name.txt', 'contents')]); | 395 var dir = d.dir('dir', [d.file('name.txt', 'contents')]); |
| 699 expect(byteStreamToString(dir.load('name.txt')), | 396 expect(byteStreamToString(dir.load('name.txt')), |
| 700 completion(equals('contents'))); | 397 completion(equals('contents'))); |
| 701 }); | 398 }); |
| 702 }); | 399 }); |
| 703 | 400 |
| 704 expectTestsPass("directory().load() loads a deeply-nested file", () { | 401 expectTestsPass("directory().load() loads a deeply-nested file", () { |
| 705 test('test', () { | 402 test('test', () { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 throwsA(equals("Can't load '.' from within 'dir'."))); | 452 throwsA(equals("Can't load '.' from within 'dir'."))); |
| 756 | 453 |
| 757 expect(dir.load('..').toList(), | 454 expect(dir.load('..').toList(), |
| 758 throwsA(equals("Can't load '..' from within 'dir'."))); | 455 throwsA(equals("Can't load '..' from within 'dir'."))); |
| 759 | 456 |
| 760 expect(dir.load('').toList(), | 457 expect(dir.load('').toList(), |
| 761 throwsA(equals("Can't load '' from within 'dir'."))); | 458 throwsA(equals("Can't load '' from within 'dir'."))); |
| 762 }); | 459 }); |
| 763 }); | 460 }); |
| 764 | 461 |
| 765 expectTestsPass("directory().load() fails to load a file with a RegExp name", | |
| 766 () { | |
| 767 test('test', () { | |
| 768 var dir = d.dir('dir', [d.file(new RegExp(r'name\.txt'), 'contents')]); | |
| 769 | |
| 770 expect(dir.load('name.txt').toList(), | |
| 771 throwsA(equals(r"Pattern /name\.txt/ must be a string."))); | |
| 772 }); | |
| 773 }); | |
| 774 | |
| 775 expectTestsPass("directory().load() fails to load a file that doesn't exist", | 462 expectTestsPass("directory().load() fails to load a file that doesn't exist", |
| 776 () { | 463 () { |
| 777 test('test', () { | 464 test('test', () { |
| 778 var dir = d.dir('dir', [d.file('name.txt', 'contents')]); | 465 var dir = d.dir('dir', [d.file('name.txt', 'contents')]); |
| 779 | 466 |
| 780 expect(dir.load('not-name.txt').toList(), | 467 expect(dir.load('not-name.txt').toList(), |
| 781 throwsA(equals("Couldn't find an entry named 'not-name.txt' within " | 468 throwsA(equals("Couldn't find an entry named 'not-name.txt' within " |
| 782 "'dir'."))); | 469 "'dir'."))); |
| 783 }); | 470 }); |
| 784 }); | 471 }); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 795 throwsA(equals("Found multiple entries named 'name.txt' within " | 482 throwsA(equals("Found multiple entries named 'name.txt' within " |
| 796 "'dir'."))); | 483 "'dir'."))); |
| 797 }); | 484 }); |
| 798 }); | 485 }); |
| 799 | 486 |
| 800 expectTestsPass("directory().describe() lists the contents of the directory", | 487 expectTestsPass("directory().describe() lists the contents of the directory", |
| 801 () { | 488 () { |
| 802 test('test', () { | 489 test('test', () { |
| 803 var dir = d.dir('dir', [ | 490 var dir = d.dir('dir', [ |
| 804 d.file('file1.txt', 'contents1'), | 491 d.file('file1.txt', 'contents1'), |
| 805 d.file('file2.txt', 'contents2'), | 492 d.file('file2.txt', 'contents2') |
| 806 d.file(new RegExp(r're\.txt'), 're-contents') | |
| 807 ]); | 493 ]); |
| 808 | 494 |
| 809 expect(dir.describe(), equals( | 495 expect(dir.describe(), equals( |
| 810 "dir\n" | 496 "dir\n" |
| 811 "|-- file1.txt\n" | 497 "|-- file1.txt\n" |
| 812 "|-- file2.txt\n" | 498 "'-- file2.txt")); |
| 813 "'-- file matching /re\\.txt/")); | |
| 814 }); | 499 }); |
| 815 }); | 500 }); |
| 816 | 501 |
| 817 expectTestsPass("directory().describe() lists the contents of nested " | 502 expectTestsPass("directory().describe() lists the contents of nested " |
| 818 "directories", () { | 503 "directories", () { |
| 819 test('test', () { | 504 test('test', () { |
| 820 var dir = d.dir('dir', [ | 505 var dir = d.dir('dir', [ |
| 821 d.file('file1.txt', 'contents1'), | 506 d.file('file1.txt', 'contents1'), |
| 822 d.dir('subdir', [ | 507 d.dir('subdir', [ |
| 823 d.file('subfile1.txt', 'subcontents1'), | 508 d.file('subfile1.txt', 'subcontents1'), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 834 "|-- file1.txt\n" | 519 "|-- file1.txt\n" |
| 835 "|-- subdir\n" | 520 "|-- subdir\n" |
| 836 "| |-- subfile1.txt\n" | 521 "| |-- subfile1.txt\n" |
| 837 "| |-- subfile2.txt\n" | 522 "| |-- subfile2.txt\n" |
| 838 "| '-- subsubdir\n" | 523 "| '-- subsubdir\n" |
| 839 "| '-- subsubfile.txt\n" | 524 "| '-- subsubfile.txt\n" |
| 840 "'-- file2.txt")); | 525 "'-- file2.txt")); |
| 841 }); | 526 }); |
| 842 }); | 527 }); |
| 843 | 528 |
| 844 expectTestsPass("directory().describe() with a RegExp describes the " | |
| 845 "directory", () { | |
| 846 test('test', () { | |
| 847 var dir = d.dir(new RegExp(r'd.r'), [ | |
| 848 d.file('file1.txt', 'contents1'), | |
| 849 d.file('file2.txt', 'contents2') | |
| 850 ]); | |
| 851 | |
| 852 expect(dir.describe(), equals( | |
| 853 "directory matching /d.r/\n" | |
| 854 "|-- file1.txt\n" | |
| 855 "'-- file2.txt")); | |
| 856 }); | |
| 857 }); | |
| 858 | |
| 859 expectTestsPass("directory().describe() with no contents returns the " | 529 expectTestsPass("directory().describe() with no contents returns the " |
| 860 "directory name", () { | 530 "directory name", () { |
| 861 test('test', () { | 531 test('test', () { |
| 862 expect(d.dir('dir').describe(), equals('dir')); | 532 expect(d.dir('dir').describe(), equals('dir')); |
| 863 }); | 533 }); |
| 864 }); | 534 }); |
| 865 | 535 |
| 866 expectTestsPass("async().create() forwards to file().create", () { | 536 expectTestsPass("async().create() forwards to file().create", () { |
| 867 test('test', () { | 537 test('test', () { |
| 868 scheduleSandbox(); | 538 scheduleSandbox(); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 matches(r"^Directory not found: '[^']+[\\/]dir'\.$")); | 639 matches(r"^Directory not found: '[^']+[\\/]dir'\.$")); |
| 970 }); | 640 }); |
| 971 }, passing: ['test 2']); | 641 }, passing: ['test 2']); |
| 972 | 642 |
| 973 expectTestsPass("async().load() fails", () { | 643 expectTestsPass("async().load() fails", () { |
| 974 test('test', () { | 644 test('test', () { |
| 975 scheduleSandbox(); | 645 scheduleSandbox(); |
| 976 | 646 |
| 977 expect(d.async(new Future.immediate(d.file('name.txt'))) | 647 expect(d.async(new Future.immediate(d.file('name.txt'))) |
| 978 .load('path').toList(), | 648 .load('path').toList(), |
| 979 throwsA(equals("Async descriptors don't support load()."))); | 649 throwsA(equals("AsyncDescriptors don't support load()."))); |
| 980 }); | 650 }); |
| 981 }); | 651 }); |
| 982 | 652 |
| 983 expectTestsPass("async().read() fails", () { | 653 expectTestsPass("async().read() fails", () { |
| 984 test('test', () { | 654 test('test', () { |
| 985 scheduleSandbox(); | 655 scheduleSandbox(); |
| 986 | 656 |
| 987 expect(d.async(new Future.immediate(d.file('name.txt'))).read().toList(), | 657 expect(d.async(new Future.immediate(d.file('name.txt'))).read().toList(), |
| 988 throwsA(equals("Async descriptors don't support read()."))); | 658 throwsA(equals("AsyncDescriptors don't support read()."))); |
| 989 }); | 659 }); |
| 990 }); | 660 }); |
| 991 | 661 |
| 992 expectTestsPass("nothing().create() does nothing", () { | 662 expectTestsPass("nothing().create() does nothing", () { |
| 993 test('test', () { | 663 test('test', () { |
| 994 scheduleSandbox(); | 664 scheduleSandbox(); |
| 995 | 665 |
| 996 d.nothing('foo').create(); | 666 d.nothing('foo').create(); |
| 997 | 667 |
| 998 schedule(() { | 668 schedule(() { |
| 999 expect(new File(path.join(sandbox, 'foo')).exists(), | 669 expect(new File(path.join(sandbox, 'foo')).exists(), |
| 1000 completion(isFalse)); | 670 completion(isFalse)); |
| 1001 }); | 671 }); |
| 1002 | 672 |
| 1003 schedule(() { | 673 schedule(() { |
| 1004 expect(new Directory(path.join(sandbox, 'foo')).exists(), | 674 expect(new Directory(path.join(sandbox, 'foo')).exists(), |
| 1005 completion(isFalse)); | 675 completion(isFalse)); |
| 1006 }); | 676 }); |
| 1007 }); | 677 }); |
| 1008 }); | 678 }); |
| 1009 | 679 |
| 1010 expectTestsPass("nothing().validate() succeeds if nothing's there", () { | 680 expectTestsPass("nothing().validate() succeeds if nothing's there", () { |
| 1011 test('test', () { | 681 test('test', () { |
| 1012 scheduleSandbox(); | 682 scheduleSandbox(); |
| 1013 | 683 |
| 1014 d.nothing('foo').validate(); | 684 d.nothing('foo').validate(); |
| 1015 }); | 685 }); |
| 1016 }); | 686 }); |
| 1017 | 687 |
| 1018 expectTestsPass("nothing().validate() with a RegExp succeeds if nothing's " | |
| 1019 "there", () { | |
| 1020 test('test', () { | |
| 1021 scheduleSandbox(); | |
| 1022 | |
| 1023 d.nothing(new RegExp('f.o')).validate(); | |
| 1024 }); | |
| 1025 }); | |
| 1026 | |
| 1027 expectTestsPass("nothing().validate() fails if there's a file", () { | 688 expectTestsPass("nothing().validate() fails if there's a file", () { |
| 1028 var errors; | 689 var errors; |
| 1029 test('test 1', () { | 690 test('test 1', () { |
| 1030 scheduleSandbox(); | 691 scheduleSandbox(); |
| 1031 | 692 |
| 1032 currentSchedule.onException.schedule(() { | 693 currentSchedule.onException.schedule(() { |
| 1033 errors = currentSchedule.errors; | 694 errors = currentSchedule.errors; |
| 1034 }); | 695 }); |
| 1035 | 696 |
| 1036 d.file('name.txt', 'contents').create(); | 697 d.file('name.txt', 'contents').create(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1061 | 722 |
| 1062 test('test 2', () { | 723 test('test 2', () { |
| 1063 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | 724 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
| 1064 expect(errors.length, equals(1)); | 725 expect(errors.length, equals(1)); |
| 1065 expect(errors.first.error, | 726 expect(errors.first.error, |
| 1066 matches(r"^Expected nothing to exist at '[^']+[\\/]dir', but found a " | 727 matches(r"^Expected nothing to exist at '[^']+[\\/]dir', but found a " |
| 1067 r"directory\.$")); | 728 r"directory\.$")); |
| 1068 }); | 729 }); |
| 1069 }, passing: ['test 2']); | 730 }, passing: ['test 2']); |
| 1070 | 731 |
| 1071 expectTestsPass("nothing().validate() with a RegExp fails if there are " | 732 expectTestsPass("nothing().load() fails", () { |
| 1072 "multiple entries", () { | 733 test('test', () { |
| 734 scheduleSandbox(); |
| 735 |
| 736 expect(d.nothing('name.txt').load('path').toList(), |
| 737 throwsA(equals("Nothing descriptors don't support load()."))); |
| 738 }); |
| 739 }); |
| 740 |
| 741 expectTestsPass("nothing().read() fails", () { |
| 742 test('test', () { |
| 743 scheduleSandbox(); |
| 744 |
| 745 expect(d.nothing('name.txt').read().toList(), |
| 746 throwsA(equals("Nothing descriptors don't support read()."))); |
| 747 }); |
| 748 }); |
| 749 |
| 750 expectTestsPass("pattern().validate() succeeds if there's a file matching " |
| 751 "the pattern and the child entry", () { |
| 752 test('test', () { |
| 753 scheduleSandbox(); |
| 754 |
| 755 d.file('foo', 'blap').create(); |
| 756 |
| 757 d.filePattern(new RegExp(r'f..'), 'blap').validate(); |
| 758 }); |
| 759 }); |
| 760 |
| 761 expectTestsPass("pattern().validate() succeeds if there's a dir matching " |
| 762 "the pattern and the child entry", () { |
| 763 test('test', () { |
| 764 scheduleSandbox(); |
| 765 |
| 766 d.dir('foo', [ |
| 767 d.file('bar', 'baz') |
| 768 ]).create(); |
| 769 |
| 770 d.dirPattern(new RegExp(r'f..'), [ |
| 771 d.file('bar', 'baz') |
| 772 ]).validate(); |
| 773 }); |
| 774 }); |
| 775 |
| 776 expectTestsPass("pattern().validate() succeeds if there's multiple files " |
| 777 "matching the pattern but only one matching the child entry", () { |
| 778 test('test', () { |
| 779 scheduleSandbox(); |
| 780 |
| 781 d.file('foo', 'blap').create(); |
| 782 d.file('fee', 'blak').create(); |
| 783 d.file('faa', 'blut').create(); |
| 784 |
| 785 d.filePattern(new RegExp(r'f..'), 'blap').validate(); |
| 786 }); |
| 787 }); |
| 788 |
| 789 expectTestsPass("pattern().validate() fails if there's no file matching the " |
| 790 "pattern", () { |
| 1073 var errors; | 791 var errors; |
| 1074 test('test 1', () { | 792 test('test 1', () { |
| 1075 scheduleSandbox(); | 793 scheduleSandbox(); |
| 794 |
| 795 currentSchedule.onException.schedule(() { |
| 796 errors = currentSchedule.errors; |
| 797 }); |
| 798 |
| 799 d.filePattern(new RegExp(r'f..'), 'bar').validate(); |
| 800 }); |
| 801 |
| 802 test('test 2', () { |
| 803 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
| 804 expect(errors.length, equals(1)); |
| 805 expect(errors.first.error, |
| 806 matches(r"^No entry found in '[^']+' matching /f\.\./\.$")); |
| 807 }); |
| 808 }, passing: ['test 2']); |
| 809 |
| 810 expectTestsPass("pattern().validate() fails if there's a file matching the " |
| 811 "pattern but not the entry", () { |
| 812 var errors; |
| 813 test('test 1', () { |
| 814 scheduleSandbox(); |
| 1076 | 815 |
| 1077 currentSchedule.onException.schedule(() { | 816 currentSchedule.onException.schedule(() { |
| 1078 errors = currentSchedule.errors; | 817 errors = currentSchedule.errors; |
| 1079 }); | 818 }); |
| 1080 | 819 |
| 1081 d.dir('foo').create(); | 820 d.file('foo', 'bap').create(); |
| 1082 d.file('faa', 'contents').create(); | 821 d.filePattern(new RegExp(r'f..'), 'bar').validate(); |
| 1083 d.file('not-foo', 'contents').create(); | |
| 1084 d.nothing(new RegExp(r'^f..$')).validate(); | |
| 1085 }); | 822 }); |
| 1086 | 823 |
| 1087 test('test 2', () { | 824 test('test 2', () { |
| 1088 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | 825 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
| 1089 expect(errors.length, equals(1)); | 826 expect(errors.length, equals(1)); |
| 1090 expect(errors.first.error, | 827 expect(errors.first.error, |
| 1091 matches(r"^Expected nothing to exist in '[^']+' matching " | 828 matches(r"^Caught error\n" |
| 1092 r"/\^f\.\.\$/, but found:\n" | 829 r"| File 'foo' should contain:\n" |
| 1093 r"\* .*[\\/]faa\n" | 830 r"| | bar\n" |
| 1094 r"\* .*[\\/]foo$")); | 831 r"| but actually contained:\n" |
| 832 r"| X bap\n" |
| 833 r"while validating\n" |
| 834 r"| foo$")); |
| 1095 }); | 835 }); |
| 1096 }, passing: ['test 2']); | 836 }, passing: ['test 2']); |
| 1097 | 837 |
| 1098 expectTestsPass("nothing().load() fails", () { | 838 expectTestsPass("pattern().validate() fails if there's a dir matching the " |
| 1099 test('test', () { | 839 "pattern but not the entry", () { |
| 840 var errors; |
| 841 test('test 1', () { |
| 1100 scheduleSandbox(); | 842 scheduleSandbox(); |
| 1101 | 843 |
| 1102 expect(d.nothing('name.txt').load('path').toList(), | 844 currentSchedule.onException.schedule(() { |
| 1103 throwsA(equals("Nothing descriptors don't support load()."))); | 845 errors = currentSchedule.errors; |
| 846 }); |
| 847 |
| 848 d.dir('foo', [ |
| 849 d.file('bar', 'bap') |
| 850 ]).create(); |
| 851 |
| 852 d.dirPattern(new RegExp(r'f..'), [ |
| 853 d.file('bar', 'baz') |
| 854 ]).validate(); |
| 1104 }); | 855 }); |
| 1105 }); | |
| 1106 | 856 |
| 1107 expectTestsPass("nothing().read() fails", () { | 857 test('test 2', () { |
| 1108 test('test', () { | 858 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
| 859 expect(errors.length, equals(1)); |
| 860 expect(errors.first.error, |
| 861 matches(r"^Caught error\n" |
| 862 r"| File 'bar' should contain:\n" |
| 863 r"| | baz\n" |
| 864 r"| but actually contained:\n" |
| 865 r"| X bap" |
| 866 r"while validating\n" |
| 867 r"| foo\n" |
| 868 r"| '-- bar$")); |
| 869 }); |
| 870 }, passing: ['test 2']); |
| 871 |
| 872 expectTestsPass("pattern().validate() fails if there's multiple files " |
| 873 "matching the pattern and the child entry", () { |
| 874 var errors; |
| 875 test('test 1', () { |
| 1109 scheduleSandbox(); | 876 scheduleSandbox(); |
| 1110 | 877 |
| 1111 expect(d.nothing('name.txt').read().toList(), | 878 currentSchedule.onException.schedule(() { |
| 1112 throwsA(equals("Nothing descriptors don't support read()."))); | 879 errors = currentSchedule.errors; |
| 880 }); |
| 881 |
| 882 d.file('foo', 'bar').create(); |
| 883 d.file('fee', 'bar').create(); |
| 884 d.file('faa', 'bar').create(); |
| 885 d.filePattern(new RegExp(r'f..'), 'bar').validate(); |
| 1113 }); | 886 }); |
| 1114 }); | 887 |
| 888 test('test 2', () { |
| 889 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
| 890 expect(errors.length, equals(1)); |
| 891 expect(errors.first.error, matches( |
| 892 r"^Multiple valid entries found in '[^']+' matching " |
| 893 r"\/f\.\./:\n" |
| 894 r"\* faa\n" |
| 895 r"\* fee\n" |
| 896 r"\* foo$")); |
| 897 }); |
| 898 }, passing: ['test 2']); |
| 1115 } | 899 } |
| 1116 | 900 |
| 1117 void scheduleSandbox() { | 901 void scheduleSandbox() { |
| 1118 schedule(() { | 902 schedule(() { |
| 1119 return new Directory('').createTemp().then((dir) { | 903 return new Directory('').createTemp().then((dir) { |
| 1120 sandbox = dir.path; | 904 sandbox = dir.path; |
| 1121 d.defaultRoot = sandbox; | 905 d.defaultRoot = sandbox; |
| 1122 }); | 906 }); |
| 1123 }); | 907 }); |
| 1124 | 908 |
| 1125 currentSchedule.onComplete.schedule(() { | 909 currentSchedule.onComplete.schedule(() { |
| 1126 d.defaultRoot = null; | 910 d.defaultRoot = null; |
| 1127 if (sandbox == null) return; | 911 if (sandbox == null) return; |
| 1128 var oldSandbox = sandbox; | 912 var oldSandbox = sandbox; |
| 1129 sandbox = null; | 913 sandbox = null; |
| 1130 return new Directory(oldSandbox).delete(recursive: true); | 914 return new Directory(oldSandbox).delete(recursive: true); |
| 1131 }); | 915 }); |
| 1132 } | 916 } |
| 1133 | 917 |
| 1134 Future<List<int>> byteStreamToList(Stream<List<int>> stream) { | 918 Future<List<int>> byteStreamToList(Stream<List<int>> stream) { |
| 1135 return stream.reduce(<int>[], (buffer, chunk) { | 919 return stream.reduce(<int>[], (buffer, chunk) { |
| 1136 buffer.addAll(chunk); | 920 buffer.addAll(chunk); |
| 1137 return buffer; | 921 return buffer; |
| 1138 }); | 922 }); |
| 1139 } | 923 } |
| 1140 | 924 |
| 1141 Future<String> byteStreamToString(Stream<List<int>> stream) => | 925 Future<String> byteStreamToString(Stream<List<int>> stream) => |
| 1142 byteStreamToList(stream).then((bytes) => new String.fromCharCodes(bytes)); | 926 byteStreamToList(stream).then((bytes) => new String.fromCharCodes(bytes)); |
| OLD | NEW |