diff --git a/src/libraries/System.IO.FileSystem/tests/Directory/EnumerableAPIs.cs b/src/libraries/System.IO.FileSystem/tests/Directory/EnumerableAPIs.cs index 6adc3c578bf..72ccb773c9d 100644 --- a/src/libraries/System.IO.FileSystem/tests/Directory/EnumerableAPIs.cs +++ b/src/libraries/System.IO.FileSystem/tests/Directory/EnumerableAPIs.cs @@ -2,6 +2,7 @@ // 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.Collections.Generic; using System.Linq; using Xunit; @@ -135,6 +136,24 @@ namespace System.IO.Tests } } + public class Directory_EnumFSE_str_str_so_alldirs : Directory_GetFileSystemEntries_str_str_so_alldirs + { + public override string[] GetEntries(string dirName) + { + return Directory.EnumerateFileSystemEntries(dirName, "*", SearchOption.AllDirectories).ToArray(); + } + + public override string[] GetEntries(string dirName, string searchPattern) + { + return Directory.EnumerateFileSystemEntries(dirName, searchPattern, SearchOption.AllDirectories).ToArray(); + } + + public override string[] GetEntries(string dirName, string searchPattern, SearchOption option) + { + return Directory.EnumerateFileSystemEntries(dirName, searchPattern, option).ToArray(); + } + } + #endregion #region EnumerateDirectories diff --git a/src/libraries/System.IO.FileSystem/tests/Directory/GetCurrentDirectory.cs b/src/libraries/System.IO.FileSystem/tests/Directory/GetCurrentDirectory.cs deleted file mode 100644 index 85e0540b5e2..00000000000 --- a/src/libraries/System.IO.FileSystem/tests/Directory/GetCurrentDirectory.cs +++ /dev/null @@ -1,122 +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 System.Collections; -using System.Globalization; -using System.Runtime.CompilerServices; -using Xunit; - -public class Directory_GetCurrentDirectory -{ - public static String s_strDtTmVer = "2000/07/07 19:00"; - public static String s_strClassMethod = "Directory.GetCurrentDirectory()"; - public static String s_strTFName = "GetCurrentDirectory.cs"; - public static String s_strTFPath = Directory.GetCurrentDirectory(); - - [Fact] - public static void runTest() - { - int iCountErrors = 0; - int iCountTestcases = 0; - String strLoc = "Loc_000oo"; - String strValue = String.Empty; - - - try - { - ///////////////////////// START TESTS //////////////////////////// - /////////////////////////////////////////////////////////////////// - - DirectoryInfo currentdir = new DirectoryInfo(Directory.GetCurrentDirectory()); - - // [] ArgumentNullException for null argument - - strLoc = "Loc_23849"; - - iCountTestcases++; - try - { - Directory.SetCurrentDirectory(null); - iCountErrors++; - printerr("Error_388rf! Expected exception not thrown, dir==" + Directory.GetCurrentDirectory()); - } - catch (ArgumentNullException) - { - } - catch (Exception exc) - { - iCountErrors++; - printerr("Error_28t7b! Incorrect exception thrown, exc==" + exc.ToString()); - } - - - // [] Vanilla case - /* Scenario disabled when porting because it modifies global process state and can not be run in parallel with other tests - DirectoryInfo dir = null; - strLoc = "Loc_2g77b"; - - dir = new DirectoryInfo(".."); - Directory.SetCurrentDirectory(dir.FullName); - - iCountTestcases++; - if (!Directory.GetCurrentDirectory().Equals(dir.FullName)) - { - Console.WriteLine(Directory.GetCurrentDirectory()); - iCountErrors++; - printerr("Error_38g8b! Directory Not set correctly"); - } - */ - - // [] Another vanilla case - /* Scenario disabled when porting because it modifies global process state and can not be run in parallel with other tests - strLoc = "Loc_9t8gt"; - - dir = new DirectoryInfo("C:\\"); - Directory.SetCurrentDirectory(dir.FullName); - iCountTestcases++; - if (!Directory.GetCurrentDirectory().Equals(dir.FullName)) - { - iCountErrors++; - printerr("Error_238g7! Directory not set correctly, dir==" + Directory.GetCurrentDirectory()); - } - */ - - // [] Set back to original - /* Scenario disabled when porting because it modifies global process state and can not be run in parallel with other tests - strLoc = "Loc_87ygv"; - - Directory.SetCurrentDirectory(currentdir.FullName); - iCountTestcases++; - if (!Directory.GetCurrentDirectory().Equals(currentdir.FullName)) - { - iCountErrors++; - printerr("Error_2g7b7! Directory not set correctly, dir==" + Directory.GetCurrentDirectory()); - } - */ - - /////////////////////////////////////////////////////////////////// - /////////////////////////// END TESTS ///////////////////////////// - } - catch (Exception exc_general) - { - ++iCountErrors; - printerr("Error Err_8888yyy! strLoc==" + strLoc + ", exc_general==" + exc_general.ToString()); - } - //// Finish Diagnostics - - if (iCountErrors != 0) - { - Console.WriteLine("FAiL! " + s_strTFName + " ,iCountErrors==" + iCountErrors.ToString()); - } - - Assert.Equal(0, iCountErrors); - } - - public static void printerr(String err, [CallerMemberName] string memberName = "", [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0) - { - Console.WriteLine("ERROR: ({0}, {1}, {2}) {3}", memberName, filePath, lineNumber, err); - } -} diff --git a/src/libraries/System.IO.FileSystem/tests/Directory/GetFileSystemEntries_str.cs b/src/libraries/System.IO.FileSystem/tests/Directory/GetFileSystemEntries_str.cs index c60fe360af3..7a1ac7158f8 100644 --- a/src/libraries/System.IO.FileSystem/tests/Directory/GetFileSystemEntries_str.cs +++ b/src/libraries/System.IO.FileSystem/tests/Directory/GetFileSystemEntries_str.cs @@ -2,6 +2,7 @@ // 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.Diagnostics; using Xunit; namespace System.IO.Tests @@ -155,12 +156,6 @@ namespace System.IO.Tests } } - [Fact] - public void CurrentDirectory() - { - Assert.NotNull(GetEntries(Directory.GetCurrentDirectory())); - } - #endregion #region PlatformSpecific @@ -228,4 +223,52 @@ namespace System.IO.Tests #endregion } + + public sealed class Directory_GetEntries_CurrentDirectory : RemoteExecutorTestBase + { + [Fact] + public void CurrentDirectory() + { + string testDir = GetTestFilePath(); + Directory.CreateDirectory(testDir); + File.WriteAllText(Path.Combine(testDir, GetTestFileName()), "cat"); + Directory.CreateDirectory(Path.Combine(testDir, GetTestFileName())); + RemoteInvoke((testDirectory) => + { + Directory.SetCurrentDirectory(testDirectory); + + Assert.NotEmpty(Directory.GetFileSystemEntries(Directory.GetCurrentDirectory())); + Assert.NotEmpty(Directory.GetFileSystemEntries(Directory.GetCurrentDirectory(), "*")); + Assert.NotEmpty(Directory.GetFileSystemEntries(Directory.GetCurrentDirectory(), "*", SearchOption.AllDirectories)); + Assert.NotEmpty(Directory.GetFileSystemEntries(Directory.GetCurrentDirectory(), "*", SearchOption.TopDirectoryOnly)); + + Assert.NotEmpty(Directory.GetDirectories(Directory.GetCurrentDirectory())); + Assert.NotEmpty(Directory.GetDirectories(Directory.GetCurrentDirectory(), "*")); + Assert.NotEmpty(Directory.GetDirectories(Directory.GetCurrentDirectory(), "*", SearchOption.AllDirectories)); + Assert.NotEmpty(Directory.GetDirectories(Directory.GetCurrentDirectory(), "*", SearchOption.TopDirectoryOnly)); + + Assert.NotEmpty(Directory.GetFiles(Directory.GetCurrentDirectory())); + Assert.NotEmpty(Directory.GetFiles(Directory.GetCurrentDirectory(), "*")); + Assert.NotEmpty(Directory.GetFiles(Directory.GetCurrentDirectory(), "*", SearchOption.AllDirectories)); + Assert.NotEmpty(Directory.GetFiles(Directory.GetCurrentDirectory(), "*", SearchOption.TopDirectoryOnly)); + + Assert.NotEmpty(Directory.EnumerateFileSystemEntries(Directory.GetCurrentDirectory())); + Assert.NotEmpty(Directory.EnumerateFileSystemEntries(Directory.GetCurrentDirectory(), "*")); + Assert.NotEmpty(Directory.EnumerateFileSystemEntries(Directory.GetCurrentDirectory(), "*", SearchOption.AllDirectories)); + Assert.NotEmpty(Directory.EnumerateFileSystemEntries(Directory.GetCurrentDirectory(), "*", SearchOption.TopDirectoryOnly)); + + Assert.NotEmpty(Directory.EnumerateDirectories(Directory.GetCurrentDirectory())); + Assert.NotEmpty(Directory.EnumerateDirectories(Directory.GetCurrentDirectory(), "*")); + Assert.NotEmpty(Directory.EnumerateDirectories(Directory.GetCurrentDirectory(), "*", SearchOption.AllDirectories)); + Assert.NotEmpty(Directory.EnumerateDirectories(Directory.GetCurrentDirectory(), "*", SearchOption.TopDirectoryOnly)); + + Assert.NotEmpty(Directory.EnumerateFiles(Directory.GetCurrentDirectory())); + Assert.NotEmpty(Directory.EnumerateFiles(Directory.GetCurrentDirectory(), "*")); + Assert.NotEmpty(Directory.EnumerateFiles(Directory.GetCurrentDirectory(), "*", SearchOption.AllDirectories)); + Assert.NotEmpty(Directory.EnumerateFiles(Directory.GetCurrentDirectory(), "*", SearchOption.TopDirectoryOnly)); + + return SuccessExitCode; + }, testDir).Dispose(); + } + } } 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 e9177c53967..e6f5eea83bd 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 @@ -122,7 +122,6 @@ -