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

Unified Diff: tests/standalone/io/file_test.dart

Issue 17033003: dart:io | Add File.rename (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes Created 7 years, 6 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 | « sdk/lib/io/file_impl.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/file_test.dart
diff --git a/tests/standalone/io/file_test.dart b/tests/standalone/io/file_test.dart
index b931475e23f23edeb843b3adc3d501f502a7526c..c34b82392180265ec4e2dc83b2d5d2c7e8d374c2 100644
--- a/tests/standalone/io/file_test.dart
+++ b/tests/standalone/io/file_test.dart
@@ -1218,6 +1218,59 @@ class FileTest {
Expect.isFalse(file.existsSync());
}
+ // Test that opens the same file for writing then for appending to test
+ // that the file is not truncated when opened for appending.
+ static void testRename() {
+ var file = new File('${tempDirectory.path}/rename_name');
+ file.create().then((file) {
+ file.rename("${tempDirectory.path}/rename_newname").then((newfile) {
+ file.exists().then((e) {
+ Expect.isFalse(e);
+ newfile.exists().then((e) {
+ Expect.isTrue(e);
+ newfile.delete().then((_) {
+ file.exists().then((e) {
+ Expect.isFalse(e);
+ if (Platform.operatingSystem != "windows") {
+ var brokenLink =
+ new Link('${tempDirectory.path}/rename_name');
+ brokenLink.create(
+ '${tempDirectory.path}/rename_newname').then((_) {
+ file.rename("xxx").then((_) {
+ throw "Rename of broken link succeeded";
+ }).catchError((e) {
+ Expect.isTrue(e is FileException);
+ asyncTestDone("testRename");
+ });
+ });
+
+ } else {
+ asyncTestDone("testRename");
+ }
+ });
+ });
+ });
+ });
+ });
+ });
+ asyncTestStarted();
+ }
+
+ static void testRenameSync() {
+ var file = new File('${tempDirectory.path}/rename_name_sync');
+ file.createSync();
+ var newfile = file.renameSync('${tempDirectory.path}/rename_newname_sync');
+ Expect.isFalse(file.existsSync());
+ Expect.isTrue(newfile.existsSync());
+ newfile.deleteSync();
+ Expect.isFalse(newfile.existsSync());
+ if (Platform.operatingSystem != "windows") {
+ var brokenLink = new Link('${tempDirectory.path}/rename_name_sync');
+ brokenLink.createSync('${tempDirectory.path}/rename_newname_sync');
+ Expect.throws(() => file.renameSync('xxx'));
+ }
+ }
+
// Helper method to be able to run the test from the runtime
// directory, or the top directory.
static String getFilename(String path) =>
@@ -1276,6 +1329,8 @@ class FileTest {
testDirectorySync();
testWriteStringUtf8();
testWriteStringUtf8Sync();
+ testRename();
+ testRenameSync();
});
}
}
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698