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

Side by Side Diff: pkg/scheduled_test/lib/descriptor.dart

Issue 812253002: Delete a bunch of packages that are now on GitHub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Un-delete http Created 6 years 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
« no previous file with comments | « pkg/scheduled_test/README.md ('k') | pkg/scheduled_test/lib/scheduled_process.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 [Descriptor.create] to schedule a task that will create that structure
10 /// on the physical filesystem, or [Descriptor.validate] to schedule an
11 /// assertion that that structure exists. For example:
12 ///
13 /// import 'dart:io';
14 ///
15 /// import 'package:scheduled_test/descriptor.dart' as d;
16 /// import 'package:scheduled_test/scheduled_test.dart';
17 ///
18 /// void main() {
19 /// test('Directory.rename', () {
20 /// d.dir('parent', [
21 /// d.file('sibling', 'sibling-contents'),
22 /// d.dir('old-name', [
23 /// d.file('child', 'child-contents')
24 /// ])
25 /// ]).create();
26 ///
27 /// schedule(() =>
28 /// new Directory('parent/old-name').rename('parent/new-name'));
29 ///
30 /// d.dir('parent', [
31 /// d.file('sibling', 'sibling-contents'),
32 /// d.dir('new-name', [
33 /// d.file('child', 'child-contents')
34 /// ])
35 /// ]).validate();
36 /// });
37 /// }
38 ///
39 /// Usually you don't want your tests cluttering up your working directory with
40 /// fake filesystem entities. You can set [defaultRoot] to configure where
41 /// filesystem descriptors are rooted on the physical filesystem. For example,
42 /// to create a temporary directory for each test:
43 ///
44 /// import 'package:scheduled_test/descriptor.dart' as d;
45 /// import 'package:scheduled_test/scheduled_test.dart';
46 ///
47 /// void main() {
48 /// setUp(() {
49 /// var tempDir;
50 /// schedule(() {
51 /// return Directory.systemTemp
52 /// .createTemp('my_temp_dir_')
53 /// .then((dir) {
54 /// tempDir = dir;
55 /// d.defaultRoot = tempDir.path;
56 /// });
57 /// });
58 ///
59 /// currentSchedule.onComplete.schedule(() {
60 /// d.defaultRoot = null;
61 /// return tempDir.delete(recursive: true);
62 /// });
63 /// });
64 ///
65 /// // ...
66 /// }
67 library scheduled_test.descriptor;
68
69 import 'dart:async';
70
71 import 'package:path/path.dart' as path;
72
73 import 'scheduled_test.dart';
74 import 'src/descriptor/async_descriptor.dart';
75 import 'src/descriptor/descriptor.dart';
76 import 'src/descriptor/directory_descriptor.dart';
77 import 'src/descriptor/file_descriptor.dart';
78 import 'src/descriptor/nothing_descriptor.dart';
79 import 'src/descriptor/pattern_descriptor.dart';
80
81 export 'src/descriptor/async_descriptor.dart';
82 export 'src/descriptor/descriptor.dart';
83 export 'src/descriptor/directory_descriptor.dart';
84 export 'src/descriptor/file_descriptor.dart';
85 export 'src/descriptor/nothing_descriptor.dart';
86 export 'src/descriptor/pattern_descriptor.dart';
87
88 /// The root path for descriptors. Top-level descriptors will be created and
89 /// validated at this path. Defaults to the current working directory.
90 ///
91 /// If this is set to `null`, it will reset itself to the current working
92 /// directory.
93 String get defaultRoot => _defaultRoot == null ? path.current : _defaultRoot;
94 set defaultRoot(String value) {
95 _defaultRoot = value;
96 }
97 String _defaultRoot;
98
99 /// Creates a new text [FileDescriptor] with [name] and [contents].
100 FileDescriptor file(String name, [String contents='']) =>
101 new FileDescriptor(name, contents);
102
103 /// Creates a new binary [FileDescriptor] descriptor with [name] and [contents].
104 FileDescriptor binaryFile(String name, List<int> contents) =>
105 new FileDescriptor.binary(name, contents);
106
107 /// Creates a new text [FileDescriptor] with [name] that matches its String
108 /// contents against [matcher]. If the file is created, it's considered to be
109 /// empty.
110 FileDescriptor matcherFile(String name, matcher) =>
111 new FileDescriptor.matcher(name, wrapMatcher(matcher));
112
113 /// Creates a new binary [FileDescriptor] with [name] that matches its binary
114 /// contents against [matcher]. If the file is created, it's considered to be
115 /// empty.
116 FileDescriptor binaryMatcherFile(String name, matcher) =>
117 new FileDescriptor.binaryMatcher(name, wrapMatcher(matcher));
118
119 /// Creates a new [DirectoryDescriptor] descriptor with [name] and [contents].
120 DirectoryDescriptor dir(String name, [Iterable<Descriptor> contents]) =>
121 new DirectoryDescriptor(name, contents == null ? <Descriptor>[] : contents);
122
123 /// Creates a new descriptor wrapping a [Future]. This descriptor forwards all
124 /// asynchronous operations to the result of [future].
125 AsyncDescriptor async(Future<Descriptor> future) => new AsyncDescriptor(future);
126
127 /// Creates a new [NothingDescriptor] descriptor that asserts that no entry
128 /// named [name] exists.
129 NothingDescriptor nothing(String name) => new NothingDescriptor(name);
130
131 /// Creates a new [PatternDescriptor] descriptor that asserts than an entry with
132 /// a name matching [pattern] exists, and matches the [Descriptor] returned
133 /// by [fn].
134 PatternDescriptor pattern(Pattern name, EntryCreator fn) =>
135 new PatternDescriptor(name, fn);
136
137 /// A convenience method for creating a [PatternDescriptor] descriptor that
138 /// constructs a [FileDescriptor] descriptor.
139 PatternDescriptor filePattern(Pattern name, [String contents='']) =>
140 pattern(name, (realName) => file(realName, contents));
141
142 /// A convenience method for creating a [PatternDescriptor] descriptor that
143 /// constructs a [DirectoryDescriptor] descriptor.
144 PatternDescriptor dirPattern(Pattern name, [Iterable<Descriptor> contents]) =>
145 pattern(name, (realName) => dir(realName, contents));
OLDNEW
« no previous file with comments | « pkg/scheduled_test/README.md ('k') | pkg/scheduled_test/lib/scheduled_process.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698