| 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:io'; | 8 import 'dart:io'; |
| 8 | 9 |
| 9 import 'package:dart_style/src/io.dart'; | 10 import 'package:dart_style/src/io.dart'; |
| 10 import 'package:path/path.dart' as p; | 11 import 'package:path/path.dart' as p; |
| 11 import 'package:scheduled_test/descriptor.dart' as d; | 12 import 'package:scheduled_test/descriptor.dart' as d; |
| 12 import 'package:scheduled_test/scheduled_test.dart'; | 13 import 'package:scheduled_test/scheduled_test.dart'; |
| 13 import 'package:unittest/compact_vm_config.dart'; | 14 import 'package:unittest/compact_vm_config.dart'; |
| 14 | 15 |
| 15 const _SOURCE = 'void main() => print("hello") ;'; | 16 const _SOURCE = 'void main() => print("hello") ;'; |
| 16 const _FORMATTED = 'void main() => print("hello");\n'; | 17 const _FORMATTED = 'void main() => print("hello");\n'; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 44 schedule(() { | 45 schedule(() { |
| 45 var dir = new Directory(d.defaultRoot); | 46 var dir = new Directory(d.defaultRoot); |
| 46 processDirectory(dir, overwrite: true); | 47 processDirectory(dir, overwrite: true); |
| 47 }, 'Run formatter.'); | 48 }, 'Run formatter.'); |
| 48 | 49 |
| 49 d.dir('code.dart', [ | 50 d.dir('code.dart', [ |
| 50 d.file('a.dart', _FORMATTED) | 51 d.file('a.dart', _FORMATTED) |
| 51 ]).validate(); | 52 ]).validate(); |
| 52 }); | 53 }); |
| 53 | 54 |
| 55 test("doesn't touch unchanged files", () { |
| 56 d.dir('code', [ |
| 57 d.file('bad.dart', _SOURCE), |
| 58 d.file('good.dart', _FORMATTED), |
| 59 ]).create(); |
| 60 |
| 61 modTime(String file) { |
| 62 return new File(p.join(d.defaultRoot, 'code', file)).statSync().modified; |
| 63 } |
| 64 |
| 65 var badBefore; |
| 66 var goodBefore; |
| 67 |
| 68 schedule(() { |
| 69 badBefore = modTime('bad.dart'); |
| 70 goodBefore = modTime('good.dart'); |
| 71 |
| 72 // Wait a bit so the mod time of a formatted file will be different. |
| 73 return new Future.delayed(new Duration(seconds: 1)); |
| 74 }); |
| 75 |
| 76 schedule(() { |
| 77 var dir = new Directory(p.join(d.defaultRoot, 'code')); |
| 78 processDirectory(dir, overwrite: true); |
| 79 |
| 80 // Should be touched. |
| 81 var badAfter = modTime('bad.dart'); |
| 82 expect(badAfter, isNot(equals(badBefore))); |
| 83 |
| 84 // Should not be touched. |
| 85 var goodAfter = modTime('good.dart'); |
| 86 expect(goodAfter, equals(goodBefore)); |
| 87 }); |
| 88 }); |
| 89 |
| 54 test("doesn't follow directory symlinks by default", () { | 90 test("doesn't follow directory symlinks by default", () { |
| 55 d.dir('code', [ | 91 d.dir('code', [ |
| 56 d.file('a.dart', _SOURCE), | 92 d.file('a.dart', _SOURCE), |
| 57 ]).create(); | 93 ]).create(); |
| 58 | 94 |
| 59 d.dir('target_dir', [ | 95 d.dir('target_dir', [ |
| 60 d.file('b.dart', _SOURCE), | 96 d.file('b.dart', _SOURCE), |
| 61 ]).create(); | 97 ]).create(); |
| 62 | 98 |
| 63 schedule(() { | 99 schedule(() { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 var dir = new Directory(p.join(d.defaultRoot, 'code')); | 178 var dir = new Directory(p.join(d.defaultRoot, 'code')); |
| 143 processDirectory(dir, overwrite: true, followLinks: true); | 179 processDirectory(dir, overwrite: true, followLinks: true); |
| 144 }, 'running formatter'); | 180 }, 'running formatter'); |
| 145 | 181 |
| 146 d.dir('code', [ | 182 d.dir('code', [ |
| 147 d.file('linked_file.dart', _FORMATTED), | 183 d.file('linked_file.dart', _FORMATTED), |
| 148 ]).validate(); | 184 ]).validate(); |
| 149 }); | 185 }); |
| 150 } | 186 } |
| 151 } | 187 } |
| OLD | NEW |