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

Side by Side Diff: packages/dart_style/test/io_test.dart

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 4 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 dart_style.test.io; 5 library dart_style.test.io;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:dart_style/src/io.dart'; 10 import 'package:dart_style/src/io.dart';
11 import 'package:path/path.dart' as p; 11 import 'package:path/path.dart' as p;
12 import 'package:scheduled_test/descriptor.dart' as d; 12 import 'package:scheduled_test/descriptor.dart' as d;
13 import 'package:scheduled_test/scheduled_test.dart'; 13 import 'package:scheduled_test/scheduled_test.dart';
14 14
15 import 'package:dart_style/src/formatter_options.dart'; 15 import 'package:dart_style/src/formatter_options.dart';
16 16
17 import 'utils.dart'; 17 import 'utils.dart';
18 18
19 void main() { 19 void main() {
20 setUpTestSuite(); 20 setUpTestSuite();
21 21
22 var overwriteOptions = new FormatterOptions(OutputReporter.overwrite); 22 var overwriteOptions = new FormatterOptions(OutputReporter.overwrite);
23 23
24 var followOptions = 24 var followOptions =
25 new FormatterOptions(OutputReporter.overwrite, followLinks: true); 25 new FormatterOptions(OutputReporter.overwrite, followLinks: true);
26 26
27 test('handles directory ending in ".dart"', () { 27 test('handles directory ending in ".dart"', () {
28 d.dir('code.dart', [d.file('a.dart', unformattedSource),]).create(); 28 d.dir('code.dart', [
29 d.file('a.dart', unformattedSource),
30 ]).create();
29 31
30 schedule(() { 32 schedule(() {
31 var dir = new Directory(d.defaultRoot); 33 var dir = new Directory(d.defaultRoot);
32 processDirectory(overwriteOptions, dir); 34 processDirectory(overwriteOptions, dir);
33 }, 'Run formatter.'); 35 }, 'Run formatter.');
34 36
35 d.dir('code.dart', [d.file('a.dart', formattedSource)]).validate(); 37 d.dir('code.dart', [
38 d.file('a.dart', formattedSource),
39 ]).validate();
36 }); 40 });
37 41
38 test("doesn't touch unchanged files", () { 42 test("doesn't touch unchanged files", () {
39 d.dir('code', [ 43 d.dir('code', [
40 d.file('bad.dart', unformattedSource), 44 d.file('bad.dart', unformattedSource),
41 d.file('good.dart', formattedSource), 45 d.file('good.dart', formattedSource),
42 ]).create(); 46 ]).create();
43 47
44 modTime(String file) { 48 modTime(String file) {
45 return new File(p.join(d.defaultRoot, 'code', file)).statSync().modified; 49 return new File(p.join(d.defaultRoot, 'code', file)).statSync().modified;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 94
91 schedule(() { 95 schedule(() {
92 var dir = new Directory(p.join(d.defaultRoot, '.code')); 96 var dir = new Directory(p.join(d.defaultRoot, '.code'));
93 processDirectory(overwriteOptions, dir); 97 processDirectory(overwriteOptions, dir);
94 }, 'Run formatter.'); 98 }, 'Run formatter.');
95 99
96 d.dir('.code', [d.file('a.dart', formattedSource)]).validate(); 100 d.dir('.code', [d.file('a.dart', formattedSource)]).validate();
97 }); 101 });
98 102
99 test("doesn't follow directory symlinks by default", () { 103 test("doesn't follow directory symlinks by default", () {
100 d.dir('code', [d.file('a.dart', unformattedSource),]).create(); 104 d.dir('code', [
105 d.file('a.dart', unformattedSource),
106 ]).create();
101 107
102 d.dir('target_dir', [d.file('b.dart', unformattedSource),]).create(); 108 d.dir('target_dir', [
109 d.file('b.dart', unformattedSource),
110 ]).create();
103 111
104 schedule(() { 112 schedule(() {
105 // Create a link to the target directory in the code directory. 113 // Create a link to the target directory in the code directory.
106 new Link(p.join(d.defaultRoot, 'code', 'linked_dir')) 114 new Link(p.join(d.defaultRoot, 'code', 'linked_dir'))
107 .createSync(p.join(d.defaultRoot, 'target_dir')); 115 .createSync(p.join(d.defaultRoot, 'target_dir'));
108 }, 'Create symlinks.'); 116 }, 'Create symlinks.');
109 117
110 schedule(() { 118 schedule(() {
111 var dir = new Directory(p.join(d.defaultRoot, 'code')); 119 var dir = new Directory(p.join(d.defaultRoot, 'code'));
112 processDirectory(overwriteOptions, dir); 120 processDirectory(overwriteOptions, dir);
113 }, 'Run formatter.'); 121 }, 'Run formatter.');
114 122
115 d.dir('code', [ 123 d.dir('code', [
116 d.file('a.dart', formattedSource), 124 d.file('a.dart', formattedSource),
117 d.dir('linked_dir', [d.file('b.dart', unformattedSource),]) 125 d.dir('linked_dir', [
126 d.file('b.dart', unformattedSource),
127 ])
118 ]).validate(); 128 ]).validate();
119 }); 129 });
120 130
121 test("follows directory symlinks when 'followLinks' is true", () { 131 test("follows directory symlinks when 'followLinks' is true", () {
122 d.dir('code', [d.file('a.dart', unformattedSource),]).create(); 132 d.dir('code', [
133 d.file('a.dart', unformattedSource),
134 ]).create();
123 135
124 d.dir('target_dir', [d.file('b.dart', unformattedSource),]).create(); 136 d.dir('target_dir', [
137 d.file('b.dart', unformattedSource),
138 ]).create();
125 139
126 schedule(() { 140 schedule(() {
127 // Create a link to the target directory in the code directory. 141 // Create a link to the target directory in the code directory.
128 new Link(p.join(d.defaultRoot, 'code', 'linked_dir')) 142 new Link(p.join(d.defaultRoot, 'code', 'linked_dir'))
129 .createSync(p.join(d.defaultRoot, 'target_dir')); 143 .createSync(p.join(d.defaultRoot, 'target_dir'));
130 }); 144 });
131 145
132 schedule(() { 146 schedule(() {
133 var dir = new Directory(p.join(d.defaultRoot, 'code')); 147 var dir = new Directory(p.join(d.defaultRoot, 'code'));
134 processDirectory(followOptions, dir); 148 processDirectory(followOptions, dir);
135 }, 'running formatter'); 149 }, 'running formatter');
136 150
137 d.dir('code', [ 151 d.dir('code', [
138 d.file('a.dart', formattedSource), 152 d.file('a.dart', formattedSource),
139 d.dir('linked_dir', [d.file('b.dart', formattedSource),]) 153 d.dir('linked_dir', [
154 d.file('b.dart', formattedSource),
155 ])
140 ]).validate(); 156 ]).validate();
141 }); 157 });
142 158
143 if (!Platform.isWindows) { 159 if (!Platform.isWindows) {
160 // TODO(rnystrom): Figure out Windows equivalent of chmod and get this
161 // test running on Windows too.
162 test("reports error if file can not be written", () {
163 d.file('a.dart', unformattedSource).create();
164
165 schedule(() {
166 Process.runSync("chmod", ["-w", p.join(d.defaultRoot, 'a.dart')]);
167 }, 'Make file read-only.');
168
169 schedule(() {
170 var file = new File(p.join(d.defaultRoot, 'a.dart'));
171 processFile(overwriteOptions, file);
172 }, 'Run formatter.');
173
174 // Should not have been formatted.
175 d.file('a.dart', unformattedSource).validate();
176 });
177
144 test("doesn't follow file symlinks by default", () { 178 test("doesn't follow file symlinks by default", () {
145 d.dir('code').create(); 179 d.dir('code').create();
146 d.file('target_file.dart', unformattedSource).create(); 180 d.file('target_file.dart', unformattedSource).create();
147 181
148 schedule(() { 182 schedule(() {
149 // Create a link to the target file in the code directory. 183 // Create a link to the target file in the code directory.
150 new Link(p.join(d.defaultRoot, 'code', 'linked_file.dart')) 184 new Link(p.join(d.defaultRoot, 'code', 'linked_file.dart'))
151 .createSync(p.join(d.defaultRoot, 'target_file.dart')); 185 .createSync(p.join(d.defaultRoot, 'target_file.dart'));
152 }, 'Create symlinks.'); 186 }, 'Create symlinks.');
153 187
154 schedule(() { 188 schedule(() {
155 var dir = new Directory(p.join(d.defaultRoot, 'code')); 189 var dir = new Directory(p.join(d.defaultRoot, 'code'));
156 processDirectory(overwriteOptions, dir); 190 processDirectory(overwriteOptions, dir);
157 }, 'Run formatter.'); 191 }, 'Run formatter.');
158 192
159 d.dir( 193 d.dir('code', [
160 'code', [d.file('linked_file.dart', unformattedSource),]).validate(); 194 d.file('linked_file.dart', unformattedSource),
195 ]).validate();
161 }); 196 });
162 197
163 test("follows file symlinks when 'followLinks' is true", () { 198 test("follows file symlinks when 'followLinks' is true", () {
164 d.dir('code').create(); 199 d.dir('code').create();
165 d.file('target_file.dart', unformattedSource).create(); 200 d.file('target_file.dart', unformattedSource).create();
166 201
167 schedule(() { 202 schedule(() {
168 // Create a link to the target file in the code directory. 203 // Create a link to the target file in the code directory.
169 new Link(p.join(d.defaultRoot, 'code', 'linked_file.dart')) 204 new Link(p.join(d.defaultRoot, 'code', 'linked_file.dart'))
170 .createSync(p.join(d.defaultRoot, 'target_file.dart')); 205 .createSync(p.join(d.defaultRoot, 'target_file.dart'));
171 }); 206 });
172 207
173 schedule(() { 208 schedule(() {
174 var dir = new Directory(p.join(d.defaultRoot, 'code')); 209 var dir = new Directory(p.join(d.defaultRoot, 'code'));
175 processDirectory(followOptions, dir); 210 processDirectory(followOptions, dir);
176 }, 'running formatter'); 211 }, 'running formatter');
177 212
178 d.dir('code', [d.file('linked_file.dart', formattedSource),]).validate(); 213 d.dir('code', [
214 d.file('linked_file.dart', formattedSource),
215 ]).validate();
179 }); 216 });
180 } 217 }
181 } 218 }
OLDNEW
« no previous file with comments | « packages/dart_style/test/formatter_test.dart ('k') | packages/dart_style/test/regression/0000/0043.stmt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698