From 193ee83dc88122e154ab02855caa905776663a61 Mon Sep 17 00:00:00 2001 From: Jo Shields Date: Wed, 26 Oct 2022 05:00:48 -0400 Subject: [PATCH] Resolve tvOS/iOS FileSystem test failures (#74927) * Use SetCurrentDirectory on tests which use an unrooted path on non-Windows out of the app's working directory, which is readonly on some platforms. Closes: #67853 * Just blank out mkfifo tests --- .../tests/Directory/CreateDirectory.cs | 51 ++++++++++--------- .../tests/Directory/Delete.cs | 33 ++++++++---- .../tests/Directory/Exists.cs | 3 +- .../tests/DirectoryInfo/Exists.cs | 3 +- .../System.IO.FileSystem/tests/File/Exists.cs | 3 +- .../tests/File/ReadWriteAllBytes.cs | 3 +- .../tests/File/ReadWriteAllBytesAsync.cs | 3 +- .../tests/FileInfo/Exists.cs | 3 +- .../tests/Path/Exists_File.cs | 3 +- 9 files changed, 56 insertions(+), 49 deletions(-) diff --git a/src/libraries/System.IO.FileSystem/tests/Directory/CreateDirectory.cs b/src/libraries/System.IO.FileSystem/tests/Directory/CreateDirectory.cs index 4cf06cc34b99f..7ed023adca957 100644 --- a/src/libraries/System.IO.FileSystem/tests/Directory/CreateDirectory.cs +++ b/src/libraries/System.IO.FileSystem/tests/Directory/CreateDirectory.cs @@ -466,34 +466,37 @@ public void DriveLetter_Windows() Assert.Equal(current.FullName, driveLetter.FullName); } - [Fact] + [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [PlatformSpecific(TestPlatforms.AnyUnix)] // drive letters casing - [ActiveIssue("https://github.com/dotnet/runtime/issues/67853", TestPlatforms.iOS | TestPlatforms.tvOS)] public void DriveLetter_Unix() { - // On Unix, there's no special casing for drive letters. These may or may not be valid names, depending - // on the file system underlying the current directory. Unix file systems typically allow these, but, - // for example, these names are not allowed if running on a file system mounted from a Windows machine. - DirectoryInfo driveLetter; - try - { - driveLetter = Create("C:"); - } - catch (IOException) - { - return; - } - var current = Create("."); - Assert.Equal("C:", driveLetter.Name); - Assert.Equal(Path.Combine(current.FullName, "C:"), driveLetter.FullName); - try + RemoteExecutor.Invoke(() => { - // If this test is inherited then it's possible this call will fail due to the "C:" directory - // being deleted in that other test before this call. What we care about testing (proper path - // handling) is unaffected by this race condition. - Directory.Delete("C:"); - } - catch (DirectoryNotFoundException) { } + Directory.SetCurrentDirectory(Path.GetTempPath()); + // On Unix, there's no special casing for drive letters. These may or may not be valid names, depending + // on the file system underlying the current directory. Unix file systems typically allow these, but, + // for example, these names are not allowed if running on a file system mounted from a Windows machine. + DirectoryInfo driveLetter; + try + { + driveLetter = Create("C:"); + } + catch (IOException) + { + return; + } + var current = Create("."); + Assert.Equal("C:", driveLetter.Name); + Assert.Equal(Path.Combine(current.FullName, "C:"), driveLetter.FullName); + try + { + // If this test is inherited then it's possible this call will fail due to the "C:" directory + // being deleted in that other test before this call. What we care about testing (proper path + // handling) is unaffected by this race condition. + Directory.Delete("C:"); + } + catch (DirectoryNotFoundException) { } + }).Dispose(); } [Fact] diff --git a/src/libraries/System.IO.FileSystem/tests/Directory/Delete.cs b/src/libraries/System.IO.FileSystem/tests/Directory/Delete.cs index feef272704f48..f86cae23145af 100644 --- a/src/libraries/System.IO.FileSystem/tests/Directory/Delete.cs +++ b/src/libraries/System.IO.FileSystem/tests/Directory/Delete.cs @@ -3,6 +3,7 @@ using System.Text; using Xunit; +using Microsoft.DotNet.RemoteExecutor; using Microsoft.DotNet.XUnitExtensions; namespace System.IO.Tests @@ -13,6 +14,10 @@ public class Directory_Delete_str : FileSystemTest static bool IsBindMountSupportedAndOnUnixAndSuperUser => IsBindMountSupported && PlatformDetection.IsUnixAndSuperUser; + static bool IsRemoteExecutorSupportedAndUsingNewNormalization => RemoteExecutor.IsSupported && UsingNewNormalization; + + static bool IsRemoteExecutorSupportedAndLongPathsAreNotBlockedAndUsingNewNormalization => RemoteExecutor.IsSupported && LongPathsAreNotBlocked && UsingNewNormalization; + #region Utilities protected virtual void Delete(string path) @@ -121,23 +126,29 @@ public void DeletingSymLinkDoesntDeleteTarget() Assert.False(Directory.Exists(linkPath), "linkPath should no longer exist"); } - [ConditionalFact(nameof(UsingNewNormalization))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/67853", TestPlatforms.iOS | TestPlatforms.tvOS)] + [ConditionalFact(nameof(IsRemoteExecutorSupportedAndUsingNewNormalization))] public void ExtendedDirectoryWithSubdirectories() { - DirectoryInfo testDir = Directory.CreateDirectory(IOInputs.ExtendedPrefix + GetTestFilePath()); - testDir.CreateSubdirectory(GetTestFileName()); - Assert.Throws(() => Delete(testDir.FullName)); - Assert.True(testDir.Exists); + RemoteExecutor.Invoke(() => + { + Directory.SetCurrentDirectory(Path.GetTempPath()); + DirectoryInfo testDir = Directory.CreateDirectory(IOInputs.ExtendedPrefix + GetTestFilePath()); + testDir.CreateSubdirectory(GetTestFileName()); + Assert.Throws(() => Delete(testDir.FullName)); + Assert.True(testDir.Exists); + }).Dispose(); } - [ConditionalFact(nameof(LongPathsAreNotBlocked), nameof(UsingNewNormalization))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/67853", TestPlatforms.iOS | TestPlatforms.tvOS)] + [ConditionalFact(nameof(IsRemoteExecutorSupportedAndLongPathsAreNotBlockedAndUsingNewNormalization))] public void LongPathExtendedDirectory() { - DirectoryInfo testDir = Directory.CreateDirectory(IOServices.GetPath(IOInputs.ExtendedPrefix + TestDirectory, characterCount: 500)); - Delete(testDir.FullName); - Assert.False(testDir.Exists); + RemoteExecutor.Invoke(() => + { + Directory.SetCurrentDirectory(Path.GetTempPath()); + DirectoryInfo testDir = Directory.CreateDirectory(IOServices.GetPath(IOInputs.ExtendedPrefix + TestDirectory, characterCount: 500)); + Delete(testDir.FullName); + Assert.False(testDir.Exists); + }).Dispose(); } #endregion diff --git a/src/libraries/System.IO.FileSystem/tests/Directory/Exists.cs b/src/libraries/System.IO.FileSystem/tests/Directory/Exists.cs index 74b77fd2f3bcb..545c1678c35ef 100644 --- a/src/libraries/System.IO.FileSystem/tests/Directory/Exists.cs +++ b/src/libraries/System.IO.FileSystem/tests/Directory/Exists.cs @@ -393,8 +393,7 @@ public void ExtendedPathAlreadyExistsAsFile() } [Fact] - [PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser)] // Makes call to native code (libc) - [ActiveIssue("https://github.com/dotnet/runtime/issues/67853", TestPlatforms.iOS | TestPlatforms.tvOS)] + [PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser & ~TestPlatforms.iOS & ~TestPlatforms.tvOS)] // Makes call to native code (libc) public void FalseForNonRegularFile() { string fileName = GetTestFilePath(); diff --git a/src/libraries/System.IO.FileSystem/tests/DirectoryInfo/Exists.cs b/src/libraries/System.IO.FileSystem/tests/DirectoryInfo/Exists.cs index 05b41aa991adc..64500874532bf 100644 --- a/src/libraries/System.IO.FileSystem/tests/DirectoryInfo/Exists.cs +++ b/src/libraries/System.IO.FileSystem/tests/DirectoryInfo/Exists.cs @@ -108,8 +108,7 @@ public void FalseForFile() } [Fact] - [PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser)] // Uses P/Invokes - [ActiveIssue("https://github.com/dotnet/runtime/issues/67853", TestPlatforms.iOS | TestPlatforms.tvOS)] + [PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser & ~TestPlatforms.iOS & ~TestPlatforms.tvOS)] // Uses P/Invokes public void FalseForNonRegularFile() { string fileName = GetTestFilePath(); diff --git a/src/libraries/System.IO.FileSystem/tests/File/Exists.cs b/src/libraries/System.IO.FileSystem/tests/File/Exists.cs index 2716c13b290d4..12a6958dd9095 100644 --- a/src/libraries/System.IO.FileSystem/tests/File/Exists.cs +++ b/src/libraries/System.IO.FileSystem/tests/File/Exists.cs @@ -254,8 +254,7 @@ public void PathAlreadyExistsAsDirectory() } [Fact] - [PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser)] // Uses P/Invokes - [ActiveIssue("https://github.com/dotnet/runtime/issues/67853", TestPlatforms.iOS | TestPlatforms.tvOS)] + [PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser & ~TestPlatforms.iOS & ~TestPlatforms.tvOS)] // Uses P/Invokes public void FalseForNonRegularFile() { string fileName = GetTestFilePath(); diff --git a/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllBytes.cs b/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllBytes.cs index ce2699fcdf1f5..b6e6c1f147613 100644 --- a/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllBytes.cs +++ b/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllBytes.cs @@ -193,8 +193,7 @@ static async Task WaitConnectionAndWritePipeStreamAsync(NamedPipeServerStream na } [Fact] - [PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser)] - [ActiveIssue("https://github.com/dotnet/runtime/issues/67853", TestPlatforms.iOS | TestPlatforms.tvOS)] + [PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser & ~TestPlatforms.iOS & ~TestPlatforms.tvOS)] public async Task ReadAllBytes_NonSeekableFileStream_InUnix() { string fifoPath = GetTestFilePath(); diff --git a/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllBytesAsync.cs b/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllBytesAsync.cs index 47b8324f66c34..fca2d0d439b63 100644 --- a/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllBytesAsync.cs +++ b/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllBytesAsync.cs @@ -203,8 +203,7 @@ static async Task WaitConnectionAndWritePipeStreamAsync(NamedPipeServerStream na } [Fact] - [PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser)] - [ActiveIssue("https://github.com/dotnet/runtime/issues/67853", TestPlatforms.iOS | TestPlatforms.tvOS)] + [PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser & ~TestPlatforms.iOS & ~TestPlatforms.tvOS)] public async Task ReadAllBytesAsync_NonSeekableFileStream_InUnix() { string fifoPath = GetTestFilePath(); diff --git a/src/libraries/System.IO.FileSystem/tests/FileInfo/Exists.cs b/src/libraries/System.IO.FileSystem/tests/FileInfo/Exists.cs index 782f0cc344562..d61a72dc308dd 100644 --- a/src/libraries/System.IO.FileSystem/tests/FileInfo/Exists.cs +++ b/src/libraries/System.IO.FileSystem/tests/FileInfo/Exists.cs @@ -89,8 +89,7 @@ public void FalseForDirectory() } [Fact] - [PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser)] // Uses P/Invokes - [ActiveIssue("https://github.com/dotnet/runtime/issues/67853", TestPlatforms.iOS | TestPlatforms.tvOS)] + [PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser & ~TestPlatforms.iOS & ~TestPlatforms.tvOS)] // Uses P/Invokes public void TrueForNonRegularFile() { string fileName = GetTestFilePath(); diff --git a/src/libraries/System.IO.FileSystem/tests/Path/Exists_File.cs b/src/libraries/System.IO.FileSystem/tests/Path/Exists_File.cs index 80f1dc52c6fbb..6ef974a0678a4 100644 --- a/src/libraries/System.IO.FileSystem/tests/Path/Exists_File.cs +++ b/src/libraries/System.IO.FileSystem/tests/Path/Exists_File.cs @@ -21,8 +21,7 @@ public void PathAlreadyExistsAsDirectory() } [Fact] - [PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser)] // Uses P/Invokes - [ActiveIssue("https://github.com/dotnet/runtime/issues/67853", TestPlatforms.iOS | TestPlatforms.tvOS)] + [PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser & ~TestPlatforms.iOS & ~TestPlatforms.tvOS)] // Uses P/Invokes public void TrueForNonRegularFile() { string fileName = GetTestFilePath();