Add a test where we attempt to rename a file.

Change-Id: I9901f8abefe1e652307e15f05ef66d033a16a02f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/220420
Commit-Queue: Brian Quinlan <bquinlan@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
diff --git a/tests/standalone/io/directory_rename_test.dart b/tests/standalone/io/directory_rename_test.dart
index a105e46..de14cea 100644
--- a/tests/standalone/io/directory_rename_test.dart
+++ b/tests/standalone/io/directory_rename_test.dart
@@ -130,6 +130,25 @@
   });
 }
 
+testRenameButActuallyFile() async {
+  await withTempDir('testRenameButActuallyFile', (Directory tempDir) async {
+    final file = File("${tempDir.path}/file");
+    file.createSync();
+    final dir = Directory(file.path);
+    try {
+      dir.renameSync("${tempDir.path}/dir");
+      Expect.fail("Expected a failure to rename the file.");
+    } on FileSystemException catch (e) {
+      Expect.isTrue(
+          e.message.contains('Rename failed'), 'Unexpected error: $e');
+      if (Platform.isLinux || Platform.isMacOS) {
+        Expect.isTrue(e.osError!.message.contains('Not a directory'),
+            'Unexpected error: $e');
+      }
+    }
+  });
+}
+
 main() async {
   await testRenameToNewPath();
   await testRenamePath();
@@ -137,4 +156,5 @@
   await testRenameToExistingFile();
   await testRenameToExistingEmptyDirectory();
   await testRenameToExistingNonEmptyDirectory();
+  await testRenameButActuallyFile();
 }
diff --git a/tests/standalone_2/io/directory_rename_test.dart b/tests/standalone_2/io/directory_rename_test.dart
index ecd0b0e..5f47913 100644
--- a/tests/standalone_2/io/directory_rename_test.dart
+++ b/tests/standalone_2/io/directory_rename_test.dart
@@ -132,6 +132,25 @@
   });
 }
 
+testRenameButActuallyFile() async {
+  await withTempDir('testRenameButActuallyFile', (Directory tempDir) async {
+    final file = File("${tempDir.path}/file");
+    file.createSync();
+    final dir = Directory(file.path);
+    try {
+      dir.renameSync("${tempDir.path}/dir");
+      Expect.fail("Expected a failure to rename the file.");
+    } on FileSystemException catch (e) {
+      Expect.isTrue(
+          e.message.contains('Rename failed'), 'Unexpected error: $e');
+      if (Platform.isLinux || Platform.isMacOS) {
+        Expect.isTrue(e.osError.message.contains('Not a directory'),
+            'Unexpected error: $e');
+      }
+    }
+  });
+}
+
 main() async {
   await testRenameToNewPath();
   await testRenamePath();
@@ -139,4 +158,5 @@
   await testRenameToExistingFile();
   await testRenameToExistingEmptyDirectory();
   await testRenameToExistingNonEmptyDirectory();
+  await testRenameButActuallyFile();
 }