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

Unified Diff: pkg/front_end/test/physical_file_system_test.dart

Issue 2864183002: Throw FileSystemException from FileSystemEntity methods. (Closed)
Patch Set: Use OS error message if available. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/front_end/test/memory_file_system_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/test/physical_file_system_test.dart
diff --git a/pkg/front_end/test/physical_file_system_test.dart b/pkg/front_end/test/physical_file_system_test.dart
index d34457a787a3401992af8d4714b5b32f6ed8d575..9c7efd0849c39d1f294eeb0f8e2cef47f77bb29d 100644
--- a/pkg/front_end/test/physical_file_system_test.dart
+++ b/pkg/front_end/test/physical_file_system_test.dart
@@ -23,69 +23,64 @@ main() {
});
}
+const Matcher _throwsFileSystemException =
+ const Throws(const isInstanceOf<FileSystemException>());
+
@reflectiveTest
-class FileTest extends _BaseTest {
+class DirectoryTest extends _BaseTest {
String path;
- FileSystemEntity file;
+ FileSystemEntity dir;
setUp() {
super.setUp();
- path = p.join(tempPath, 'file.txt');
- file = PhysicalFileSystem.instance.entityForUri(p.toUri(path));
+ path = p.join(tempPath, 'dir');
+ dir = PhysicalFileSystem.instance.entityForUri(p.toUri(path));
}
test_equals_differentPaths() {
- expect(file == entityForPath(p.join(tempPath, 'file2.txt')), isFalse);
+ expect(dir == entityForPath(p.join(tempPath, 'dir2')), isFalse);
}
test_equals_samePath() {
- expect(file == entityForPath(p.join(tempPath, 'file.txt')), isTrue);
- }
-
- test_hashCode_samePath() {
- expect(file.hashCode, entityForPath(p.join(tempPath, 'file.txt')).hashCode);
+ expect(dir == entityForPath(p.join(tempPath, 'dir')), isTrue);
}
- test_readAsBytes_badUtf8() async {
- // A file containing invalid UTF-8 can still be read as raw bytes.
- List<int> bytes = [0xc0, 0x40]; // Invalid UTF-8
- new io.File(path).writeAsBytesSync(bytes);
- expect(await file.readAsBytes(), bytes);
+ test_exists_directoryExists() async {
+ await new io.Directory(path).create();
+ expect(await dir.exists(), isTrue);
}
- test_readAsBytes_doesNotExist() {
- expect(file.readAsBytes(), throwsException);
+ test_exists_doesNotExist() async {
+ expect(await dir.exists(), isFalse);
}
- test_readAsBytes_exists() async {
- var s = 'contents';
- new io.File(path).writeAsStringSync(s);
- expect(await file.readAsBytes(), UTF8.encode(s));
+ test_readAsBytes() async {
+ await new io.Directory(path).create();
+ expect(dir.readAsBytes(), _throwsFileSystemException);
}
- test_readAsString_badUtf8() {
- new io.File(path).writeAsBytesSync([0xc0, 0x40]); // Invalid UTF-8
- expect(file.readAsString(), throwsException);
+ test_uri() {
+ expect(dir.uri, p.toUri(path));
}
+}
- test_readAsString_doesNotExist() {
- expect(file.readAsString(), throwsException);
- }
+@reflectiveTest
+class FileTest extends _BaseTest {
+ String path;
+ FileSystemEntity file;
- test_readAsString_exists() async {
- var s = 'contents';
- new io.File(path).writeAsStringSync(s);
- expect(await file.readAsString(), s);
+ setUp() {
+ super.setUp();
+ path = p.join(tempPath, 'file.txt');
+ file = PhysicalFileSystem.instance.entityForUri(p.toUri(path));
}
- test_readAsString_utf8() async {
- var bytes = [0xe2, 0x82, 0xac]; // Unicode € symbol (in UTF-8)
- new io.File(path).writeAsBytesSync(bytes);
- expect(await file.readAsString(), '\u20ac');
+ test_equals_differentPaths() {
+ expect(file == entityForPath(p.join(tempPath, 'file2.txt')), isFalse);
}
- test_uri() {
- expect(file.uri, p.toUri(path));
+ test_equals_samePath() {
+ expect(file == entityForPath(p.join(tempPath, 'file.txt')), isTrue);
}
test_exists_doesNotExist() async {
@@ -97,6 +92,14 @@ class FileTest extends _BaseTest {
expect(await file.exists(), isTrue);
}
+ test_hashCode_samePath() {
+ expect(file.hashCode, entityForPath(p.join(tempPath, 'file.txt')).hashCode);
+ }
+
+ test_lastModified_doesNotExist() {
+ expect(file.lastModified(), _throwsFileSystemException);
+ }
+
test_lastModified_increasesOnEachChange() async {
new io.File(path).writeAsStringSync('contents1');
var mod1 = await file.lastModified();
@@ -114,43 +117,47 @@ class FileTest extends _BaseTest {
var mod3 = await file2.lastModified();
expect(mod3.isAfter(mod2), isTrue);
}
-}
-@reflectiveTest
-class DirectoryTest extends _BaseTest {
- String path;
- FileSystemEntity dir;
+ test_readAsBytes_badUtf8() async {
+ // A file containing invalid UTF-8 can still be read as raw bytes.
+ List<int> bytes = [0xc0, 0x40]; // Invalid UTF-8
+ new io.File(path).writeAsBytesSync(bytes);
+ expect(await file.readAsBytes(), bytes);
+ }
- setUp() {
- super.setUp();
- path = p.join(tempPath, 'dir');
- dir = PhysicalFileSystem.instance.entityForUri(p.toUri(path));
+ test_readAsBytes_doesNotExist() {
+ expect(file.readAsBytes(), _throwsFileSystemException);
}
- test_equals_differentPaths() {
- expect(dir == entityForPath(p.join(tempPath, 'dir2')), isFalse);
+ test_readAsBytes_exists() async {
+ var s = 'contents';
+ new io.File(path).writeAsStringSync(s);
+ expect(await file.readAsBytes(), UTF8.encode(s));
}
- test_equals_samePath() {
- expect(dir == entityForPath(p.join(tempPath, 'dir')), isTrue);
+ test_readAsString_badUtf8() {
+ new io.File(path).writeAsBytesSync([0xc0, 0x40]); // Invalid UTF-8
+ expect(file.readAsString(), _throwsFileSystemException);
}
- test_readAsBytes() async {
- await new io.Directory(path).create();
- expect(dir.readAsBytes(), throwsException);
+ test_readAsString_doesNotExist() {
+ expect(file.readAsString(), _throwsFileSystemException);
}
- test_uri() {
- expect(dir.uri, p.toUri(path));
+ test_readAsString_exists() async {
+ var s = 'contents';
+ new io.File(path).writeAsStringSync(s);
+ expect(await file.readAsString(), s);
}
- test_exists_doesNotExist() async {
- expect(await dir.exists(), isFalse);
+ test_readAsString_utf8() async {
+ var bytes = [0xe2, 0x82, 0xac]; // Unicode € symbol (in UTF-8)
+ new io.File(path).writeAsBytesSync(bytes);
+ expect(await file.readAsString(), '\u20ac');
}
- test_exists_directoryExists() async {
- await new io.Directory(path).create();
- expect(await dir.exists(), isTrue);
+ test_uri() {
+ expect(file.uri, p.toUri(path));
}
}
« no previous file with comments | « pkg/front_end/test/memory_file_system_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698