OLD | NEW |
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); |
22 }); | 23 }); |
23 } | 24 } |
24 | 25 |
25 @reflectiveTest | 26 @reflectiveTest |
26 class FileTest extends _BaseTest { | 27 class FileTest extends _BaseTest { |
27 String path; | 28 String path; |
28 FileSystemEntity file; | 29 FileSystemEntity file; |
29 | 30 |
30 setUp() { | 31 setUp() { |
31 super.setUp(); | 32 super.setUp(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 80 |
80 test_readAsString_utf8() async { | 81 test_readAsString_utf8() async { |
81 var bytes = [0xe2, 0x82, 0xac]; // Unicode € symbol (in UTF-8) | 82 var bytes = [0xe2, 0x82, 0xac]; // Unicode € symbol (in UTF-8) |
82 new io.File(path).writeAsBytesSync(bytes); | 83 new io.File(path).writeAsBytesSync(bytes); |
83 expect(await file.readAsString(), '\u20ac'); | 84 expect(await file.readAsString(), '\u20ac'); |
84 } | 85 } |
85 | 86 |
86 test_uri() { | 87 test_uri() { |
87 expect(file.uri, p.toUri(path)); | 88 expect(file.uri, p.toUri(path)); |
88 } | 89 } |
| 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 } |
89 } | 117 } |
90 | 118 |
91 @reflectiveTest | 119 @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 await 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 await new io.Directory(path).create(); |
| 153 expect(await dir.exists(), isTrue); |
| 154 } |
| 155 } |
| 156 |
| 157 @reflectiveTest |
92 class PhysicalFileSystemTest extends _BaseTest { | 158 class PhysicalFileSystemTest extends _BaseTest { |
93 Uri tempUri; | 159 Uri tempUri; |
94 | 160 |
95 setUp() { | 161 setUp() { |
96 super.setUp(); | 162 super.setUp(); |
97 tempUri = new Uri.directory(tempPath); | 163 tempUri = new Uri.directory(tempPath); |
98 } | 164 } |
99 | 165 |
100 test_entityForPath() { | 166 test_entityForPath() { |
101 var path = p.join(tempPath, 'file.txt'); | 167 var path = p.join(tempPath, 'file.txt'); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 tempDirectory.deleteSync(recursive: true); | 256 tempDirectory.deleteSync(recursive: true); |
191 } on io.FileSystemException { | 257 } on io.FileSystemException { |
192 // Sometimes on Windows the delete fails with errno 32 | 258 // Sometimes on Windows the delete fails with errno 32 |
193 // (ERROR_SHARING_VIOLATION: The process cannot access the file because it | 259 // (ERROR_SHARING_VIOLATION: The process cannot access the file because it |
194 // is being used by another process). Wait 1 second and try again. | 260 // is being used by another process). Wait 1 second and try again. |
195 await new Future.delayed(new Duration(seconds: 1)); | 261 await new Future.delayed(new Duration(seconds: 1)); |
196 tempDirectory.deleteSync(recursive: true); | 262 tempDirectory.deleteSync(recursive: true); |
197 } | 263 } |
198 } | 264 } |
199 } | 265 } |
OLD | NEW |