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

Side by Side Diff: utils/tests/pub/io_test.dart

Issue 12253054: Get rid of join() and encapsulate File and Directory in io.dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase. 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
« no previous file with comments | « utils/pub/validator/name.dart ('k') | utils/tests/pub/test_pub.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 io_test; 5 library io_test;
6 6
7 import '../../../pkg/path/lib/path.dart' as path;
7 import '../../../pkg/unittest/lib/unittest.dart'; 8 import '../../../pkg/unittest/lib/unittest.dart';
9
8 import '../../pub/io.dart'; 10 import '../../pub/io.dart';
9 import '../../pub/utils.dart'; 11 import '../../pub/utils.dart';
10 import 'test_pub.dart'; 12 import 'test_pub.dart';
11 13
12 main() { 14 main() {
13 initConfig(); 15 initConfig();
14 16
15 group('listDir', () { 17 group('listDir', () {
16 test('lists a simple directory non-recursively', () { 18 test('lists a simple directory non-recursively', () {
17 expect(withTempDir((path) { 19 expect(withTempDir((temp) {
18 var future = defer(() { 20 var future = defer(() {
19 writeTextFile(join(path, 'file1.txt'), ''); 21 writeTextFile(path.join(temp, 'file1.txt'), '');
20 writeTextFile(join(path, 'file2.txt'), ''); 22 writeTextFile(path.join(temp, 'file2.txt'), '');
21 createDir(join(path, 'subdir')); 23 createDir(path.join(temp, 'subdir'));
22 writeTextFile(join(path, 'subdir', 'file3.txt'), ''); 24 writeTextFile(path.join(temp, 'subdir', 'file3.txt'), '');
23 return listDir(path); 25 return listDir(temp);
24 }); 26 });
25 expect(future, completion(unorderedEquals([ 27 expect(future, completion(unorderedEquals([
26 join(path, 'file1.txt'), 28 path.join(temp, 'file1.txt'),
27 join(path, 'file2.txt'), 29 path.join(temp, 'file2.txt'),
28 join(path, 'subdir') 30 path.join(temp, 'subdir')
29 ]))); 31 ])));
30 return future; 32 return future;
31 }), completes); 33 }), completes);
32 }); 34 });
33 35
34 test('lists a simple directory recursively', () { 36 test('lists a simple directory recursively', () {
35 expect(withTempDir((path) { 37 expect(withTempDir((temp) {
36 var future = defer(() { 38 var future = defer(() {
37 writeTextFile(join(path, 'file1.txt'), ''); 39 writeTextFile(path.join(temp, 'file1.txt'), '');
38 writeTextFile(join(path, 'file2.txt'), ''); 40 writeTextFile(path.join(temp, 'file2.txt'), '');
39 createDir(join(path, 'subdir')); 41 createDir(path.join(temp, 'subdir'));
40 writeTextFile(join(path, 'subdir', 'file3.txt'), ''); 42 writeTextFile(path.join(temp, 'subdir', 'file3.txt'), '');
41 return listDir(path, recursive: true); 43 return listDir(temp, recursive: true);
42 }); 44 });
43 45
44 expect(future, completion(unorderedEquals([ 46 expect(future, completion(unorderedEquals([
45 join(path, 'file1.txt'), 47 path.join(temp, 'file1.txt'),
46 join(path, 'file2.txt'), 48 path.join(temp, 'file2.txt'),
47 join(path, 'subdir'), 49 path.join(temp, 'subdir'),
48 join(path, 'subdir', 'file3.txt'), 50 path.join(temp, 'subdir', 'file3.txt'),
49 ]))); 51 ])));
50 return future; 52 return future;
51 }), completes); 53 }), completes);
52 }); 54 });
53 55
54 test('ignores hidden files by default', () { 56 test('ignores hidden files by default', () {
55 expect(withTempDir((path) { 57 expect(withTempDir((temp) {
56 var future = defer(() { 58 var future = defer(() {
57 writeTextFile(join(path, 'file1.txt'), ''); 59 writeTextFile(path.join(temp, 'file1.txt'), '');
58 writeTextFile(join(path, 'file2.txt'), ''); 60 writeTextFile(path.join(temp, 'file2.txt'), '');
59 writeTextFile(join(path, '.file3.txt'), ''); 61 writeTextFile(path.join(temp, '.file3.txt'), '');
60 createDir(join(path, '.subdir')); 62 createDir(path.join(temp, '.subdir'));
61 writeTextFile(join(path, '.subdir', 'file3.txt'), ''); 63 writeTextFile(path.join(temp, '.subdir', 'file3.txt'), '');
62 return listDir(path, recursive: true); 64 return listDir(temp, recursive: true);
63 }); 65 });
64 expect(future, completion(unorderedEquals([ 66 expect(future, completion(unorderedEquals([
65 join(path, 'file1.txt'), 67 path.join(temp, 'file1.txt'),
66 join(path, 'file2.txt') 68 path.join(temp, 'file2.txt')
67 ]))); 69 ])));
68 return future; 70 return future;
69 }), completes); 71 }), completes);
70 }); 72 });
71 73
72 test('includes hidden files when told to', () { 74 test('includes hidden files when told to', () {
73 expect(withTempDir((path) { 75 expect(withTempDir((temp) {
74 var future = defer(() { 76 var future = defer(() {
75 writeTextFile(join(path, 'file1.txt'), ''); 77 writeTextFile(path.join(temp, 'file1.txt'), '');
76 writeTextFile(join(path, 'file2.txt'), ''); 78 writeTextFile(path.join(temp, 'file2.txt'), '');
77 writeTextFile(join(path, '.file3.txt'), ''); 79 writeTextFile(path.join(temp, '.file3.txt'), '');
78 createDir(join(path, '.subdir')); 80 createDir(path.join(temp, '.subdir'));
79 writeTextFile(join(path, '.subdir', 'file3.txt'), ''); 81 writeTextFile(path.join(temp, '.subdir', 'file3.txt'), '');
80 return listDir(path, recursive: true, includeHiddenFiles: true); 82 return listDir(temp, recursive: true, includeHiddenFiles: true);
81 }); 83 });
82 expect(future, completion(unorderedEquals([ 84 expect(future, completion(unorderedEquals([
83 join(path, 'file1.txt'), 85 path.join(temp, 'file1.txt'),
84 join(path, 'file2.txt'), 86 path.join(temp, 'file2.txt'),
85 join(path, '.file3.txt'), 87 path.join(temp, '.file3.txt'),
86 join(path, '.subdir'), 88 path.join(temp, '.subdir'),
87 join(path, '.subdir', 'file3.txt') 89 path.join(temp, '.subdir', 'file3.txt')
88 ]))); 90 ])));
89 return future; 91 return future;
90 }), completes); 92 }), completes);
91 }); 93 });
92 94
93 test('returns the unresolved paths for symlinks', () { 95 test('returns the unresolved paths for symlinks', () {
94 expect(withTempDir((path) { 96 expect(withTempDir((temp) {
95 var dirToList = join(path, 'dir-to-list'); 97 var dirToList = path.join(temp, 'dir-to-list');
96 var future = defer(() { 98 var future = defer(() {
97 createDir(join(path, 'dir1')); 99 createDir(path.join(temp, 'dir1'));
98 writeTextFile(join(path, 'dir1', 'file1.txt'), ''); 100 writeTextFile(path.join(temp, 'dir1', 'file1.txt'), '');
99 createDir(join(path, 'dir2')); 101 createDir(path.join(temp, 'dir2'));
100 writeTextFile(join(path, 'dir2', 'file2.txt'), ''); 102 writeTextFile(path.join(temp, 'dir2', 'file2.txt'), '');
101 createDir(dirToList); 103 createDir(dirToList);
102 return createSymlink(join(path, 'dir1'), 104 return createSymlink(path.join(temp, 'dir1'),
103 join(dirToList, 'linked-dir1')); 105 path.join(dirToList, 'linked-dir1'));
104 }).then((_) { 106 }).then((_) {
105 createDir(join(dirToList, 'subdir')); 107 createDir(path.join(dirToList, 'subdir'));
106 return createSymlink( 108 return createSymlink(
107 join(path, 'dir2'), 109 path.join(temp, 'dir2'),
108 join(dirToList, 'subdir', 'linked-dir2')); 110 path.join(dirToList, 'subdir', 'linked-dir2'));
109 }).then((_) => listDir(dirToList, recursive: true)); 111 }).then((_) => listDir(dirToList, recursive: true));
110 expect(future, completion(unorderedEquals([ 112 expect(future, completion(unorderedEquals([
111 join(dirToList, 'linked-dir1'), 113 path.join(dirToList, 'linked-dir1'),
112 join(dirToList, 'linked-dir1', 'file1.txt'), 114 path.join(dirToList, 'linked-dir1', 'file1.txt'),
113 join(dirToList, 'subdir'), 115 path.join(dirToList, 'subdir'),
114 join(dirToList, 'subdir', 'linked-dir2'), 116 path.join(dirToList, 'subdir', 'linked-dir2'),
115 join(dirToList, 'subdir', 'linked-dir2', 'file2.txt'), 117 path.join(dirToList, 'subdir', 'linked-dir2', 'file2.txt'),
116 ]))); 118 ])));
117 return future; 119 return future;
118 }), completes); 120 }), completes);
119 }); 121 });
120 122
121 test('works with recursive symlinks', () { 123 test('works with recursive symlinks', () {
122 expect(withTempDir((path) { 124 expect(withTempDir((temp) {
123 var future = defer(() { 125 var future = defer(() {
124 writeTextFile(join(path, 'file1.txt'), ''); 126 writeTextFile(path.join(temp, 'file1.txt'), '');
125 return createSymlink(path, join(path, 'linkdir')); 127 return createSymlink(temp, path.join(temp, 'linkdir'));
126 }).then((_) => listDir(path, recursive: true)); 128 }).then((_) => listDir(temp, recursive: true));
127 expect(future, completion(unorderedEquals([ 129 expect(future, completion(unorderedEquals([
128 join(path, 'file1.txt'), 130 path.join(temp, 'file1.txt'),
129 join(path, 'linkdir') 131 path.join(temp, 'linkdir')
130 ]))); 132 ])));
131 return future; 133 return future;
132 }), completes); 134 }), completes);
133 }); 135 });
134 }); 136 });
135 } 137 }
OLDNEW
« no previous file with comments | « utils/pub/validator/name.dart ('k') | utils/tests/pub/test_pub.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698