Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStephen Toub <stoub@microsoft.com>2017-06-01 23:10:17 +0300
committerDan Moseley <danmose@microsoft.com>2017-06-01 23:10:17 +0300
commita84b402d70d5720268649c4707ddb3152974fa08 (patch)
treed4a168276200f65094691b9eb3b2a9da923cffe5 /src
parentd44eb05f19f0e5fdbcc2978d06b822f75ee7a5c2 (diff)
Remove TemporaryDirectory/File from FileSystem tests (#20576)
* Remove TemporaryDirectory/File from FileSystem tests * Explicitly set UseShellExecute=false in MountHelper
Diffstat (limited to 'src')
-rw-r--r--src/System.IO.FileSystem/tests/Directory/CreateDirectory.cs22
-rw-r--r--src/System.IO.FileSystem/tests/Directory/GetDirectories.cs44
-rw-r--r--src/System.IO.FileSystem/tests/Directory/GetFiles.cs33
-rw-r--r--src/System.IO.FileSystem/tests/FileSystemTest.cs41
-rw-r--r--src/System.IO.FileSystem/tests/PortedCommon/ReparsePointUtilities.cs1
-rw-r--r--src/System.IO.FileSystem/tests/PortedCommon/TemporaryDirectory.cs30
-rw-r--r--src/System.IO.FileSystem/tests/PortedCommon/TemporaryFile.cs20
-rw-r--r--src/System.IO.FileSystem/tests/PortedCommon/TemporaryFileSystemItem.cs82
-rw-r--r--src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj3
9 files changed, 67 insertions, 209 deletions
diff --git a/src/System.IO.FileSystem/tests/Directory/CreateDirectory.cs b/src/System.IO.FileSystem/tests/Directory/CreateDirectory.cs
index df92fd0ba3..a5db695dc5 100644
--- a/src/System.IO.FileSystem/tests/Directory/CreateDirectory.cs
+++ b/src/System.IO.FileSystem/tests/Directory/CreateDirectory.cs
@@ -359,14 +359,11 @@ namespace System.IO.Tests
public void WindowsExtendedSyntaxWhiteSpace()
{
var paths = IOInputs.GetSimpleWhiteSpace();
- using (TemporaryDirectory directory = new TemporaryDirectory())
- {
- foreach (var path in paths)
- {
- string extendedPath = Path.Combine(IOInputs.ExtendedPrefix + directory.Path, path);
- Directory.CreateDirectory(extendedPath);
- Assert.True(Directory.Exists(extendedPath), extendedPath);
- }
+ foreach (var path in paths)
+ {
+ string extendedPath = Path.Combine(IOInputs.ExtendedPrefix + TestDirectory, path);
+ Directory.CreateDirectory(extendedPath);
+ Assert.True(Directory.Exists(extendedPath), extendedPath);
}
}
@@ -416,13 +413,10 @@ namespace System.IO.Tests
public void PathWithReservedDeviceNameAsExtendedPath()
{
var paths = IOInputs.GetReservedDeviceNames();
- using (TemporaryDirectory directory = new TemporaryDirectory())
+ Assert.All(paths, (path) =>
{
- Assert.All(paths, (path) =>
- {
- Assert.True(Create(IOInputs.ExtendedPrefix + Path.Combine(directory.Path, path)).Exists, path);
- });
- }
+ Assert.True(Create(IOInputs.ExtendedPrefix + Path.Combine(TestDirectory, path)).Exists, path);
+ });
}
[Fact]
diff --git a/src/System.IO.FileSystem/tests/Directory/GetDirectories.cs b/src/System.IO.FileSystem/tests/Directory/GetDirectories.cs
index f7ab14bcbf..0f5adb759d 100644
--- a/src/System.IO.FileSystem/tests/Directory/GetDirectories.cs
+++ b/src/System.IO.FileSystem/tests/Directory/GetDirectories.cs
@@ -21,31 +21,31 @@ namespace System.IO.Tests
[ConditionalFact(nameof(CanCreateSymbolicLinks))]
public void EnumerateWithSymLinkToDirectory()
{
- using (var containingFolder = new TemporaryDirectory())
+ DirectoryInfo containingFolder = Directory.CreateDirectory(GetTestFilePath());
+
+ // Test a symlink to a directory that does and then doesn't exist
+ DirectoryInfo targetDir = Directory.CreateDirectory(GetTestFilePath());
{
- // Test a symlink to a directory that does and then doesn't exist
- using (var targetDir = new TemporaryDirectory())
- {
- // Create a symlink to a folder that exists
- string linkPath = Path.Combine(containingFolder.Path, Path.GetRandomFileName());
- Assert.True(MountHelper.CreateSymbolicLink(linkPath, targetDir.Path, isDirectory: true));
+ // Create a symlink to a folder that exists
+ string linkPath = Path.Combine(containingFolder.FullName, Path.GetRandomFileName());
+ Assert.True(MountHelper.CreateSymbolicLink(linkPath, targetDir.FullName, isDirectory: true));
- Assert.True(Directory.Exists(linkPath));
- Assert.Equal(1, GetEntries(containingFolder.Path).Count());
- }
+ Assert.True(Directory.Exists(linkPath));
+ Assert.Equal(1, GetEntries(containingFolder.FullName).Count());
+ }
+ targetDir.Delete(recursive: true);
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- {
- Assert.Equal(1, GetEntries(containingFolder.Path).Count());
- Assert.Equal(0, Directory.GetFiles(containingFolder.Path).Count());
- }
- else
- {
- // The target file is gone and the symlink still exists; since it can't be resolved,
- // on Unix it's treated as a file rather than as a directory.
- Assert.Equal(0, GetEntries(containingFolder.Path).Count());
- Assert.Equal(1, Directory.GetFiles(containingFolder.Path).Count());
- }
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ {
+ Assert.Equal(1, GetEntries(containingFolder.FullName).Count());
+ Assert.Equal(0, Directory.GetFiles(containingFolder.FullName).Count());
+ }
+ else
+ {
+ // The target file is gone and the symlink still exists; since it can't be resolved,
+ // on Unix it's treated as a file rather than as a directory.
+ Assert.Equal(0, GetEntries(containingFolder.FullName).Count());
+ Assert.Equal(1, Directory.GetFiles(containingFolder.FullName).Count());
}
}
}
diff --git a/src/System.IO.FileSystem/tests/Directory/GetFiles.cs b/src/System.IO.FileSystem/tests/Directory/GetFiles.cs
index c999231add..3c4724334f 100644
--- a/src/System.IO.FileSystem/tests/Directory/GetFiles.cs
+++ b/src/System.IO.FileSystem/tests/Directory/GetFiles.cs
@@ -21,27 +21,26 @@ namespace System.IO.Tests
[ConditionalFact(nameof(CanCreateSymbolicLinks))]
public void EnumerateWithSymLinkToFile()
{
- using (var containingFolder = new TemporaryDirectory())
- {
- string linkPath;
+ DirectoryInfo containingFolder = Directory.CreateDirectory(GetTestFilePath());
- // Test a symlink to a file that does and then doesn't exist
- using (var targetFile = new TemporaryFile())
- {
- linkPath = Path.Combine(containingFolder.Path, Path.GetRandomFileName());
- Assert.True(MountHelper.CreateSymbolicLink(linkPath, targetFile.Path, isDirectory: false));
+ // Test a symlink to a file that does and then doesn't exist
+ FileInfo targetFile = new FileInfo(GetTestFilePath());
+ targetFile.Create().Dispose();
- Assert.True(File.Exists(linkPath));
- Assert.Equal(1, GetEntries(containingFolder.Path).Count());
- }
+ string linkPath = Path.Combine(containingFolder.FullName, Path.GetRandomFileName());
+ Assert.True(MountHelper.CreateSymbolicLink(linkPath, targetFile.FullName, isDirectory: false));
- // The symlink still exists even though the target file is gone.
- Assert.Equal(1, GetEntries(containingFolder.Path).Count());
+ Assert.True(File.Exists(linkPath));
+ Assert.Equal(1, GetEntries(containingFolder.FullName).Count());
- // The symlink is gone
- File.Delete(linkPath);
- Assert.Equal(0, GetEntries(containingFolder.Path).Count());
- }
+ targetFile.Delete();
+
+ // The symlink still exists even though the target file is gone.
+ Assert.Equal(1, GetEntries(containingFolder.FullName).Count());
+
+ // The symlink is gone
+ File.Delete(linkPath);
+ Assert.Equal(0, GetEntries(containingFolder.FullName).Count());
}
}
diff --git a/src/System.IO.FileSystem/tests/FileSystemTest.cs b/src/System.IO.FileSystem/tests/FileSystemTest.cs
index 07aaef81f6..d3627c51c0 100644
--- a/src/System.IO.FileSystem/tests/FileSystemTest.cs
+++ b/src/System.IO.FileSystem/tests/FileSystemTest.cs
@@ -29,28 +29,27 @@ namespace System.IO.Tests
/// the symbolic link may fail to create. Only run this test if it creates
/// links successfully.
/// </summary>
- protected static bool CanCreateSymbolicLinks
+ protected static bool CanCreateSymbolicLinks { get; } = ComputeCanCreateSymbolicLinks();
+
+ private static bool ComputeCanCreateSymbolicLinks()
{
- get
- {
- bool success = true;
-
- // Verify file symlink creation
- string path = Path.GetTempFileName();
- string linkPath = path + ".link";
- success = MountHelper.CreateSymbolicLink(linkPath, path, isDirectory: false);
- try { File.Delete(path); } catch { }
- try { File.Delete(linkPath); } catch { }
-
- // Verify directory symlink creation
- path = Path.GetTempFileName();
- linkPath = path + ".link";
- success = success && MountHelper.CreateSymbolicLink(linkPath, path, isDirectory: true);
- try { Directory.Delete(path); } catch { }
- try { Directory.Delete(linkPath); } catch { }
-
- return success;
- }
+ bool success = true;
+
+ // Verify file symlink creation
+ string path = Path.GetTempFileName();
+ string linkPath = path + ".link";
+ success = MountHelper.CreateSymbolicLink(linkPath, path, isDirectory: false);
+ try { File.Delete(path); } catch { }
+ try { File.Delete(linkPath); } catch { }
+
+ // Verify directory symlink creation
+ path = Path.GetTempFileName();
+ linkPath = path + ".link";
+ success = success && MountHelper.CreateSymbolicLink(linkPath, path, isDirectory: true);
+ try { Directory.Delete(path); } catch { }
+ try { Directory.Delete(linkPath); } catch { }
+
+ return success;
}
}
}
diff --git a/src/System.IO.FileSystem/tests/PortedCommon/ReparsePointUtilities.cs b/src/System.IO.FileSystem/tests/PortedCommon/ReparsePointUtilities.cs
index 756817a254..d9bf124acf 100644
--- a/src/System.IO.FileSystem/tests/PortedCommon/ReparsePointUtilities.cs
+++ b/src/System.IO.FileSystem/tests/PortedCommon/ReparsePointUtilities.cs
@@ -45,6 +45,7 @@ public static class MountHelper
symLinkProcess.StartInfo.FileName = "/bin/ln";
symLinkProcess.StartInfo.Arguments = string.Format("-s \"{0}\" \"{1}\"", targetPath, linkPath);
}
+ symLinkProcess.StartInfo.UseShellExecute = false;
symLinkProcess.StartInfo.RedirectStandardOutput = true;
symLinkProcess.Start();
diff --git a/src/System.IO.FileSystem/tests/PortedCommon/TemporaryDirectory.cs b/src/System.IO.FileSystem/tests/PortedCommon/TemporaryDirectory.cs
deleted file mode 100644
index eabbcaa71c..0000000000
--- a/src/System.IO.FileSystem/tests/PortedCommon/TemporaryDirectory.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System;
-using System.IO;
-using IOPath = System.IO.Path;
-
-internal class TemporaryDirectory : TemporaryFileSystemItem<DirectoryInfo>
-{
- public TemporaryDirectory()
- : base(CreateTemporaryDirectoryInfo())
- {
- }
-
- protected override void Delete()
- {
- if (Directory.Exists(Path))
- {
- Directory.Delete(Path, true);
- }
- }
-
- private static DirectoryInfo CreateTemporaryDirectoryInfo()
- {
- string path = IOPath.Combine(TestInfo.CurrentDirectory, IOPath.GetRandomFileName());
-
- return Directory.CreateDirectory(path);
- }
-}
diff --git a/src/System.IO.FileSystem/tests/PortedCommon/TemporaryFile.cs b/src/System.IO.FileSystem/tests/PortedCommon/TemporaryFile.cs
deleted file mode 100644
index 51c59b0544..0000000000
--- a/src/System.IO.FileSystem/tests/PortedCommon/TemporaryFile.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System;
-using System.IO;
-using IOPath = System.IO.Path;
-
-internal class TemporaryFile : TemporaryFileSystemItem<FileInfo>
-{
- public TemporaryFile()
- : base(new FileInfo(IOPath.GetTempFileName()))
- {
- }
-
- protected override void Delete()
- {
- File.Delete(Path);
- }
-}
diff --git a/src/System.IO.FileSystem/tests/PortedCommon/TemporaryFileSystemItem.cs b/src/System.IO.FileSystem/tests/PortedCommon/TemporaryFileSystemItem.cs
deleted file mode 100644
index 20a29020ec..0000000000
--- a/src/System.IO.FileSystem/tests/PortedCommon/TemporaryFileSystemItem.cs
+++ /dev/null
@@ -1,82 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System;
-using System.Diagnostics;
-using System.IO;
-using IOPath = System.IO.Path;
-
-internal abstract class TemporaryFileSystemItem<T> : IDisposable
- where T : FileSystemInfo
-{
- private readonly T _info;
-
- protected TemporaryFileSystemItem(T info)
- {
-#if !TEST_WINRT // TODO: reenable once DirectoryInfo adapter is in place
- Debug.Assert(info.Exists);
-#endif
-
- _info = info;
- }
-
- public string Path
- {
- get { return _info.FullName; }
- }
-
- public string Drive
- {
- get { return IOServices.RemoveTrailingSlash(IOPath.GetPathRoot(_info.FullName)); }
- }
-
- public T Info
- {
- get { return _info; }
- }
-
- public bool IsReadOnly
- {
- get { return (_info.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly; }
- set
- {
- if (value)
- {
- _info.Attributes |= FileAttributes.ReadOnly;
- }
- else
- {
- _info.Attributes &= ~FileAttributes.ReadOnly;
- }
- }
- }
-
- public bool IsHidden
- {
- get { return (_info.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden; }
- set
- {
- if (value)
- {
- _info.Attributes |= FileAttributes.Hidden;
- }
- else
- {
- _info.Attributes &= ~FileAttributes.Hidden;
- }
- }
- }
-
- public void Dispose()
- {
- if (Info.Exists && IsReadOnly)
- {
- IsReadOnly = false;
- }
-
- Delete();
- }
-
- protected abstract void Delete();
-}
diff --git a/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj b/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj
index 02cbadaf0d..edbca98c81 100644
--- a/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj
+++ b/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj
@@ -107,9 +107,6 @@
<Compile Include="PortedCommon\IOServices.cs" />
<Compile Include="PortedCommon\PathInfo.cs" />
<Compile Include="PortedCommon\ReparsePointUtilities.cs" />
- <Compile Include="PortedCommon\TemporaryDirectory.cs" />
- <Compile Include="PortedCommon\TemporaryFile.cs" />
- <Compile Include="PortedCommon\TemporaryFileSystemItem.cs" />
<Compile Include="DirectoryInfo\EnumerableAPIs.cs" />
<Compile Include="DirectoryInfo\GetDirectories.cs" />
<Compile Include="DirectoryInfo\GetFiles.cs" />