| OLD | NEW |
| 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'; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 test('handles directory ending in ".dart"', () { | 27 test('handles directory ending in ".dart"', () { |
| 28 d.dir('code.dart', [ | 28 d.dir('code.dart', [ |
| 29 d.file('a.dart', unformattedSource), | 29 d.file('a.dart', unformattedSource), |
| 30 ]).create(); | 30 ]).create(); |
| 31 | 31 |
| 32 schedule(() { | 32 schedule(() { |
| 33 var dir = new Directory(d.defaultRoot); | 33 var dir = new Directory(d.defaultRoot); |
| 34 processDirectory(overwriteOptions, dir); | 34 processDirectory(overwriteOptions, dir); |
| 35 }, 'Run formatter.'); | 35 }, 'Run formatter.'); |
| 36 | 36 |
| 37 d.dir('code.dart', [d.file('a.dart', formattedSource)]).validate(); | 37 d.dir('code.dart', [ |
| 38 d.file('a.dart', formattedSource), |
| 39 ]).validate(); |
| 38 }); | 40 }); |
| 39 | 41 |
| 40 test("doesn't touch unchanged files", () { | 42 test("doesn't touch unchanged files", () { |
| 41 d.dir('code', [ | 43 d.dir('code', [ |
| 42 d.file('bad.dart', unformattedSource), | 44 d.file('bad.dart', unformattedSource), |
| 43 d.file('good.dart', formattedSource), | 45 d.file('good.dart', formattedSource), |
| 44 ]).create(); | 46 ]).create(); |
| 45 | 47 |
| 46 modTime(String file) { | 48 modTime(String file) { |
| 47 return new File(p.join(d.defaultRoot, 'code', file)).statSync().modified; | 49 return new File(p.join(d.defaultRoot, 'code', file)).statSync().modified; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 150 |
| 149 d.dir('code', [ | 151 d.dir('code', [ |
| 150 d.file('a.dart', formattedSource), | 152 d.file('a.dart', formattedSource), |
| 151 d.dir('linked_dir', [ | 153 d.dir('linked_dir', [ |
| 152 d.file('b.dart', formattedSource), | 154 d.file('b.dart', formattedSource), |
| 153 ]) | 155 ]) |
| 154 ]).validate(); | 156 ]).validate(); |
| 155 }); | 157 }); |
| 156 | 158 |
| 157 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 |
| 158 test("doesn't follow file symlinks by default", () { | 178 test("doesn't follow file symlinks by default", () { |
| 159 d.dir('code').create(); | 179 d.dir('code').create(); |
| 160 d.file('target_file.dart', unformattedSource).create(); | 180 d.file('target_file.dart', unformattedSource).create(); |
| 161 | 181 |
| 162 schedule(() { | 182 schedule(() { |
| 163 // Create a link to the target file in the code directory. | 183 // Create a link to the target file in the code directory. |
| 164 new Link(p.join(d.defaultRoot, 'code', 'linked_file.dart')) | 184 new Link(p.join(d.defaultRoot, 'code', 'linked_file.dart')) |
| 165 .createSync(p.join(d.defaultRoot, 'target_file.dart')); | 185 .createSync(p.join(d.defaultRoot, 'target_file.dart')); |
| 166 }, 'Create symlinks.'); | 186 }, 'Create symlinks.'); |
| 167 | 187 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 189 var dir = new Directory(p.join(d.defaultRoot, 'code')); | 209 var dir = new Directory(p.join(d.defaultRoot, 'code')); |
| 190 processDirectory(followOptions, dir); | 210 processDirectory(followOptions, dir); |
| 191 }, 'running formatter'); | 211 }, 'running formatter'); |
| 192 | 212 |
| 193 d.dir('code', [ | 213 d.dir('code', [ |
| 194 d.file('linked_file.dart', formattedSource), | 214 d.file('linked_file.dart', formattedSource), |
| 195 ]).validate(); | 215 ]).validate(); |
| 196 }); | 216 }); |
| 197 } | 217 } |
| 198 } | 218 } |
| OLD | NEW |