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

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

Issue 12330062: Add a filesystem descriptor library to scheduled_test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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
(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) {
Bob Nystrom 2013/02/22 17:58:21 Seems like this is almost always the behavior you
nweiz 2013/02/22 20:57:20 I don't think it's possible to have this code run
Bob Nystrom 2013/02/22 22:08:57 Could schedule() do that eagerly?
nweiz 2013/02/22 23:05:21 It's a Dart constraint, not a unittest constraint.
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:path/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.
Bob Nystrom 2013/02/22 17:58:21 How about defaulting to a temp directory for each
nweiz 2013/02/22 20:57:20 See above.
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 [File] descriptor with [name] and [contents].
Bob Nystrom 2013/02/22 17:58:21 new -> new text
nweiz 2013/02/22 20:57:20 Done.
90 File file(Pattern name, String contents) => new File(name, contents);
Bob Nystrom 2013/02/22 17:58:21 Maybe make contents optional and default to just t
nweiz 2013/02/22 20:57:20 Done, although I think it's more intuitive if it d
Bob Nystrom 2013/02/22 22:08:57 That works too.
91
92 /// Creates a new [File] descriptor with [name] and [contents].
93 File binaryFile(Pattern name, List<int> contents) =>
94 new File.bytes(name, contents);
95
96 /// Creates a new [Directory] descriptor with [name] and [contents].
97 Directory dir(Pattern name, [List<Entry> contents]) =>
Bob Nystrom 2013/02/22 17:58:21 List -> Iterable
nweiz 2013/02/22 20:57:20 Done.
98 new Directory(name, contents == null ? <Entry>[] : contents);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698