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 /// A library for declaratively describing a filesystem structure, usually for |
| 6 /// the purpose of creating or validating it as part of a scheduled test. |
| 7 /// |
| 8 /// You can use [dir] and [file] to define a filesystem structure. Then, you can |
| 9 /// call [Entry.create] to schedule a task that will create that structure on |
| 10 /// the physical filesystem, or [Entry.validate] to schedule an assertion that |
| 11 /// that structure exists. For example: |
| 12 /// |
| 13 /// import 'package:scheduled_test/descriptor.dart' as d; |
| 14 /// import 'package:scheduled_test/scheduled_test.dart'; |
| 15 /// |
| 16 /// void main() { |
| 17 /// test('Directory.rename', () { |
| 18 /// d.dir('parent', [ |
| 19 /// d.file('sibling', 'sibling-contents'), |
| 20 /// d.dir('old-name', [ |
| 21 /// d.file('child', 'child-contents') |
| 22 /// ]) |
| 23 /// ]).create(); |
| 24 /// |
| 25 /// schedule(() => |
| 26 /// new Directory('parent/old-name').rename('parent/new-name')); |
| 27 /// |
| 28 /// d.dir('parent', [ |
| 29 /// d.file('sibling', 'sibling-contents'), |
| 30 /// d.dir('new-name', [ |
| 31 /// d.file('child', 'child-contents') |
| 32 /// ]) |
| 33 /// ]).validate(); |
| 34 /// }) |
| 35 /// } |
| 36 /// |
| 37 /// Usually you don't want your tests cluttering up your working directory with |
| 38 /// fake filesystem entities. You can set [defaultRoot] to configure where |
| 39 /// filesystem descriptors are rooted on the physical filesystem. For example, |
| 40 /// to create a temporary directory for each test: |
| 41 /// |
| 42 /// import 'package:scheduled_test/descriptor.dart' as d; |
| 43 /// import 'package:scheduled_test/scheduled_test.dart'; |
| 44 /// |
| 45 /// void main() { |
| 46 /// setUp(() { |
| 47 /// var tempDir; |
| 48 /// schedule(() { |
| 49 /// return new Directory('').createTemp().then((dir) { |
| 50 /// tempDir = dir; |
| 51 /// d.defaultRoot = tempDir.path; |
| 52 /// }); |
| 53 /// }); |
| 54 /// |
| 55 /// currentSchedule.onComplete.schedule(() { |
| 56 /// d.defaultRoot = null; |
| 57 /// return tempDir.delete(recursive: true); |
| 58 /// }); |
| 59 /// }); |
| 60 /// |
| 61 /// // ... |
| 62 /// } |
| 63 library descriptor; |
| 64 |
| 65 import 'dart:async'; |
| 66 |
| 67 import 'package:pathos/path.dart' as path; |
| 68 |
| 69 import 'scheduled_test.dart'; |
| 70 import 'src/descriptor/directory.dart'; |
| 71 import 'src/descriptor/entry.dart'; |
| 72 import 'src/descriptor/file.dart'; |
| 73 |
| 74 export 'src/descriptor/directory.dart'; |
| 75 export 'src/descriptor/entry.dart'; |
| 76 export 'src/descriptor/file.dart'; |
| 77 |
| 78 /// The root path for descriptors. Top-level descriptors will be created and |
| 79 /// validated at this path. Defaults to the current working directory. |
| 80 /// |
| 81 /// If this is set to `null`, it will reset itself to the current working |
| 82 /// directory. |
| 83 String get defaultRoot => _defaultRoot == null ? path.current : _defaultRoot; |
| 84 set defaultRoot(String value) { |
| 85 _defaultRoot = value; |
| 86 } |
| 87 String _defaultRoot; |
| 88 |
| 89 /// Creates a new text [File] descriptor with [name] and [contents]. |
| 90 File file(Pattern name, [String contents='']) => new File(name, contents); |
| 91 |
| 92 /// Creates a new binary [File] descriptor with [name] and [contents]. |
| 93 File binaryFile(Pattern name, List<int> contents) => |
| 94 new File.binary(name, contents); |
| 95 |
| 96 /// Creates a new [Directory] descriptor with [name] and [contents]. |
| 97 Directory dir(Pattern name, [Iterable<Entry> contents]) => |
| 98 new Directory(name, contents == null ? <Entry>[] : contents); |
OLD | NEW |