| 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'; | 
| 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 = new FormatterOptions(OutputReporter.overwrite, | 24   var followOptions = | 
| 25       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', [ | 28     d.dir('code.dart', [d.file('a.dart', unformattedSource),]).create(); | 
| 29       d.file('a.dart', unformattedSource), |  | 
| 30     ]).create(); |  | 
| 31 | 29 | 
| 32     schedule(() { | 30     schedule(() { | 
| 33       var dir = new Directory(d.defaultRoot); | 31       var dir = new Directory(d.defaultRoot); | 
| 34       processDirectory(overwriteOptions, dir); | 32       processDirectory(overwriteOptions, dir); | 
| 35     }, 'Run formatter.'); | 33     }, 'Run formatter.'); | 
| 36 | 34 | 
| 37     d.dir('code.dart', [ | 35     d.dir('code.dart', [d.file('a.dart', formattedSource)]).validate(); | 
| 38       d.file('a.dart', formattedSource) |  | 
| 39     ]).validate(); |  | 
| 40   }); | 36   }); | 
| 41 | 37 | 
| 42   test("doesn't touch unchanged files", () { | 38   test("doesn't touch unchanged files", () { | 
| 43     d.dir('code', [ | 39     d.dir('code', [ | 
| 44       d.file('bad.dart', unformattedSource), | 40       d.file('bad.dart', unformattedSource), | 
| 45       d.file('good.dart', formattedSource), | 41       d.file('good.dart', formattedSource), | 
| 46     ]).create(); | 42     ]).create(); | 
| 47 | 43 | 
| 48     modTime(String file) { | 44     modTime(String file) { | 
| 49       return new File(p.join(d.defaultRoot, 'code', file)).statSync().modified; | 45       return new File(p.join(d.defaultRoot, 'code', file)).statSync().modified; | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
| 68       var badAfter = modTime('bad.dart'); | 64       var badAfter = modTime('bad.dart'); | 
| 69       expect(badAfter, isNot(equals(badBefore))); | 65       expect(badAfter, isNot(equals(badBefore))); | 
| 70 | 66 | 
| 71       // Should not be touched. | 67       // Should not be touched. | 
| 72       var goodAfter = modTime('good.dart'); | 68       var goodAfter = modTime('good.dart'); | 
| 73       expect(goodAfter, equals(goodBefore)); | 69       expect(goodAfter, equals(goodBefore)); | 
| 74     }); | 70     }); | 
| 75   }); | 71   }); | 
| 76 | 72 | 
| 77   test("skips subdirectories whose name starts with '.'", () { | 73   test("skips subdirectories whose name starts with '.'", () { | 
| 78     d.dir('code', [ | 74     d.dir('code', [d.dir('.skip', [d.file('a.dart', unformattedSource)])]) | 
| 79       d.dir('.skip', [ | 75         .create(); | 
| 80         d.file('a.dart', unformattedSource) |  | 
| 81       ]) |  | 
| 82     ]).create(); |  | 
| 83 | 76 | 
| 84     schedule(() { | 77     schedule(() { | 
| 85       var dir = new Directory(d.defaultRoot); | 78       var dir = new Directory(d.defaultRoot); | 
| 86       processDirectory(overwriteOptions, dir); | 79       processDirectory(overwriteOptions, dir); | 
| 87     }, 'Run formatter.'); | 80     }, 'Run formatter.'); | 
| 88 | 81 | 
| 89     d.dir('code', [ | 82     d.dir('code', [d.dir('.skip', [d.file('a.dart', unformattedSource)])]) | 
| 90       d.dir('.skip', [ | 83         .validate(); | 
| 91         d.file('a.dart', unformattedSource) |  | 
| 92       ]) |  | 
| 93     ]).validate(); |  | 
| 94   }); | 84   }); | 
| 95 | 85 | 
| 96   test("traverses the given directory even if its name starts with '.'", () { | 86   test("traverses the given directory even if its name starts with '.'", () { | 
| 97     d.dir('.code', [ | 87     d.dir('.code', [d.file('a.dart', unformattedSource)]).create(); | 
| 98       d.file('a.dart', unformattedSource) |  | 
| 99     ]).create(); |  | 
| 100 | 88 | 
| 101     schedule(() { | 89     schedule(() { | 
| 102       var dir = new Directory(p.join(d.defaultRoot, '.code')); | 90       var dir = new Directory(p.join(d.defaultRoot, '.code')); | 
| 103       processDirectory(overwriteOptions, dir); | 91       processDirectory(overwriteOptions, dir); | 
| 104     }, 'Run formatter.'); | 92     }, 'Run formatter.'); | 
| 105 | 93 | 
| 106     d.dir('.code', [ | 94     d.dir('.code', [d.file('a.dart', formattedSource)]).validate(); | 
| 107       d.file('a.dart', formattedSource) |  | 
| 108     ]).validate(); |  | 
| 109   }); | 95   }); | 
| 110 | 96 | 
| 111   test("doesn't follow directory symlinks by default", () { | 97   test("doesn't follow directory symlinks by default", () { | 
| 112     d.dir('code', [ | 98     d.dir('code', [d.file('a.dart', unformattedSource),]).create(); | 
| 113       d.file('a.dart', unformattedSource), |  | 
| 114     ]).create(); |  | 
| 115 | 99 | 
| 116     d.dir('target_dir', [ | 100     d.dir('target_dir', [d.file('b.dart', unformattedSource),]).create(); | 
| 117       d.file('b.dart', unformattedSource), |  | 
| 118     ]).create(); |  | 
| 119 | 101 | 
| 120     schedule(() { | 102     schedule(() { | 
| 121       // Create a link to the target directory in the code directory. | 103       // Create a link to the target directory in the code directory. | 
| 122       new Link(p.join(d.defaultRoot, 'code', 'linked_dir')) | 104       new Link(p.join(d.defaultRoot, 'code', 'linked_dir')) | 
| 123           .createSync(p.join(d.defaultRoot, 'target_dir')); | 105           .createSync(p.join(d.defaultRoot, 'target_dir')); | 
| 124     }, 'Create symlinks.'); | 106     }, 'Create symlinks.'); | 
| 125 | 107 | 
| 126     schedule(() { | 108     schedule(() { | 
| 127       var dir = new Directory(p.join(d.defaultRoot, 'code')); | 109       var dir = new Directory(p.join(d.defaultRoot, 'code')); | 
| 128       processDirectory(overwriteOptions, dir); | 110       processDirectory(overwriteOptions, dir); | 
| 129     }, 'Run formatter.'); | 111     }, 'Run formatter.'); | 
| 130 | 112 | 
| 131     d.dir('code', [ | 113     d.dir('code', [ | 
| 132       d.file('a.dart', formattedSource), | 114       d.file('a.dart', formattedSource), | 
| 133       d.dir('linked_dir', [ | 115       d.dir('linked_dir', [d.file('b.dart', unformattedSource),]) | 
| 134         d.file('b.dart', unformattedSource), |  | 
| 135       ]) |  | 
| 136     ]).validate(); | 116     ]).validate(); | 
| 137   }); | 117   }); | 
| 138 | 118 | 
| 139   test("follows directory symlinks when 'followLinks' is true", () { | 119   test("follows directory symlinks when 'followLinks' is true", () { | 
| 140     d.dir('code', [ | 120     d.dir('code', [d.file('a.dart', unformattedSource),]).create(); | 
| 141       d.file('a.dart', unformattedSource), |  | 
| 142     ]).create(); |  | 
| 143 | 121 | 
| 144     d.dir('target_dir', [ | 122     d.dir('target_dir', [d.file('b.dart', unformattedSource),]).create(); | 
| 145       d.file('b.dart', unformattedSource), |  | 
| 146     ]).create(); |  | 
| 147 | 123 | 
| 148     schedule(() { | 124     schedule(() { | 
| 149       // Create a link to the target directory in the code directory. | 125       // Create a link to the target directory in the code directory. | 
| 150       new Link(p.join(d.defaultRoot, 'code', 'linked_dir')) | 126       new Link(p.join(d.defaultRoot, 'code', 'linked_dir')) | 
| 151           .createSync(p.join(d.defaultRoot, 'target_dir')); | 127           .createSync(p.join(d.defaultRoot, 'target_dir')); | 
| 152     }); | 128     }); | 
| 153 | 129 | 
| 154     schedule(() { | 130     schedule(() { | 
| 155       var dir = new Directory(p.join(d.defaultRoot, 'code')); | 131       var dir = new Directory(p.join(d.defaultRoot, 'code')); | 
| 156       processDirectory(followOptions, dir); | 132       processDirectory(followOptions, dir); | 
| 157     }, 'running formatter'); | 133     }, 'running formatter'); | 
| 158 | 134 | 
| 159     d.dir('code', [ | 135     d.dir('code', [ | 
| 160       d.file('a.dart', formattedSource), | 136       d.file('a.dart', formattedSource), | 
| 161       d.dir('linked_dir', [ | 137       d.dir('linked_dir', [d.file('b.dart', formattedSource),]) | 
| 162         d.file('b.dart', formattedSource), |  | 
| 163       ]) |  | 
| 164     ]).validate(); | 138     ]).validate(); | 
| 165   }); | 139   }); | 
| 166 | 140 | 
| 167   if (!Platform.isWindows) { | 141   if (!Platform.isWindows) { | 
| 168     test("doesn't follow file symlinks by default", () { | 142     test("doesn't follow file symlinks by default", () { | 
| 169       d.dir('code').create(); | 143       d.dir('code').create(); | 
| 170       d.file('target_file.dart', unformattedSource).create(); | 144       d.file('target_file.dart', unformattedSource).create(); | 
| 171 | 145 | 
| 172       schedule(() { | 146       schedule(() { | 
| 173         // Create a link to the target file in the code directory. | 147         // Create a link to the target file in the code directory. | 
| 174         new Link(p.join(d.defaultRoot, 'code', 'linked_file.dart')) | 148         new Link(p.join(d.defaultRoot, 'code', 'linked_file.dart')) | 
| 175             .createSync(p.join(d.defaultRoot, 'target_file.dart')); | 149             .createSync(p.join(d.defaultRoot, 'target_file.dart')); | 
| 176       }, 'Create symlinks.'); | 150       }, 'Create symlinks.'); | 
| 177 | 151 | 
| 178       schedule(() { | 152       schedule(() { | 
| 179         var dir = new Directory(p.join(d.defaultRoot, 'code')); | 153         var dir = new Directory(p.join(d.defaultRoot, 'code')); | 
| 180         processDirectory(overwriteOptions, dir); | 154         processDirectory(overwriteOptions, dir); | 
| 181       }, 'Run formatter.'); | 155       }, 'Run formatter.'); | 
| 182 | 156 | 
| 183       d.dir('code', [ | 157       d.dir('code', [d.file('linked_file.dart', unformattedSource),]) | 
| 184         d.file('linked_file.dart', unformattedSource), | 158           .validate(); | 
| 185       ]).validate(); |  | 
| 186     }); | 159     }); | 
| 187 | 160 | 
| 188     test("follows file symlinks when 'followLinks' is true", () { | 161     test("follows file symlinks when 'followLinks' is true", () { | 
| 189       d.dir('code').create(); | 162       d.dir('code').create(); | 
| 190       d.file('target_file.dart', unformattedSource).create(); | 163       d.file('target_file.dart', unformattedSource).create(); | 
| 191 | 164 | 
| 192       schedule(() { | 165       schedule(() { | 
| 193         // Create a link to the target file in the code directory. | 166         // Create a link to the target file in the code directory. | 
| 194         new Link(p.join(d.defaultRoot, 'code', 'linked_file.dart')) | 167         new Link(p.join(d.defaultRoot, 'code', 'linked_file.dart')) | 
| 195             .createSync(p.join(d.defaultRoot, 'target_file.dart')); | 168             .createSync(p.join(d.defaultRoot, 'target_file.dart')); | 
| 196       }); | 169       }); | 
| 197 | 170 | 
| 198       schedule(() { | 171       schedule(() { | 
| 199         var dir = new Directory(p.join(d.defaultRoot, 'code')); | 172         var dir = new Directory(p.join(d.defaultRoot, 'code')); | 
| 200         processDirectory(followOptions, dir); | 173         processDirectory(followOptions, dir); | 
| 201       }, 'running formatter'); | 174       }, 'running formatter'); | 
| 202 | 175 | 
| 203       d.dir('code', [ | 176       d.dir('code', [d.file('linked_file.dart', formattedSource),]).validate(); | 
| 204         d.file('linked_file.dart', formattedSource), |  | 
| 205       ]).validate(); |  | 
| 206     }); | 177     }); | 
| 207   } | 178   } | 
| 208 } | 179 } | 
| OLD | NEW | 
|---|