Skip to content

Commit

Permalink
Resolve tvOS/iOS FileSystem test failures (#74927)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
directhex authored Oct 26, 2022
1 parent 3e40074 commit 193ee83
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
33 changes: 22 additions & 11 deletions src/libraries/System.IO.FileSystem/tests/Directory/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Text;
using Xunit;
using Microsoft.DotNet.RemoteExecutor;
using Microsoft.DotNet.XUnitExtensions;

namespace System.IO.Tests
Expand All @@ -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)
Expand Down Expand Up @@ -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<IOException>(() => 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<IOException>(() => 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
Expand Down
3 changes: 1 addition & 2 deletions src/libraries/System.IO.FileSystem/tests/Directory/Exists.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions src/libraries/System.IO.FileSystem/tests/File/Exists.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions src/libraries/System.IO.FileSystem/tests/FileInfo/Exists.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions src/libraries/System.IO.FileSystem/tests/Path/Exists_File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 193ee83

Please sign in to comment.