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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/dart_style/test/io_test.dart
diff --git a/packages/dart_style/test/io_test.dart b/packages/dart_style/test/io_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3962de6c545c3d3aacbb3c38e7dadda78faa17c4
--- /dev/null
+++ b/packages/dart_style/test/io_test.dart
@@ -0,0 +1,181 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library dart_style.test.io;
+
+import 'dart:async';
+import 'dart:io';
+
+import 'package:dart_style/src/io.dart';
+import 'package:path/path.dart' as p;
+import 'package:scheduled_test/descriptor.dart' as d;
+import 'package:scheduled_test/scheduled_test.dart';
+
+import 'package:dart_style/src/formatter_options.dart';
+
+import 'utils.dart';
+
+void main() {
+ setUpTestSuite();
+
+ var overwriteOptions = new FormatterOptions(OutputReporter.overwrite);
+
+ var followOptions =
+ new FormatterOptions(OutputReporter.overwrite, followLinks: true);
+
+ test('handles directory ending in ".dart"', () {
+ d.dir('code.dart', [d.file('a.dart', unformattedSource),]).create();
+
+ schedule(() {
+ var dir = new Directory(d.defaultRoot);
+ processDirectory(overwriteOptions, dir);
+ }, 'Run formatter.');
+
+ d.dir('code.dart', [d.file('a.dart', formattedSource)]).validate();
+ });
+
+ test("doesn't touch unchanged files", () {
+ d.dir('code', [
+ d.file('bad.dart', unformattedSource),
+ d.file('good.dart', formattedSource),
+ ]).create();
+
+ modTime(String file) {
+ return new File(p.join(d.defaultRoot, 'code', file)).statSync().modified;
+ }
+
+ var badBefore;
+ var goodBefore;
+
+ schedule(() {
+ badBefore = modTime('bad.dart');
+ goodBefore = modTime('good.dart');
+
+ // Wait a bit so the mod time of a formatted file will be different.
+ return new Future.delayed(new Duration(seconds: 1));
+ });
+
+ schedule(() {
+ var dir = new Directory(p.join(d.defaultRoot, 'code'));
+ processDirectory(overwriteOptions, dir);
+
+ // Should be touched.
+ var badAfter = modTime('bad.dart');
+ expect(badAfter, isNot(equals(badBefore)));
+
+ // Should not be touched.
+ var goodAfter = modTime('good.dart');
+ expect(goodAfter, equals(goodBefore));
+ });
+ });
+
+ test("skips subdirectories whose name starts with '.'", () {
+ d.dir('code', [
+ d.dir('.skip', [d.file('a.dart', unformattedSource)])
+ ]).create();
+
+ schedule(() {
+ var dir = new Directory(d.defaultRoot);
+ processDirectory(overwriteOptions, dir);
+ }, 'Run formatter.');
+
+ d.dir('code', [
+ d.dir('.skip', [d.file('a.dart', unformattedSource)])
+ ]).validate();
+ });
+
+ test("traverses the given directory even if its name starts with '.'", () {
+ d.dir('.code', [d.file('a.dart', unformattedSource)]).create();
+
+ schedule(() {
+ var dir = new Directory(p.join(d.defaultRoot, '.code'));
+ processDirectory(overwriteOptions, dir);
+ }, 'Run formatter.');
+
+ d.dir('.code', [d.file('a.dart', formattedSource)]).validate();
+ });
+
+ test("doesn't follow directory symlinks by default", () {
+ d.dir('code', [d.file('a.dart', unformattedSource),]).create();
+
+ d.dir('target_dir', [d.file('b.dart', unformattedSource),]).create();
+
+ schedule(() {
+ // Create a link to the target directory in the code directory.
+ new Link(p.join(d.defaultRoot, 'code', 'linked_dir'))
+ .createSync(p.join(d.defaultRoot, 'target_dir'));
+ }, 'Create symlinks.');
+
+ schedule(() {
+ var dir = new Directory(p.join(d.defaultRoot, 'code'));
+ processDirectory(overwriteOptions, dir);
+ }, 'Run formatter.');
+
+ d.dir('code', [
+ d.file('a.dart', formattedSource),
+ d.dir('linked_dir', [d.file('b.dart', unformattedSource),])
+ ]).validate();
+ });
+
+ test("follows directory symlinks when 'followLinks' is true", () {
+ d.dir('code', [d.file('a.dart', unformattedSource),]).create();
+
+ d.dir('target_dir', [d.file('b.dart', unformattedSource),]).create();
+
+ schedule(() {
+ // Create a link to the target directory in the code directory.
+ new Link(p.join(d.defaultRoot, 'code', 'linked_dir'))
+ .createSync(p.join(d.defaultRoot, 'target_dir'));
+ });
+
+ schedule(() {
+ var dir = new Directory(p.join(d.defaultRoot, 'code'));
+ processDirectory(followOptions, dir);
+ }, 'running formatter');
+
+ d.dir('code', [
+ d.file('a.dart', formattedSource),
+ d.dir('linked_dir', [d.file('b.dart', formattedSource),])
+ ]).validate();
+ });
+
+ if (!Platform.isWindows) {
+ test("doesn't follow file symlinks by default", () {
+ d.dir('code').create();
+ d.file('target_file.dart', unformattedSource).create();
+
+ schedule(() {
+ // Create a link to the target file in the code directory.
+ new Link(p.join(d.defaultRoot, 'code', 'linked_file.dart'))
+ .createSync(p.join(d.defaultRoot, 'target_file.dart'));
+ }, 'Create symlinks.');
+
+ schedule(() {
+ var dir = new Directory(p.join(d.defaultRoot, 'code'));
+ processDirectory(overwriteOptions, dir);
+ }, 'Run formatter.');
+
+ d.dir('code', [d.file('linked_file.dart', unformattedSource),])
+ .validate();
+ });
+
+ test("follows file symlinks when 'followLinks' is true", () {
+ d.dir('code').create();
+ d.file('target_file.dart', unformattedSource).create();
+
+ schedule(() {
+ // Create a link to the target file in the code directory.
+ new Link(p.join(d.defaultRoot, 'code', 'linked_file.dart'))
+ .createSync(p.join(d.defaultRoot, 'target_file.dart'));
+ });
+
+ schedule(() {
+ var dir = new Directory(p.join(d.defaultRoot, 'code'));
+ processDirectory(followOptions, dir);
+ }, 'running formatter');
+
+ d.dir('code', [d.file('linked_file.dart', formattedSource),]).validate();
+ });
+ }
+}
« 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