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

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

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library dart_style.test.io;
6
7 import 'dart:async';
8 import 'dart:io';
9
10 import 'package:dart_style/src/io.dart';
11 import 'package:path/path.dart' as p;
12 import 'package:scheduled_test/descriptor.dart' as d;
13 import 'package:scheduled_test/scheduled_test.dart';
14
15 import 'package:dart_style/src/formatter_options.dart';
16
17 import 'utils.dart';
18
19 void main() {
20 setUpTestSuite();
21
22 var overwriteOptions = new FormatterOptions(OutputReporter.overwrite);
23
24 var followOptions =
25 new FormatterOptions(OutputReporter.overwrite, followLinks: true);
26
27 test('handles directory ending in ".dart"', () {
28 d.dir('code.dart', [d.file('a.dart', unformattedSource),]).create();
29
30 schedule(() {
31 var dir = new Directory(d.defaultRoot);
32 processDirectory(overwriteOptions, dir);
33 }, 'Run formatter.');
34
35 d.dir('code.dart', [d.file('a.dart', formattedSource)]).validate();
36 });
37
38 test("doesn't touch unchanged files", () {
39 d.dir('code', [
40 d.file('bad.dart', unformattedSource),
41 d.file('good.dart', formattedSource),
42 ]).create();
43
44 modTime(String file) {
45 return new File(p.join(d.defaultRoot, 'code', file)).statSync().modified;
46 }
47
48 var badBefore;
49 var goodBefore;
50
51 schedule(() {
52 badBefore = modTime('bad.dart');
53 goodBefore = modTime('good.dart');
54
55 // Wait a bit so the mod time of a formatted file will be different.
56 return new Future.delayed(new Duration(seconds: 1));
57 });
58
59 schedule(() {
60 var dir = new Directory(p.join(d.defaultRoot, 'code'));
61 processDirectory(overwriteOptions, dir);
62
63 // Should be touched.
64 var badAfter = modTime('bad.dart');
65 expect(badAfter, isNot(equals(badBefore)));
66
67 // Should not be touched.
68 var goodAfter = modTime('good.dart');
69 expect(goodAfter, equals(goodBefore));
70 });
71 });
72
73 test("skips subdirectories whose name starts with '.'", () {
74 d.dir('code', [
75 d.dir('.skip', [d.file('a.dart', unformattedSource)])
76 ]).create();
77
78 schedule(() {
79 var dir = new Directory(d.defaultRoot);
80 processDirectory(overwriteOptions, dir);
81 }, 'Run formatter.');
82
83 d.dir('code', [
84 d.dir('.skip', [d.file('a.dart', unformattedSource)])
85 ]).validate();
86 });
87
88 test("traverses the given directory even if its name starts with '.'", () {
89 d.dir('.code', [d.file('a.dart', unformattedSource)]).create();
90
91 schedule(() {
92 var dir = new Directory(p.join(d.defaultRoot, '.code'));
93 processDirectory(overwriteOptions, dir);
94 }, 'Run formatter.');
95
96 d.dir('.code', [d.file('a.dart', formattedSource)]).validate();
97 });
98
99 test("doesn't follow directory symlinks by default", () {
100 d.dir('code', [d.file('a.dart', unformattedSource),]).create();
101
102 d.dir('target_dir', [d.file('b.dart', unformattedSource),]).create();
103
104 schedule(() {
105 // Create a link to the target directory in the code directory.
106 new Link(p.join(d.defaultRoot, 'code', 'linked_dir'))
107 .createSync(p.join(d.defaultRoot, 'target_dir'));
108 }, 'Create symlinks.');
109
110 schedule(() {
111 var dir = new Directory(p.join(d.defaultRoot, 'code'));
112 processDirectory(overwriteOptions, dir);
113 }, 'Run formatter.');
114
115 d.dir('code', [
116 d.file('a.dart', formattedSource),
117 d.dir('linked_dir', [d.file('b.dart', unformattedSource),])
118 ]).validate();
119 });
120
121 test("follows directory symlinks when 'followLinks' is true", () {
122 d.dir('code', [d.file('a.dart', unformattedSource),]).create();
123
124 d.dir('target_dir', [d.file('b.dart', unformattedSource),]).create();
125
126 schedule(() {
127 // Create a link to the target directory in the code directory.
128 new Link(p.join(d.defaultRoot, 'code', 'linked_dir'))
129 .createSync(p.join(d.defaultRoot, 'target_dir'));
130 });
131
132 schedule(() {
133 var dir = new Directory(p.join(d.defaultRoot, 'code'));
134 processDirectory(followOptions, dir);
135 }, 'running formatter');
136
137 d.dir('code', [
138 d.file('a.dart', formattedSource),
139 d.dir('linked_dir', [d.file('b.dart', formattedSource),])
140 ]).validate();
141 });
142
143 if (!Platform.isWindows) {
144 test("doesn't follow file symlinks by default", () {
145 d.dir('code').create();
146 d.file('target_file.dart', unformattedSource).create();
147
148 schedule(() {
149 // Create a link to the target file in the code directory.
150 new Link(p.join(d.defaultRoot, 'code', 'linked_file.dart'))
151 .createSync(p.join(d.defaultRoot, 'target_file.dart'));
152 }, 'Create symlinks.');
153
154 schedule(() {
155 var dir = new Directory(p.join(d.defaultRoot, 'code'));
156 processDirectory(overwriteOptions, dir);
157 }, 'Run formatter.');
158
159 d.dir('code', [d.file('linked_file.dart', unformattedSource),])
160 .validate();
161 });
162
163 test("follows file symlinks when 'followLinks' is true", () {
164 d.dir('code').create();
165 d.file('target_file.dart', unformattedSource).create();
166
167 schedule(() {
168 // Create a link to the target file in the code directory.
169 new Link(p.join(d.defaultRoot, 'code', 'linked_file.dart'))
170 .createSync(p.join(d.defaultRoot, 'target_file.dart'));
171 });
172
173 schedule(() {
174 var dir = new Directory(p.join(d.defaultRoot, 'code'));
175 processDirectory(followOptions, dir);
176 }, 'running formatter');
177
178 d.dir('code', [d.file('linked_file.dart', formattedSource),]).validate();
179 });
180 }
181 }
OLDNEW
« no previous file with comments | « packages/dart_style/test/formatter_test.dart ('k') | packages/dart_style/test/regression/0000/0000.stmt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698