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

Side by Side Diff: pkg/front_end/test/physical_file_system_test.dart

Issue 2852463004: Revert "Extend file-system abstraction with a couple methods, remove context." (Closed)
Patch Set: Created 3 years, 7 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
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 // SharedOptions=--supermixin 4 // SharedOptions=--supermixin
5 5
6 library front_end.test.physical_file_system_test; 6 library front_end.test.physical_file_system_test;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:convert'; 9 import 'dart:convert';
10 import 'dart:io' as io; 10 import 'dart:io' as io;
11 11
12 import 'package:front_end/file_system.dart'; 12 import 'package:front_end/file_system.dart';
13 import 'package:front_end/physical_file_system.dart'; 13 import 'package:front_end/physical_file_system.dart';
14 import 'package:path/path.dart' as p; 14 import 'package:path/path.dart' as p;
15 import 'package:test/test.dart'; 15 import 'package:test/test.dart';
16 import 'package:test_reflective_loader/test_reflective_loader.dart'; 16 import 'package:test_reflective_loader/test_reflective_loader.dart';
17 17
18 main() { 18 main() {
19 defineReflectiveSuite(() { 19 defineReflectiveSuite(() {
20 defineReflectiveTests(PhysicalFileSystemTest); 20 defineReflectiveTests(PhysicalFileSystemTest);
21 defineReflectiveTests(FileTest); 21 defineReflectiveTests(FileTest);
22 defineReflectiveTests(DirectoryTest);
23 }); 22 });
24 } 23 }
25 24
26 @reflectiveTest 25 @reflectiveTest
27 class FileTest extends _BaseTest { 26 class FileTest extends _BaseTest {
28 String path; 27 String path;
29 FileSystemEntity file; 28 FileSystemEntity file;
30 29
31 setUp() { 30 setUp() {
32 super.setUp(); 31 super.setUp();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 79
81 test_readAsString_utf8() async { 80 test_readAsString_utf8() async {
82 var bytes = [0xe2, 0x82, 0xac]; // Unicode € symbol (in UTF-8) 81 var bytes = [0xe2, 0x82, 0xac]; // Unicode € symbol (in UTF-8)
83 new io.File(path).writeAsBytesSync(bytes); 82 new io.File(path).writeAsBytesSync(bytes);
84 expect(await file.readAsString(), '\u20ac'); 83 expect(await file.readAsString(), '\u20ac');
85 } 84 }
86 85
87 test_uri() { 86 test_uri() {
88 expect(file.uri, p.toUri(path)); 87 expect(file.uri, p.toUri(path));
89 } 88 }
90
91 test_exists_doesNotExist() async {
92 expect(await file.exists(), isFalse);
93 }
94
95 test_exists_fileExists() async {
96 new io.File(path).writeAsStringSync('contents');
97 expect(await file.exists(), isTrue);
98 }
99
100 test_lastModified_increasesOnEachChange() async {
101 new io.File(path).writeAsStringSync('contents1');
102 var mod1 = await file.lastModified();
103
104 // Pause to ensure the file-system time-stamps are different.
105 await new Future.delayed(new Duration(seconds: 1));
106 new io.File(path).writeAsStringSync('contents2');
107 var mod2 = await file.lastModified();
108 expect(mod2.isAfter(mod1), isTrue);
109
110 await new Future.delayed(new Duration(seconds: 1));
111 var path2 = p.join(tempPath, 'file2.txt');
112 new io.File(path2).writeAsStringSync('contents2');
113 var file2 = entityForPath(path2);
114 var mod3 = await file2.lastModified();
115 expect(mod3.isAfter(mod2), isTrue);
116 }
117 } 89 }
118 90
119 @reflectiveTest 91 @reflectiveTest
120 class DirectoryTest extends _BaseTest {
121 String path;
122 FileSystemEntity dir;
123
124 setUp() {
125 super.setUp();
126 path = p.join(tempPath, 'dir');
127 dir = PhysicalFileSystem.instance.entityForUri(p.toUri(path));
128 }
129
130 test_equals_differentPaths() {
131 expect(dir == entityForPath(p.join(tempPath, 'dir2')), isFalse);
132 }
133
134 test_equals_samePath() {
135 expect(dir == entityForPath(p.join(tempPath, 'dir')), isTrue);
136 }
137
138 test_readAsBytes() async {
139 new io.Directory(path).create();
140 expect(dir.readAsBytes(), throwsException);
141 }
142
143 test_uri() {
144 expect(dir.uri, p.toUri(path));
145 }
146
147 test_exists_doesNotExist() async {
148 expect(await dir.exists(), isFalse);
149 }
150
151 test_exists_directoryExists() async {
152 new io.Directory(path).create();
153 expect(await dir.exists(), isTrue);
154 }
155 }
156
157 @reflectiveTest
158 class PhysicalFileSystemTest extends _BaseTest { 92 class PhysicalFileSystemTest extends _BaseTest {
159 Uri tempUri; 93 Uri tempUri;
160 94
161 setUp() { 95 setUp() {
162 super.setUp(); 96 super.setUp();
163 tempUri = new Uri.directory(tempPath); 97 tempUri = new Uri.directory(tempPath);
164 } 98 }
165 99
166 test_entityForPath() { 100 test_entityForPath() {
167 var path = p.join(tempPath, 'file.txt'); 101 var path = p.join(tempPath, 'file.txt');
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 tempDirectory.deleteSync(recursive: true); 190 tempDirectory.deleteSync(recursive: true);
257 } on io.FileSystemException { 191 } on io.FileSystemException {
258 // Sometimes on Windows the delete fails with errno 32 192 // Sometimes on Windows the delete fails with errno 32
259 // (ERROR_SHARING_VIOLATION: The process cannot access the file because it 193 // (ERROR_SHARING_VIOLATION: The process cannot access the file because it
260 // is being used by another process). Wait 1 second and try again. 194 // is being used by another process). Wait 1 second and try again.
261 await new Future.delayed(new Duration(seconds: 1)); 195 await new Future.delayed(new Duration(seconds: 1));
262 tempDirectory.deleteSync(recursive: true); 196 tempDirectory.deleteSync(recursive: true);
263 } 197 }
264 } 198 }
265 } 199 }
OLDNEW
« no previous file with comments | « pkg/front_end/test/memory_file_system_test.dart ('k') | pkg/front_end/test/src/base/processed_options_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698