From: Kenneth Pouncey Date: Mon, 10 Aug 2020 20:35:25 +0000 (+0200) Subject: [browser][file system] Tests System.IO.FileSystem (#39768) X-Git-Tag: submit/tizen/20210909.063632~6105 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4dbe414c31cdd479289c496a8687251f2f2aa52a;p=platform%2Fupstream%2Fdotnet%2Fruntime.git [browser][file system] Tests System.IO.FileSystem (#39768) * [browser][file system] Tests System.IO.FileSystem * Remove FileSystem from test project exclusions. * [browser][filesystem] Comment on skipped tests due to IO.Pipes not supported * [browser][filesystem] Comment on skipped tests due to monitor not supported * Address review comments * Address review comments on how to handle monitor PNSE * Update src/libraries/System.IO.FileSystem/tests/File/GetSetTimes.cs Co-authored-by: Jan Kotas * Add ActiveIssue for browser platform ``` [ActiveIssue("https://github.com/dotnet/runtime/issues/39955", TestPlatforms.Browser)] public void NotFoundErrorIsExpected() ``` * Simplify test case with `PlatformDetection.IsSuperUser` as per review comment * Remove unused variable from tests * Browser platform volume does not limit each component of the path to a total of 255 characters. - Remove the test `DirectoryWithComponentLongerThanMaxComponentAsPath_ThrowsException` for Browser platform. - Add new test `DirectoryWithComponentLongerThanMaxComponentAsPath_BrowserDoesNotThrowsException` for Browser platform in case this check is added in the future. * Fix windows tests * Add ActiveIssue to test System.IO.Tests.DirectoryInfo_Name.CurrentDirectory - System.IO.Tests.DirectoryInfo_Name.CurrentDirectory does not pass because it is using Path.GetFileName on the current directory of "/". - See issue https://github.com/dotnet/runtime/issues/39998 for more information * Add active issue for tests that need to support file locking. * Add active issue for tests that need to support file locking. * Browser volume does not have a limit on segments * Remove browser platform test * Remove active issue for NotFoundErrorIsExpected * Remove platform specific from SkippingHiddenFiles * Fix enumeration test errors failing from `HiddenFilesAreReturned`. - WebAssembly (BROWSER) has dirent d_type but is not identifying correctly but by returning UNKNOWN the managed code properly stats the file to detect if entry is directory or not. * Fix enumeration test errors failing from `HiddenFilesAreReturned`. - WebAssembly (BROWSER) has dirent d_type but is not identifying correctly but by returning UNKNOWN the managed code properly stats the file to detect if entry is directory or not. * Fix build for TARGET_WASM not defined * Address review comment by add check for IsWindows to IsSuperUser. * Address review comment by add check for IsWindows to IsSuperUser. * Platform Specific test for hidden files no longer needed. * Platform Specific test fno longer needed. * Use active issue for rename issue * ActiveIssue no longer needed - PR https://github.com/dotnet/runtime/pull/40310 works around the issue for now while waiting for fix https://github.com/emscripten-core/emscripten/issues/11804 / https://github.com/emscripten-core/emscripten/pull/11812 * Use ActiveIssue for SettingUpdatesProperties * Use ActiveIssue for TimesIncludeMillisecondPart * Use ActiveIssue for ErrorHandlingTests failures * Use ActiveIssue for SetUptoNanoseconds * Use ActiveIssue for GetSetTimes test failures * Use ActiveIssue for tests failing with DirectoryNotFoundException * Use ActiveIssue for tests failing with UnauthorizedAccessException * Remove debugging statement from pal_io * Address type in CreateDirectory method name Co-authored-by: Jan Kotas Co-authored-by: Mitchell Hwang --- diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Unix.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Unix.cs index a042993..fb7db1e 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Unix.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Unix.cs @@ -47,9 +47,7 @@ namespace System 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() : diff --git a/src/libraries/Native/Unix/System.Native/pal_io.c b/src/libraries/Native/Unix/System.Native/pal_io.c index 85c5bf0..e0ed6ca 100644 --- a/src/libraries/Native/Unix/System.Native/pal_io.c +++ b/src/libraries/Native/Unix/System.Native/pal_io.c @@ -91,7 +91,10 @@ c_static_assert(PAL_S_IFSOCK == S_IFSOCK); // 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); @@ -345,10 +348,13 @@ static void ConvertDirent(const struct dirent* entry, DirectoryEntry* outputEntr // 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; diff --git a/src/libraries/System.IO.FileSystem/tests/Base/BaseGetSetTimes.cs b/src/libraries/System.IO.FileSystem/tests/Base/BaseGetSetTimes.cs index 58a515e..67d9655 100644 --- a/src/libraries/System.IO.FileSystem/tests/Base/BaseGetSetTimes.cs +++ b/src/libraries/System.IO.FileSystem/tests/Base/BaseGetSetTimes.cs @@ -41,6 +41,7 @@ namespace System.IO.Tests } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/40528", TestPlatforms.Browser)] public void SettingUpdatesProperties() { T item = GetExistingItem(); @@ -77,6 +78,7 @@ namespace System.IO.Tests } [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(); diff --git a/src/libraries/System.IO.FileSystem/tests/Directory/CreateDirectory.cs b/src/libraries/System.IO.FileSystem/tests/Directory/CreateDirectory.cs index 5b3b2dc..78c234d 100644 --- a/src/libraries/System.IO.FileSystem/tests/Directory/CreateDirectory.cs +++ b/src/libraries/System.IO.FileSystem/tests/Directory/CreateDirectory.cs @@ -210,17 +210,26 @@ namespace System.IO.Tests 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(() => 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)] diff --git a/src/libraries/System.IO.FileSystem/tests/Directory/Delete.cs b/src/libraries/System.IO.FileSystem/tests/Directory/Delete.cs index 386b847..00d5c46 100644 --- a/src/libraries/System.IO.FileSystem/tests/Directory/Delete.cs +++ b/src/libraries/System.IO.FileSystem/tests/Directory/Delete.cs @@ -244,6 +244,7 @@ namespace System.IO.Tests } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/40536", TestPlatforms.Browser)] public void RecursiveDeleteWithTrailingSlash() { DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath()); diff --git a/src/libraries/System.IO.FileSystem/tests/Directory/Exists.cs b/src/libraries/System.IO.FileSystem/tests/Directory/Exists.cs index 04b1411..44d07e2 100644 --- a/src/libraries/System.IO.FileSystem/tests/Directory/Exists.cs +++ b/src/libraries/System.IO.FileSystem/tests/Directory/Exists.cs @@ -390,7 +390,7 @@ namespace System.IO.Tests } [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(); diff --git a/src/libraries/System.IO.FileSystem/tests/Directory/Move.cs b/src/libraries/System.IO.FileSystem/tests/Directory/Move.cs index 3dcd99c..c5a145c 100644 --- a/src/libraries/System.IO.FileSystem/tests/Directory/Move.cs +++ b/src/libraries/System.IO.FileSystem/tests/Directory/Move.cs @@ -173,6 +173,7 @@ namespace System.IO.Tests } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/40536", TestPlatforms.Browser)] public void TrailingDirectorySeparators() { string testDirSource = Path.Combine(TestDirectory, GetTestFileName()); diff --git a/src/libraries/System.IO.FileSystem/tests/DirectoryInfo/Exists.cs b/src/libraries/System.IO.FileSystem/tests/DirectoryInfo/Exists.cs index 615bd4c..1be2524 100644 --- a/src/libraries/System.IO.FileSystem/tests/DirectoryInfo/Exists.cs +++ b/src/libraries/System.IO.FileSystem/tests/DirectoryInfo/Exists.cs @@ -110,7 +110,7 @@ namespace System.IO.Tests } [Fact] - [PlatformSpecific(TestPlatforms.AnyUnix)] // Uses P/Invokes + [PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser)] // Uses P/Invokes public void FalseForNonRegularFile() { string fileName = GetTestFilePath(); diff --git a/src/libraries/System.IO.FileSystem/tests/DirectoryInfo/MoveTo.cs b/src/libraries/System.IO.FileSystem/tests/DirectoryInfo/MoveTo.cs index e5e5478..fba22eb 100644 --- a/src/libraries/System.IO.FileSystem/tests/DirectoryInfo/MoveTo.cs +++ b/src/libraries/System.IO.FileSystem/tests/DirectoryInfo/MoveTo.cs @@ -24,6 +24,7 @@ namespace System.IO.Tests #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 diff --git a/src/libraries/System.IO.FileSystem/tests/DirectoryInfo/Name.cs b/src/libraries/System.IO.FileSystem/tests/DirectoryInfo/Name.cs index 52e08f5..3002175 100644 --- a/src/libraries/System.IO.FileSystem/tests/DirectoryInfo/Name.cs +++ b/src/libraries/System.IO.FileSystem/tests/DirectoryInfo/Name.cs @@ -8,6 +8,7 @@ namespace System.IO.Tests public class DirectoryInfo_Name : FileSystemTest { [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/39998", TestPlatforms.Browser)] public void CurrentDirectory() { var info = new DirectoryInfo("."); diff --git a/src/libraries/System.IO.FileSystem/tests/Enumeration/ErrorHandlingTests.cs b/src/libraries/System.IO.FileSystem/tests/Enumeration/ErrorHandlingTests.cs index 2c330cb..675b86c 100644 --- a/src/libraries/System.IO.FileSystem/tests/Enumeration/ErrorHandlingTests.cs +++ b/src/libraries/System.IO.FileSystem/tests/Enumeration/ErrorHandlingTests.cs @@ -102,6 +102,7 @@ namespace System.IO.Tests } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/40531", TestPlatforms.Browser)] public void VariableLengthFileNames_AllCreatableFilesAreEnumerable() { DirectoryInfo testDirectory = Directory.CreateDirectory(GetTestFilePath()); @@ -119,6 +120,7 @@ namespace System.IO.Tests } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/40531", TestPlatforms.Browser)] public void VariableLengthDirectoryNames_AllCreatableDirectoriesAreEnumerable() { DirectoryInfo testDirectory = Directory.CreateDirectory(GetTestFilePath()); diff --git a/src/libraries/System.IO.FileSystem/tests/File/Copy.cs b/src/libraries/System.IO.FileSystem/tests/File/Copy.cs index 9da51a7..e0b6957 100644 --- a/src/libraries/System.IO.FileSystem/tests/File/Copy.cs +++ b/src/libraries/System.IO.FileSystem/tests/File/Copy.cs @@ -108,6 +108,7 @@ namespace System.IO.Tests [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(); @@ -140,7 +141,10 @@ namespace System.IO.Tests } // 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) diff --git a/src/libraries/System.IO.FileSystem/tests/File/Create.cs b/src/libraries/System.IO.FileSystem/tests/File/Create.cs index 405d1f9..447bb32 100644 --- a/src/libraries/System.IO.FileSystem/tests/File/Create.cs +++ b/src/libraries/System.IO.FileSystem/tests/File/Create.cs @@ -111,6 +111,7 @@ namespace System.IO.Tests } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/40065", TestPlatforms.Browser)] public void FileInUse() { DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath()); @@ -144,7 +145,12 @@ namespace System.IO.Tests 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()); @@ -153,10 +159,6 @@ namespace System.IO.Tests Create(Path.Combine(testDir.FullName, new string('a', 300)))); } - #endregion - - #region PlatformSpecific - [Fact] [PlatformSpecific(TestPlatforms.AnyUnix)] public void LongDirectoryName() diff --git a/src/libraries/System.IO.FileSystem/tests/File/Exists.cs b/src/libraries/System.IO.FileSystem/tests/File/Exists.cs index 40d5ebc..225ed8e 100644 --- a/src/libraries/System.IO.FileSystem/tests/File/Exists.cs +++ b/src/libraries/System.IO.FileSystem/tests/File/Exists.cs @@ -247,7 +247,7 @@ namespace System.IO.Tests } [Fact] - [PlatformSpecific(TestPlatforms.AnyUnix)] // Uses P/Invokes + [PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser)] // Uses P/Invokes public void FalseForNonRegularFile() { string fileName = GetTestFilePath(); diff --git a/src/libraries/System.IO.FileSystem/tests/File/GetSetTimes.cs b/src/libraries/System.IO.FileSystem/tests/File/GetSetTimes.cs index a7840eb..07140ac 100644 --- a/src/libraries/System.IO.FileSystem/tests/File/GetSetTimes.cs +++ b/src/libraries/System.IO.FileSystem/tests/File/GetSetTimes.cs @@ -13,7 +13,7 @@ namespace System.IO.Tests { // 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() { @@ -135,6 +135,7 @@ namespace System.IO.Tests } [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(); diff --git a/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllBytes.cs b/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllBytes.cs index b6b4796..a5d9b5e 100644 --- a/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllBytes.cs +++ b/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllBytes.cs @@ -80,6 +80,7 @@ namespace System.IO.Tests } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/40065", TestPlatforms.Browser)] public void OpenFile_ThrowsIOException() { string path = GetTestFilePath(); @@ -105,7 +106,7 @@ namespace System.IO.Tests 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)); diff --git a/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllBytesAsync.cs b/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllBytesAsync.cs index 598fc01..3c46acf 100644 --- a/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllBytesAsync.cs +++ b/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllBytesAsync.cs @@ -94,6 +94,7 @@ namespace System.IO.Tests } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/40065", TestPlatforms.Browser)] public async Task OpenFile_ThrowsIOExceptionAsync() { string path = GetTestFilePath(); @@ -119,7 +120,7 @@ namespace System.IO.Tests 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)); diff --git a/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllLines.cs b/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllLines.cs index d5ef0ee..62ff393 100644 --- a/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllLines.cs +++ b/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllLines.cs @@ -78,6 +78,7 @@ namespace System.IO.Tests } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/40065", TestPlatforms.Browser)] public void OpenFile_ThrowsIOException() { string path = GetTestFilePath(); @@ -111,7 +112,7 @@ namespace System.IO.Tests 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)); @@ -266,6 +267,7 @@ namespace System.IO.Tests } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/40065", TestPlatforms.Browser)] public void OpenFile_ThrowsIOException() { string path = GetTestFilePath(); @@ -299,7 +301,7 @@ namespace System.IO.Tests 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)); diff --git a/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllLinesAsync.cs b/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllLinesAsync.cs index 87b3ad7..d717e28 100644 --- a/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllLinesAsync.cs +++ b/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllLinesAsync.cs @@ -76,6 +76,7 @@ namespace System.IO.Tests } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/40065", TestPlatforms.Browser)] public async Task OpenFile_ThrowsIOExceptionAsync() { string path = GetTestFilePath(); @@ -106,7 +107,7 @@ namespace System.IO.Tests 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)); diff --git a/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllText.cs b/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllText.cs index e511b69..9d330b2 100644 --- a/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllText.cs +++ b/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllText.cs @@ -85,6 +85,7 @@ namespace System.IO.Tests } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/40065", TestPlatforms.Browser)] public void OpenFile_ThrowsIOException() { string path = GetTestFilePath(); @@ -118,7 +119,7 @@ namespace System.IO.Tests 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)); diff --git a/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllTextAsync.cs b/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllTextAsync.cs index 3381398..ac77b25 100644 --- a/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllTextAsync.cs +++ b/src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllTextAsync.cs @@ -84,6 +84,7 @@ namespace System.IO.Tests } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/40065", TestPlatforms.Browser)] public async Task OpenFile_ThrowsIOExceptionAsync() { string path = GetTestFilePath(); @@ -114,7 +115,7 @@ namespace System.IO.Tests 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)); diff --git a/src/libraries/System.IO.FileSystem/tests/FileInfo/Exists.cs b/src/libraries/System.IO.FileSystem/tests/FileInfo/Exists.cs index 777a544..b0f1779 100644 --- a/src/libraries/System.IO.FileSystem/tests/FileInfo/Exists.cs +++ b/src/libraries/System.IO.FileSystem/tests/FileInfo/Exists.cs @@ -91,7 +91,7 @@ namespace System.IO.Tests } [Fact] - [PlatformSpecific(TestPlatforms.AnyUnix)] // Uses P/Invokes + [PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser)] // Uses P/Invokes public void TrueForNonRegularFile() { string fileName = GetTestFilePath(); diff --git a/src/libraries/System.IO.FileSystem/tests/FileInfo/GetSetTimes.cs b/src/libraries/System.IO.FileSystem/tests/FileInfo/GetSetTimes.cs index b27adf5..27b2e84 100644 --- a/src/libraries/System.IO.FileSystem/tests/FileInfo/GetSetTimes.cs +++ b/src/libraries/System.IO.FileSystem/tests/FileInfo/GetSetTimes.cs @@ -104,6 +104,7 @@ namespace System.IO.Tests } [ConditionalFact(nameof(isNotHFS))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/40530", TestPlatforms.Browser)] public void CopyToMillisecondPresent() { FileInfo input = GetNonZeroMilliseconds(); @@ -118,6 +119,7 @@ namespace System.IO.Tests } [ConditionalFact(nameof(isNotHFS))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/40530", TestPlatforms.Browser)] public void CopyToNanosecondsPresent() { FileInfo input = GetNonZeroNanoseconds(); @@ -160,6 +162,7 @@ namespace System.IO.Tests } [ConditionalFact(nameof(isNotHFS))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/40530", TestPlatforms.Browser)] public void MoveToMillisecondPresent() { FileInfo input = GetNonZeroMilliseconds(); diff --git a/src/libraries/System.IO.FileSystem/tests/FileStream/CanSeek.cs b/src/libraries/System.IO.FileSystem/tests/FileStream/CanSeek.cs index 0bf573c..bb1c783 100644 --- a/src/libraries/System.IO.FileSystem/tests/FileStream/CanSeek.cs +++ b/src/libraries/System.IO.FileSystem/tests/FileStream/CanSeek.cs @@ -43,6 +43,7 @@ namespace System.IO.Tests } [Fact] + [PlatformSpecific(~TestPlatforms.Browser)] // IO.Pipes not supported public void CanSeekReturnsFalseForPipe() { using (var pipeStream = new AnonymousPipeServerStream()) diff --git a/src/libraries/System.IO.FileSystem/tests/FileStream/CopyToAsync.cs b/src/libraries/System.IO.FileSystem/tests/FileStream/CopyToAsync.cs index da71457..6141240 100644 --- a/src/libraries/System.IO.FileSystem/tests/FileStream/CopyToAsync.cs +++ b/src/libraries/System.IO.FileSystem/tests/FileStream/CopyToAsync.cs @@ -177,6 +177,7 @@ namespace System.IO.Tests [Theory] [InlineData(10, 1024)] + [PlatformSpecific(~TestPlatforms.Browser)] // IO.Pipes not supported public async Task AnonymousPipeViaFileStream_AllDataCopied(int writeSize, int numWrites) { long totalLength = writeSize * numWrites; diff --git a/src/libraries/System.IO.FileSystem/tests/FileStream/Flush.cs b/src/libraries/System.IO.FileSystem/tests/FileStream/Flush.cs index ba96528..b955208 100644 --- a/src/libraries/System.IO.FileSystem/tests/FileStream/Flush.cs +++ b/src/libraries/System.IO.FileSystem/tests/FileStream/Flush.cs @@ -135,6 +135,7 @@ namespace System.IO.Tests [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)) diff --git a/src/libraries/System.IO.FileSystem/tests/FileStream/Pipes.cs b/src/libraries/System.IO.FileSystem/tests/FileStream/Pipes.cs index 7c6f08e..fd366dc 100644 --- a/src/libraries/System.IO.FileSystem/tests/FileStream/Pipes.cs +++ b/src/libraries/System.IO.FileSystem/tests/FileStream/Pipes.cs @@ -15,6 +15,7 @@ namespace System.IO.Tests [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)) @@ -70,6 +71,7 @@ namespace System.IO.Tests [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)) diff --git a/src/libraries/System.IO.FileSystem/tests/FileStream/ReadWriteSpan.cs b/src/libraries/System.IO.FileSystem/tests/FileStream/ReadWriteSpan.cs index f6b7416..4d66807 100644 --- a/src/libraries/System.IO.FileSystem/tests/FileStream/ReadWriteSpan.cs +++ b/src/libraries/System.IO.FileSystem/tests/FileStream/ReadWriteSpan.cs @@ -23,7 +23,7 @@ namespace System.IO.Tests Assert.Throws(() => fs.Write(new Span(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)) @@ -46,7 +46,7 @@ namespace System.IO.Tests } } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] // Browser PNSE: Cannot wait on monitors public void NonEmptyFile_Read_GetsExpectedData() { string fileName = GetTestFilePath(); @@ -111,7 +111,7 @@ namespace System.IO.Tests } } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] // Browser PNSE: Cannot wait on monitors public void NonEmptyWrite_WritesExpectedData() { using (var fs = CreateFileStream(GetTestFilePath(), FileMode.Create)) diff --git a/src/libraries/System.IO.FileSystem/tests/FileStream/WriteAsync.cs b/src/libraries/System.IO.FileSystem/tests/FileStream/WriteAsync.cs index 5f60690..7b236db 100644 --- a/src/libraries/System.IO.FileSystem/tests/FileStream/WriteAsync.cs +++ b/src/libraries/System.IO.FileSystem/tests/FileStream/WriteAsync.cs @@ -276,7 +276,7 @@ namespace System.IO.Tests } } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] // Browser PNSE: Cannot wait on monitors public Task ManyConcurrentWriteAsyncs() { // For inner loop, just test one case diff --git a/src/libraries/System.IO.FileSystem/tests/FileStream/ctor_str_fm_fa_fs.cs b/src/libraries/System.IO.FileSystem/tests/FileStream/ctor_str_fm_fa_fs.cs index b719725..805354e 100644 --- a/src/libraries/System.IO.FileSystem/tests/FileStream/ctor_str_fm_fa_fs.cs +++ b/src/libraries/System.IO.FileSystem/tests/FileStream/ctor_str_fm_fa_fs.cs @@ -121,6 +121,7 @@ namespace System.IO.Tests [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(); diff --git a/src/libraries/System.IO.FileSystem/tests/FileStream/ctor_str_fm_fa_fs.write.cs b/src/libraries/System.IO.FileSystem/tests/FileStream/ctor_str_fm_fa_fs.write.cs index 6f1abef..e0d6191 100644 --- a/src/libraries/System.IO.FileSystem/tests/FileStream/ctor_str_fm_fa_fs.write.cs +++ b/src/libraries/System.IO.FileSystem/tests/FileStream/ctor_str_fm_fa_fs.write.cs @@ -40,6 +40,7 @@ namespace System.IO.Tests } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/40065", TestPlatforms.Browser)] public void FileShareWithoutWriteThrows() { string fileName = GetTestFilePath(); diff --git a/src/libraries/System.IO.FileSystem/tests/FileSystemTest.Browser.cs b/src/libraries/System.IO.FileSystem/tests/FileSystemTest.Browser.cs new file mode 100644 index 0000000..afaa1cc --- /dev/null +++ b/src/libraries/System.IO.FileSystem/tests/FileSystemTest.Browser.cs @@ -0,0 +1,16 @@ +// 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(); + } + } +} diff --git a/src/libraries/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj b/src/libraries/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj index e0769d4..7115d41 100644 --- a/src/libraries/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj +++ b/src/libraries/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj @@ -46,12 +46,15 @@ - + + + + diff --git a/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateFromFile.Tests.cs b/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateFromFile.Tests.cs index f23da73..4a08c3f 100644 --- a/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateFromFile.Tests.cs +++ b/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateFromFile.Tests.cs @@ -696,13 +696,13 @@ namespace System.IO.MemoryMappedFiles.Tests 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); } /// diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index 9ba9856..28cee27 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -25,7 +25,6 @@ -