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

Side by Side Diff: tests/standalone/io/file_system_links_test.dart

Issue 10309004: Deal with symbolic links for file and directories on Mac and Linux. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 | « runtime/bin/file_macos.cc ('k') | tests/standalone/io/ln.sh » ('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) 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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #import('dart:io');
6
7
8 createLink(String dst, String link, bool symbolic, void callback()) {
9 var args = [ symbolic ? '-s' : '', dst, link ];
10 var script = 'tests/standalone/io/ln.sh';
11 if (!new File(script).existsSync()) {
12 script = '../$script';
13 }
14 new Process.run(script, args, null, (exit, out, err) {
15 if (exit == 0) {
16 callback();
17 } else {
18 throw new Exception('link creation failed');
19 }
20 });
21 }
22
23
24 testFileExistsCreate() {
25 var temp = new Directory('');
26 temp.createTempSync();
27 var x = '${temp.path}${Platform.pathSeparator()}x';
28 var y = '${temp.path}${Platform.pathSeparator()}y';
29 createLink(x, y, true, () {
30 Expect.isFalse(new File(x).existsSync());
31 Expect.isFalse(new File(y).existsSync());
32 new File(y).createSync();
33 Expect.isTrue(new File(x).existsSync());
34 Expect.isTrue(new File(y).existsSync());
35 temp.deleteRecursivelySync();
36 });
37 }
38
39
40 testFileDelete() {
41 var temp = new Directory('');
42 temp.createTempSync();
43 var x = '${temp.path}${Platform.pathSeparator()}x';
44 var y = '${temp.path}${Platform.pathSeparator()}y';
45 new File(x).createSync();
46 createLink(x, y, true, () {
47 Expect.isTrue(new File(x).existsSync());
48 Expect.isTrue(new File(y).existsSync());
49 new File(y).deleteSync();
50 Expect.isTrue(new File(x).existsSync());
51 Expect.isFalse(new File(y).existsSync());
52 createLink(x, y, false, () {
53 Expect.isTrue(new File(x).existsSync());
54 Expect.isTrue(new File(y).existsSync());
55 new File(y).deleteSync();
56 Expect.isTrue(new File(x).existsSync());
57 Expect.isFalse(new File(y).existsSync());
58 temp.deleteRecursivelySync();
59 });
60 });
61 }
62
63
64 testFileWriteRead() {
65 var temp = new Directory('');
66 temp.createTempSync();
67 var x = '${temp.path}${Platform.pathSeparator()}x';
68 var y = '${temp.path}${Platform.pathSeparator()}y';
69 new File(x).createSync();
70 createLink(x, y, true, () {
71 var data = "asdf".charCodes();
72 var output = new File(y).openOutputStream(FileMode.WRITE);
73 output.write(data);
74 output.onNoPendingWrites = () {
75 output.close();
76 var read = new File(y).readAsBytesSync();
77 Expect.listEquals(data, read);
78 var read2 = new File(x).readAsBytesSync();
79 Expect.listEquals(data, read2);
80 temp.deleteRecursivelySync();
81 };
82 });
83 }
84
85
86 testDirectoryExistsCreate() {
87 var temp = new Directory('');
88 temp.createTempSync();
89 var x = '${temp.path}${Platform.pathSeparator()}x';
90 var y = '${temp.path}${Platform.pathSeparator()}y';
91 createLink(x, y, true, () {
92 Expect.isFalse(new Directory(x).existsSync());
93 Expect.isFalse(new Directory(y).existsSync());
94 Expect.throws(new Directory(y).createSync);
95 temp.deleteRecursivelySync();
96 });
97 }
98
99
100 testDirectoryDelete() {
101 var temp = new Directory('');
102 temp.createTempSync();
103 var temp2 = new Directory('');
104 temp2.createTempSync();
105 var y = '${temp.path}${Platform.pathSeparator()}y';
106 var x = '${temp2.path}${Platform.pathSeparator()}x';
107 new File(x).createSync();
108 createLink(temp2.path, y, true, () {
109 var link = new Directory(y);
110 Expect.isTrue(link.existsSync());
111 Expect.isTrue(temp2.existsSync());
112 link.deleteSync();
113 Expect.isFalse(link.existsSync());
114 Expect.isTrue(temp2.existsSync());
115 createLink(temp2.path, y, true, () {
116 Expect.isTrue(link.existsSync());
117 temp.deleteRecursivelySync();
118 Expect.isFalse(link.existsSync());
119 Expect.isTrue(temp2.existsSync());
120 Expect.isTrue(new File(x).existsSync());
121 temp2.deleteRecursivelySync();
122 });
123 });
124 }
125
126
127 testDirectoryListing() {
128 var temp = new Directory('');
129 temp.createTempSync();
130 var temp2 = new Directory('');
131 temp2.createTempSync();
132 var y = '${temp.path}${Platform.pathSeparator()}y';
133 var x = '${temp2.path}${Platform.pathSeparator()}x';
134 new File(x).createSync();
135 createLink(temp2.path, y, true, () {
136 var files = [];
137 var dirs = [];
138 temp.list(recursive: true);
139 temp.onFile = (f) => files.add(f);
140 temp.onDir = (d) => dirs.add(d);
141 temp.onDone = (success) {
142 Expect.isTrue(success);
143 Expect.equals(1, files.length);
144 Expect.isTrue(files[0].endsWith(x));
145 Expect.equals(1, dirs.length);
146 Expect.isTrue(dirs[0].endsWith(y));
147 temp.deleteRecursivelySync();
148 temp2.deleteRecursivelySync();
149 };
150 });
151 }
152
153
154 main() {
155 testFileExistsCreate();
156 testFileDelete();
157 testFileWriteRead();
158 testDirectoryExistsCreate();
159 testDirectoryDelete();
160 testDirectoryListing();
161 }
OLDNEW
« no previous file with comments | « runtime/bin/file_macos.cc ('k') | tests/standalone/io/ln.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698