[corlib] Add test for deleting non-existing file
authorAlexander Köplinger <alex.koeplinger@outlook.com>
Wed, 5 Jul 2017 15:54:47 +0000 (17:54 +0200)
committerAlexander Köplinger <alex.koeplinger@outlook.com>
Fri, 7 Jul 2017 14:17:56 +0000 (16:17 +0200)
It shouldn't throw in that case.

Helps cover https://bugzilla.xamarin.com/show_bug.cgi?id=57629
(note that we don't explicitly test on a readonly FS as that is hard
to do in a unit test, but running this test on Android should suffice).

mcs/class/corlib/Test/System.IO/DriveInfoTest.cs
mcs/class/corlib/Test/System.IO/FileTest.cs
mcs/class/test-helpers/NunitHelpers.cs

index 44d4f78cd95f8fe5336568f042bc808a25f0aadf..1d78d88b3a3710d0e3e53e557178d17413c9da92 100644 (file)
@@ -41,23 +41,30 @@ namespace MonoTests.System.IO
        public class DriveInfoTest
        {
                [Test]
-               [Category ("MobileNotWorking")]
                public void Constructor ()
                {
-                       var drive = new DriveInfo (Environment.OSVersion.Platform == PlatformID.Unix ? "/" : "C:\\");
+                       if (Environment.OSVersion.Platform != PlatformID.Win32NT)
+                               Assert.Ignore ("The Jenkins builders don't have '/' mounted, just testing Windows for now.");
+
+                       var drive = new DriveInfo ("C:\\");
                        ValidateDriveInfo (drive);
                        Assert.AreEqual (DriveType.Fixed, drive.DriveType);
                }
 
+               [Test]
+               public void ConstructorThrowsOnNonExistingDrive ()
+               {
+                       Assert.Throws<ArgumentException> (() => new DriveInfo ("/monodriveinfotest"));
+               }
+
                [Test]
                public void GetDrivesNotEmpty ()
                {
                        var drives = DriveInfo.GetDrives ();
-                       Assert.That (drives, Is.Not.Empty);
+                       CollectionAssert.IsNotEmpty (drives);
                }
 
                [Test]
-               [Category ("MobileNotWorking")]
                public void GetDrivesValidInfo ()
                {
                        var drives = DriveInfo.GetDrives ();
@@ -69,17 +76,21 @@ namespace MonoTests.System.IO
 
                void ValidateDriveInfo (DriveInfo d)
                {
-                       Assert.That (d.Name, Is.Not.Empty);
-                       Assert.That (d.VolumeLabel, Is.Not.Empty);
+                       AssertHelper.IsNotEmpty (d.Name);
+                       AssertHelper.IsNotEmpty (d.VolumeLabel);
                        Assert.NotNull (d.RootDirectory);
 
-                       AssertHelper.GreaterOrEqual (d.AvailableFreeSpace, 0);
-                       AssertHelper.GreaterOrEqual (d.TotalFreeSpace, 0);
-                       AssertHelper.GreaterOrEqual (d.TotalSize, 0);
+                       if (d.DriveFormat != null) {
+                               Assert.AreNotEqual ("", d.DriveFormat);
+                               Assert.AreNotEqual (DriveType.Unknown, d.DriveType, "DriveFormat=" + d.DriveFormat);
+                       }
 
-                       Assert.That (d.DriveFormat, Is.Not.Empty);
-                       if (d.DriveType == DriveType.Fixed)
+                       if (d.DriveType == DriveType.Fixed) { // just consider fixed drives for now
                                Assert.True (d.IsReady);
+                               AssertHelper.GreaterOrEqual (d.AvailableFreeSpace, 0);
+                               AssertHelper.GreaterOrEqual (d.TotalFreeSpace, 0);
+                               AssertHelper.GreaterOrEqual (d.TotalSize, 0);
+                       }
                }
        }
 }
index 4fc95243fe0b899020c9f96256de8d9387082442..4528027b24e9bc730bcb914ef0f2573189f1cc90 100644 (file)
@@ -532,6 +532,12 @@ namespace MonoTests.System.IO
                        }
                }
 
+               [Test]
+               public void Delete_NonExisting_NoException ()
+               {
+                       File.Delete (Path.Combine (Directory.GetDirectoryRoot (Directory.GetCurrentDirectory ()), "monononexistingfile.dat"));
+               }
+
                [Test]
                public void GetAttributes_Archive ()
                {
index 5bc3211f89a2885bc0548205b18312a4976397bc..20ea722a1551791e8dfc5c61379586f400157650 100644 (file)
@@ -30,6 +30,11 @@ namespace NUnit.Framework
                {
                        Assert.That(collection, new EmptyCollectionConstraint(), message, args);
                }
+
+               public static void IsNotEmpty(IEnumerable collection, string message = null, params object[] args)
+               {
+                       Assert.That(collection, Is.Not.Empty, message, args);
+               }
        }
 
        static class FileAssert