public static bool IsNotFedoraOrRedHatFamily => !IsFedora && !IsRedHatFamily;
public static bool IsNotDebian10 => !IsDebian10;
- public static bool IsSuperUser => IsBrowser ? false : (!IsWindows ?
- libc.geteuid() == 0 :
- throw new PlatformNotSupportedException());
+ public static bool IsSuperUser => IsBrowser || IsWindows ? false : libc.geteuid() == 0;
public static Version OpenSslVersion => !IsOSXLike && !IsWindows ?
GetOpenSslVersion() :
// Validate that our enum for inode types is the same as what is
// declared by the dirent.h header on the local system.
// (AIX doesn't have dirent d_type, so none of this there)
-#if defined(DT_UNKNOWN)
+// WebAssembly (BROWSER) has dirent d_type but is not correct
+// by returning UNKNOWN the managed code properly stats the file
+// to detect if entry is directory or not.
+#if defined(DT_UNKNOWN) || defined(TARGET_WASM)
c_static_assert((int)PAL_DT_UNKNOWN == (int)DT_UNKNOWN);
c_static_assert((int)PAL_DT_FIFO == (int)DT_FIFO);
c_static_assert((int)PAL_DT_CHR == (int)DT_CHR);
// the start of the unmanaged string. Give the caller back a pointer to the
// location of the start of the string that exists in their own byte buffer.
outputEntry->Name = entry->d_name;
-#if !defined(DT_UNKNOWN)
+#if !defined(DT_UNKNOWN) || defined(TARGET_WASM)
// AIX has no d_type, and since we can't get the directory that goes with
// the filename from ReadDir, we can't stat the file. Return unknown and
// hope that managed code can properly stat the file.
+ // WebAssembly (BROWSER) has dirent d_type but is not correct
+ // by returning UNKNOWN the managed code properly stats the file
+ // to detect if entry is directory or not.
outputEntry->InodeType = PAL_DT_UNKNOWN;
#else
outputEntry->InodeType = (int32_t)entry->d_type;
}
[Fact]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/40528", TestPlatforms.Browser)]
public void SettingUpdatesProperties()
{
T item = GetExistingItem();
}
[ConditionalFact(nameof(isNotHFS))] // OSX HFS driver format does not support millisec granularity
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/40530", TestPlatforms.Browser)]
public void TimesIncludeMillisecondPart()
{
T item = GetExistingItem();
Assert.Equal(path, result.FullName);
Assert.True(Directory.Exists(result.FullName));
}
+ #endregion
+
+ #region PlatformSpecific
[Theory,
MemberData(nameof(PathsWithComponentLongerThanMaxComponent))]
+ [PlatformSpecific(~TestPlatforms.Browser)] // Browser does not have a limit on the maximum component length
public void DirectoryWithComponentLongerThanMaxComponentAsPath_ThrowsException(string path)
{
AssertExtensions.ThrowsAny<IOException, DirectoryNotFoundException, PathTooLongException>(() => Create(path));
}
- #endregion
-
- #region PlatformSpecific
+ [Theory,
+ MemberData(nameof(PathsWithComponentLongerThanMaxComponent))]
+ [PlatformSpecific(TestPlatforms.Browser)] // Browser specific test in case the check changes in the future
+ public void DirectoryWithComponentLongerThanMaxComponentAsPath_BrowserDoesNotThrowException(string path)
+ {
+ DirectoryInfo result = Create(path);
+ Assert.True(Directory.Exists(path));
+ }
[Theory, MemberData(nameof(PathsWithInvalidColons))]
[PlatformSpecific(TestPlatforms.Windows)]
}
[Fact]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/40536", TestPlatforms.Browser)]
public void RecursiveDeleteWithTrailingSlash()
{
DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath());
}
[Fact]
- [PlatformSpecific(TestPlatforms.AnyUnix)] // Makes call to native code (libc)
+ [PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser)] // Makes call to native code (libc)
public void FalseForNonRegularFile()
{
string fileName = GetTestFilePath();
}
[Fact]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/40536", TestPlatforms.Browser)]
public void TrailingDirectorySeparators()
{
string testDirSource = Path.Combine(TestDirectory, GetTestFileName());
}
[Fact]
- [PlatformSpecific(TestPlatforms.AnyUnix)] // Uses P/Invokes
+ [PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser)] // Uses P/Invokes
public void FalseForNonRegularFile()
{
string fileName = GetTestFilePath();
#region UniversalTests
[Fact]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/40536", TestPlatforms.Browser)]
public void DirectoryPathUpdatesOnMove()
{
//NOTE: MoveTo adds a trailing separator character to the FullName of a DirectoryInfo
public class DirectoryInfo_Name : FileSystemTest
{
[Fact]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/39998", TestPlatforms.Browser)]
public void CurrentDirectory()
{
var info = new DirectoryInfo(".");
}
[Fact]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/40531", TestPlatforms.Browser)]
public void VariableLengthFileNames_AllCreatableFilesAreEnumerable()
{
DirectoryInfo testDirectory = Directory.CreateDirectory(GetTestFilePath());
}
[Fact]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/40531", TestPlatforms.Browser)]
public void VariableLengthDirectoryNames_AllCreatableDirectoriesAreEnumerable()
{
DirectoryInfo testDirectory = Directory.CreateDirectory(GetTestFilePath());
[Theory]
[MemberData(nameof(CopyFileWithData_MemberData))]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/40543", TestPlatforms.Browser)]
public void CopyFileWithData(char[] data, bool readOnly)
{
string testFileSource = GetTestFilePath();
}
// Ensure last write/access time on the new file is appropriate
- Assert.InRange(File.GetLastWriteTimeUtc(testFileDest), lastWriteTime.AddSeconds(-1), lastWriteTime.AddSeconds(1));
+ if (PlatformDetection.IsNotBrowser) // There is only one write time on browser vfs
+ {
+ Assert.InRange(File.GetLastWriteTimeUtc(testFileDest), lastWriteTime.AddSeconds(-1), lastWriteTime.AddSeconds(1));
+ }
Assert.Equal(readOnly, (File.GetAttributes(testFileDest) & FileAttributes.ReadOnly) != 0);
if (readOnly)
}
[Fact]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/40065", TestPlatforms.Browser)]
public void FileInUse()
{
DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath());
Assert.True(File.Exists(testFile));
}
+ #endregion
+
+ #region PlatformSpecific
+
[Fact]
+ [PlatformSpecific(~TestPlatforms.Browser)] // Browser platform volume does not limit segments
public void LongPathSegment()
{
DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath());
Create(Path.Combine(testDir.FullName, new string('a', 300))));
}
- #endregion
-
- #region PlatformSpecific
-
[Fact]
[PlatformSpecific(TestPlatforms.AnyUnix)]
public void LongDirectoryName()
}
[Fact]
- [PlatformSpecific(TestPlatforms.AnyUnix)] // Uses P/Invokes
+ [PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser)] // Uses P/Invokes
public void FalseForNonRegularFile()
{
string fileName = GetTestFilePath();
{
// OSX has the limitation of setting upto 2262-04-11T23:47:16 (long.Max) date.
// 32bit Unix has time_t up to ~ 2038.
- private static bool SupportsLongMaxDateTime => PlatformDetection.IsWindows || (RuntimeInformation.ProcessArchitecture != Architecture.Arm && RuntimeInformation.ProcessArchitecture != Architecture.X86 && !PlatformDetection.IsOSXLike);
+ private static bool SupportsLongMaxDateTime => PlatformDetection.IsWindows || (!PlatformDetection.Is32BitProcess && !PlatformDetection.IsOSXLike);
protected override string GetExistingItem()
{
}
[ConditionalFact(nameof(isNotHFS))] // OSX HFS driver format does not support nanosecond granularity.
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/40532", TestPlatforms.Browser)]
public void SetUptoNanoseconds()
{
string file = GetTestFilePath();
}
[Fact]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/40065", TestPlatforms.Browser)]
public void OpenFile_ThrowsIOException()
{
string path = GetTestFilePath();
try
{
// Operation succeeds when being run by the Unix superuser
- if (!OperatingSystem.IsWindows() && geteuid() == 0)
+ if (PlatformDetection.IsSuperUser)
{
File.WriteAllBytes(path, Encoding.UTF8.GetBytes("text"));
Assert.Equal(Encoding.UTF8.GetBytes("text"), File.ReadAllBytes(path));
}
[Fact]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/40065", TestPlatforms.Browser)]
public async Task OpenFile_ThrowsIOExceptionAsync()
{
string path = GetTestFilePath();
try
{
// Operation succeeds when being run by the Unix superuser
- if (!OperatingSystem.IsWindows() && geteuid() == 0)
+ if (PlatformDetection.IsSuperUser)
{
await File.WriteAllBytesAsync(path, Encoding.UTF8.GetBytes("text"));
Assert.Equal(Encoding.UTF8.GetBytes("text"), await File.ReadAllBytesAsync(path));
}
[Fact]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/40065", TestPlatforms.Browser)]
public void OpenFile_ThrowsIOException()
{
string path = GetTestFilePath();
try
{
// Operation succeeds when being run by the Unix superuser
- if (!OperatingSystem.IsWindows() && geteuid() == 0)
+ if (PlatformDetection.IsSuperUser)
{
Write(path, new string[] { "text" });
Assert.Equal(new string[] { "text" }, Read(path));
}
[Fact]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/40065", TestPlatforms.Browser)]
public void OpenFile_ThrowsIOException()
{
string path = GetTestFilePath();
try
{
// Operation succeeds when being run by the Unix superuser
- if (!OperatingSystem.IsWindows() && geteuid() == 0)
+ if (PlatformDetection.IsSuperUser)
{
Write(path, new string[] { "text" });
Assert.Equal(new string[] { "text" }, Read(path));
}
[Fact]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/40065", TestPlatforms.Browser)]
public async Task OpenFile_ThrowsIOExceptionAsync()
{
string path = GetTestFilePath();
try
{
// Operation succeeds when being run by the Unix superuser
- if (!OperatingSystem.IsWindows() && geteuid() == 0)
+ if (PlatformDetection.IsSuperUser)
{
await WriteAsync(path, new string[] { "text" });
Assert.Equal(new string[] { "text" }, await ReadAsync(path));
}
[Fact]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/40065", TestPlatforms.Browser)]
public void OpenFile_ThrowsIOException()
{
string path = GetTestFilePath();
try
{
// Operation succeeds when being run by the Unix superuser
- if (!OperatingSystem.IsWindows() && geteuid() == 0)
+ if (PlatformDetection.IsSuperUser)
{
Write(path, "text");
Assert.Equal("text", Read(path));
}
[Fact]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/40065", TestPlatforms.Browser)]
public async Task OpenFile_ThrowsIOExceptionAsync()
{
string path = GetTestFilePath();
try
{
// Operation succeeds when being run by the Unix superuser
- if (!OperatingSystem.IsWindows() && geteuid() == 0)
+ if (PlatformDetection.IsSuperUser)
{
await WriteAsync(path, "text");
Assert.Equal("text", await ReadAsync(path));
}
[Fact]
- [PlatformSpecific(TestPlatforms.AnyUnix)] // Uses P/Invokes
+ [PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser)] // Uses P/Invokes
public void TrueForNonRegularFile()
{
string fileName = GetTestFilePath();
}
[ConditionalFact(nameof(isNotHFS))]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/40530", TestPlatforms.Browser)]
public void CopyToMillisecondPresent()
{
FileInfo input = GetNonZeroMilliseconds();
}
[ConditionalFact(nameof(isNotHFS))]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/40530", TestPlatforms.Browser)]
public void CopyToNanosecondsPresent()
{
FileInfo input = GetNonZeroNanoseconds();
}
[ConditionalFact(nameof(isNotHFS))]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/40530", TestPlatforms.Browser)]
public void MoveToMillisecondPresent()
{
FileInfo input = GetNonZeroMilliseconds();
}
[Fact]
+ [PlatformSpecific(~TestPlatforms.Browser)] // IO.Pipes not supported
public void CanSeekReturnsFalseForPipe()
{
using (var pipeStream = new AnonymousPipeServerStream())
[Theory]
[InlineData(10, 1024)]
+ [PlatformSpecific(~TestPlatforms.Browser)] // IO.Pipes not supported
public async Task AnonymousPipeViaFileStream_AllDataCopied(int writeSize, int numWrites)
{
long totalLength = writeSize * numWrites;
[InlineData(null)]
[InlineData(false)]
[InlineData(true)]
+ [PlatformSpecific(~TestPlatforms.Browser)] // IO.Pipes not supported
public void FlushCanBeUsedOnPipes_Success(bool? flushToDisk)
{
using (var pipeStream = new AnonymousPipeServerStream(PipeDirection.In))
[Theory]
[InlineData(true)]
[InlineData(false)]
+ [PlatformSpecific(~TestPlatforms.Browser)] // IO.Pipes not supported
public async Task AnonymousPipeWriteViaFileStream(bool asyncWrites)
{
using (var server = new AnonymousPipeServerStream(PipeDirection.In))
[Theory]
[InlineData(true)]
[InlineData(false)]
+ [PlatformSpecific(~TestPlatforms.Browser)] // IO.Pipes not supported
public async Task AnonymousPipeReadViaFileStream(bool asyncReads)
{
using (var server = new AnonymousPipeServerStream(PipeDirection.Out))
Assert.Throws<ObjectDisposedException>(() => fs.Write(new Span<byte>(new byte[1])));
}
- [Fact]
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] // Browser PNSE: Cannot wait on monitors
public void EmptyFile_Read_Succeeds()
{
using (var fs = CreateFileStream(GetTestFilePath(), FileMode.Create))
}
}
- [Fact]
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] // Browser PNSE: Cannot wait on monitors
public void NonEmptyFile_Read_GetsExpectedData()
{
string fileName = GetTestFilePath();
}
}
- [Fact]
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] // Browser PNSE: Cannot wait on monitors
public void NonEmptyWrite_WritesExpectedData()
{
using (var fs = CreateFileStream(GetTestFilePath(), FileMode.Create))
}
}
- [Fact]
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] // Browser PNSE: Cannot wait on monitors
public Task ManyConcurrentWriteAsyncs()
{
// For inner loop, just test one case
[Theory]
[InlineData(FileMode.Create)]
[InlineData(FileMode.Truncate)]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/40065", TestPlatforms.Browser)]
public void NoTruncateOnFileShareViolation(FileMode fileMode)
{
string fileName = GetTestFilePath();
}
[Fact]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/40065", TestPlatforms.Browser)]
public void FileShareWithoutWriteThrows()
{
string fileName = GetTestFilePath();
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Runtime.InteropServices;
+using Xunit;
+
+namespace System.IO.Tests
+{
+ public abstract partial class FileSystemTest
+ {
+ protected static int mkfifo(string path, int mode)
+ {
+ throw new PlatformNotSupportedException();
+ }
+ }
+}
<Compile Include="Enumeration\ExampleTests.cs" />
<Compile Include="Enumeration\RemovedDirectoryTests.cs" />
</ItemGroup>
- <ItemGroup Condition="'$(TargetsUnix)' == 'true' or '$(TargetsBrowser)' == 'true'">
+ <ItemGroup Condition="'$(TargetsUnix)' == 'true'">
<Compile Include="FileSystemTest.Unix.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsWindows)' == 'true'">
<Compile Include="FileSystemTest.Windows.cs" />
</ItemGroup>
+ <ItemGroup Condition="'$(TargetsBrowser)' == 'true'">
+ <Compile Include="FileSystemTest.Browser.cs" />
+ </ItemGroup>
<ItemGroup>
<!-- Rewritten -->
<Compile Include="DirectoryInfo\GetSetAttributes.cs" />
public void WriteToReadOnlyFile_ReadWrite(MemoryMappedFileAccess access)
{
WriteToReadOnlyFile(access, access == MemoryMappedFileAccess.Read ||
- (!OperatingSystem.IsWindows() && PlatformDetection.IsSuperUser));
+ PlatformDetection.IsSuperUser);
}
[Fact]
public void WriteToReadOnlyFile_CopyOnWrite()
{
- WriteToReadOnlyFile(MemoryMappedFileAccess.CopyOnWrite, (!OperatingSystem.IsWindows() && PlatformDetection.IsSuperUser));
+ WriteToReadOnlyFile(MemoryMappedFileAccess.CopyOnWrite, PlatformDetection.IsSuperUser);
}
/// <summary>
<!-- Mono-Browser ignores runtimeconfig.template.json (e.g. for this it has "System.Globalization.EnforceJapaneseEraYearRanges": true) -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Globalization.Calendars\tests\CalendarTestWithConfigSwitch\System.Globalization.CalendarsWithConfigSwitch.Tests.csproj" />
- <ProjectExclusions Include="$(MSBuildThisFileDirectory)System.IO.FileSystem\tests\System.IO.FileSystem.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Linq.Parallel\tests\System.Linq.Parallel.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Net.Http\tests\FunctionalTests\System.Net.Http.Functional.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Net.WebSockets.Client\tests\System.Net.WebSockets.Client.Tests.csproj" />