diff options
author | Santiago Fernandez Madero <safern@microsoft.com> | 2017-04-28 02:17:34 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-28 02:17:34 +0300 |
commit | 134cc0df801938a4ba3e58f902a58cec09b744ef (patch) | |
tree | 5ad23fb80a117f9635d8ce37ad269e347418afb4 /src | |
parent | c8413f506307108a4688486525b1f927d76cc9cb (diff) |
Fix some System.IO.PathTests on Desktop to support legacy path behavior (#19012)
* Fix System.IO.PathTests
Diffstat (limited to 'src')
-rw-r--r-- | src/Common/tests/System/AssertExtensions.cs | 25 | ||||
-rw-r--r-- | src/Common/tests/System/IO/PathFeatures.cs (renamed from src/System.IO.FileSystem/tests/PathFeatures.cs) | 0 | ||||
-rw-r--r-- | src/System.IO.FileSystem/tests/Performance/System.IO.FileSystem.Performance.Tests.csproj | 4 | ||||
-rw-r--r-- | src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj | 4 | ||||
-rw-r--r-- | src/System.Runtime.Extensions/tests/System.Runtime.Extensions.Tests.csproj | 3 | ||||
-rw-r--r-- | src/System.Runtime.Extensions/tests/System/IO/PathTests.cs | 73 |
6 files changed, 90 insertions, 19 deletions
diff --git a/src/Common/tests/System/AssertExtensions.cs b/src/Common/tests/System/AssertExtensions.cs index ce84bc17b4..7eb11653de 100644 --- a/src/Common/tests/System/AssertExtensions.cs +++ b/src/Common/tests/System/AssertExtensions.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.Runtime.InteropServices; using Xunit; +using Xunit.Sdk; namespace System { @@ -73,5 +74,29 @@ namespace System Throws<TNetCoreExceptionType>(netCoreParamName, action); } } + + public static void ThrowsAny(Type firstExceptionType, Type secondExceptionType, Action action) + { + try + { + action(); + } + catch (Exception e) + { + if (e.GetType().Equals(firstExceptionType) || e.GetType().Equals(secondExceptionType)) + { + return; + } + throw new XunitException($"Expected: ({firstExceptionType}) or ({secondExceptionType}) -> Actual: ({e.GetType()})"); + } + throw new XunitException("AssertExtensions.ThrowsAny<firstExceptionType, secondExceptionType> didn't throw any exception"); + } + + public static void ThrowsAny<TFirstExceptionType, TSecondExceptionType>(Action action) + where TFirstExceptionType : Exception + where TSecondExceptionType : Exception + { + ThrowsAny(typeof(TFirstExceptionType), typeof(TSecondExceptionType), action); + } } } diff --git a/src/System.IO.FileSystem/tests/PathFeatures.cs b/src/Common/tests/System/IO/PathFeatures.cs index 7062d9ee1a..7062d9ee1a 100644 --- a/src/System.IO.FileSystem/tests/PathFeatures.cs +++ b/src/Common/tests/System/IO/PathFeatures.cs diff --git a/src/System.IO.FileSystem/tests/Performance/System.IO.FileSystem.Performance.Tests.csproj b/src/System.IO.FileSystem/tests/Performance/System.IO.FileSystem.Performance.Tests.csproj index 7df96f1f2d..2d9fd50a0f 100644 --- a/src/System.IO.FileSystem/tests/Performance/System.IO.FileSystem.Performance.Tests.csproj +++ b/src/System.IO.FileSystem/tests/Performance/System.IO.FileSystem.Performance.Tests.csproj @@ -16,7 +16,6 @@ <Compile Include="..\PortedCommon\ReparsePointUtilities.cs" /> <Compile Include="..\TestData.cs" /> <Compile Include="..\FileSystemTest.cs" /> - <Compile Include="..\PathFeatures.cs" /> <Compile Include="Perf.Directory.cs" /> <Compile Include="Perf.File.cs" /> <Compile Include="Perf.FileInfo.cs" /> @@ -27,6 +26,9 @@ <Compile Include="$(CommonTestPath)\System\IO\FileCleanupTestBase.cs"> <Link>Common\System\IO\FileCleanupTestBase.cs</Link> </Compile> + <Compile Include="$(CommonTestPath)\System\IO\PathFeatures.cs"> + <Link>Common\System\IO\PathFeatures.cs</Link> + </Compile> </ItemGroup> <ItemGroup> <ProjectReference Include="$(CommonPath)\..\perf\PerfRunner\PerfRunner.csproj"> diff --git a/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj b/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj index d265aaf3a2..109b8c4975 100644 --- a/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj +++ b/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj @@ -97,7 +97,6 @@ <Compile Include="File\Move.cs" /> <Compile Include="File\ReadWriteAllText.cs" /> <Compile Include="File\ReadWriteAllLines.cs" /> - <Compile Include="PathFeatures.cs" /> <Compile Include="TestData.cs" /> <Compile Include="UnseekableFileStream.cs" /> <Compile Include="FSAssert.cs" /> @@ -160,6 +159,9 @@ <Compile Include="$(CommonTestPath)\System\IO\TempFile.cs"> <Link>Common\System\IO\TempFile.cs</Link> </Compile> + <Compile Include="$(CommonTestPath)\System\IO\PathFeatures.cs"> + <Link>Common\System\IO\PathFeatures.cs</Link> + </Compile> <Compile Include="$(CommonTestPath)\System\PlatformDetection.cs"> <Link>Common\System\PlatformDetection.cs</Link> </Compile> diff --git a/src/System.Runtime.Extensions/tests/System.Runtime.Extensions.Tests.csproj b/src/System.Runtime.Extensions/tests/System.Runtime.Extensions.Tests.csproj index 1aa2a71a5e..c12743c39d 100644 --- a/src/System.Runtime.Extensions/tests/System.Runtime.Extensions.Tests.csproj +++ b/src/System.Runtime.Extensions/tests/System.Runtime.Extensions.Tests.csproj @@ -91,6 +91,9 @@ <Compile Include="$(CommonTestPath)\System\IO\FileCleanupTestBase.cs"> <Link>Common\System\IO\FileCleanupTestBase.cs</Link> </Compile> + <Compile Include="$(CommonTestPath)\System\IO\PathFeatures.cs"> + <Link>Common\System\IO\PathFeatures.cs</Link> + </Compile> <Compile Include="$(CommonTestPath)\System\ShouldNotBeInvokedException.cs"> <Link>Common\System\ShouldNotBeInvokedException.cs</Link> </Compile> diff --git a/src/System.Runtime.Extensions/tests/System/IO/PathTests.cs b/src/System.Runtime.Extensions/tests/System/IO/PathTests.cs index bf055a1554..067d211f00 100644 --- a/src/System.Runtime.Extensions/tests/System/IO/PathTests.cs +++ b/src/System.Runtime.Extensions/tests/System/IO/PathTests.cs @@ -192,17 +192,27 @@ namespace System.IO.Tests [InlineData(@"\\a\b\", @"\\a\b")] [InlineData(@"\\a\b", @"\\a\b")] [InlineData(@"\\test\unc", @"\\test\unc")] - [InlineData(@"\\?\UNC\test\unc\path\to\something", @"\\?\UNC\test\unc")] - [InlineData(@"\\?\UNC\test\unc", @"\\?\UNC\test\unc")] - [InlineData(@"\\?\UNC\a\b1", @"\\?\UNC\a\b1")] - [InlineData(@"\\?\UNC\a\b2\", @"\\?\UNC\a\b2")] - [InlineData(@"\\?\C:\foo\bar.txt", @"\\?\C:\")] public static void GetPathRoot_Windows_UncAndExtended(string value, string expected) { Assert.True(Path.IsPathRooted(value)); Assert.Equal(expected, Path.GetPathRoot(value)); } + [PlatformSpecific(TestPlatforms.Windows)] // Tests UNC + [Theory] + [InlineData(@"\\?\UNC\test\unc", @"\\?\UNC", @"\\?\UNC\test\unc\path\to\something")] + [InlineData(@"\\?\UNC\test\unc", @"\\?\UNC", @"\\?\UNC\test\unc")] + [InlineData(@"\\?\UNC\a\b1", @"\\?\UNC", @"\\?\UNC\a\b1")] + [InlineData(@"\\?\UNC\a\b2", @"\\?\UNC", @"\\?\UNC\a\b2\")] + [InlineData(@"\\?\C:\", @"\\?\C:", @"\\?\C:\foo\bar.txt")] + public static void GetPathRoot_Windows_UncAndExtended_WithLegacySupport(string normalExpected, string legacyExpected, string value) + { + Assert.True(Path.IsPathRooted(value)); + + string expected = PathFeatures.IsUsingLegacyPathNormalization() ? legacyExpected : normalExpected; + Assert.Equal(expected, Path.GetPathRoot(value)); + } + [PlatformSpecific(TestPlatforms.Windows)] // Tests Windows-specific path convention [Theory] [InlineData(@"C:", @"C:")] @@ -580,14 +590,6 @@ namespace System.IO.Tests [InlineData(@"\\?\UNC\server5\share\.")] [InlineData(@"\\?\UNC\server6\share\..")] [InlineData(@"\\?\UNC\a\b\\")] - [InlineData(@"\\.\UNC\")] - [InlineData(@"\\.\UNC\server7")] - [InlineData(@"\\.\UNC\server8\")] - [InlineData(@"\\.\UNC\server9\\")] - [InlineData(@"\\.\UNC\serverA\..")] - [InlineData(@"\\.\UNC\serverB\share\.")] - [InlineData(@"\\.\UNC\serverC\share\..")] - [InlineData(@"\\.\UNC\a\b\\")] [InlineData(@"\\.\")] [InlineData(@"\\.\.")] [InlineData(@"\\.\..")] @@ -600,6 +602,13 @@ namespace System.IO.Tests [InlineData(@"\\.\C:\Foo2\..")] public static void GetFullPath_Windows_ValidExtendedPaths(string path) { + if (PathFeatures.IsUsingLegacyPathNormalization()) + { + // Legacy Path doesn't support any of these paths. + AssertExtensions.ThrowsAny<ArgumentException, NotSupportedException>(() => Path.GetFullPath(path)); + return; + } + // None of these should throw if (path.StartsWith(@"\\?\")) { @@ -611,6 +620,22 @@ namespace System.IO.Tests } } + [PlatformSpecific(TestPlatforms.Windows)] // Tests Windows-specific paths + [Theory] + [InlineData(@"\\.\UNC\")] + [InlineData(@"\\.\UNC\LOCALHOST")] + [InlineData(@"\\.\UNC\localHOST\")] + [InlineData(@"\\.\UNC\LOcaLHOST\\")] + [InlineData(@"\\.\UNC\lOCALHOST\..")] + [InlineData(@"\\.\UNC\LOCALhost\share\.")] + [InlineData(@"\\.\UNC\loCALHOST\share\..")] + [InlineData(@"\\.\UNC\a\b\\")] + public static void GetFullPath_Windows_ValidLegacy_ValidExtendedPaths(string path) + { + // should not throw + Path.GetFullPath(path); + } + [PlatformSpecific(TestPlatforms.Windows)] // Tests valid paths based on UNC [Theory] // https://github.com/dotnet/corefx/issues/11965 @@ -632,13 +657,27 @@ namespace System.IO.Tests [InlineData(@"\\.\UNC\LOCALHOST\shareF\test.txt.~SS", @"\\.\UNC\LOCALHOST\shareF\test.txt.~SS")] [InlineData(@"\\.\UNC\LOCALHOST\shareG", @"\\.\UNC\LOCALHOST\shareG")] [InlineData(@"\\.\UNC\LOCALHOST\shareH\dir", @"\\.\UNC\LOCALHOST\shareH\dir")] - [InlineData(@"\\.\UNC\LOCALHOST\shareI\", @"\\.\UNC\LOCALHOST\shareI\. ")] - [InlineData(@"\\.\UNC\LOCALHOST\shareJ\", @"\\.\UNC\LOCALHOST\shareJ\.. ")] [InlineData(@"\\.\UNC\LOCALHOST\shareK\", @"\\.\UNC\LOCALHOST\shareK\ ")] [InlineData(@"\\.\UNC\LOCALHOST\ shareL\", @"\\.\UNC\LOCALHOST\ shareL\")] - public static void GetFullPath_Windows_UNC_Valid(string expected, string input) { + if (input.StartsWith(@"\\?\") && PathFeatures.IsUsingLegacyPathNormalization()) + { + Assert.Throws<ArgumentException>(() => Path.GetFullPath(input)); + } + else + { + Assert.Equal(expected, Path.GetFullPath(input)); + } + } + + [PlatformSpecific(TestPlatforms.Windows)] // Tests valid paths based on UNC + [Theory] + [InlineData(@"\\.\UNC\LOCALHOST\shareI\", @"\\.\UNC\LOCALHOST\shareI", @"\\.\UNC\LOCALHOST\shareI\. ")] + [InlineData(@"\\.\UNC\LOCALHOST\shareJ\", @"\\.\UNC\LOCALHOST", @"\\.\UNC\LOCALHOST\shareJ\.. ")] + public static void GetFullPath_Windows_UNC_Valid_LegacyPathSupport(string normalExpected, string legacyExpected, string input) + { + string expected = PathFeatures.IsUsingLegacyPathNormalization() ? legacyExpected : normalExpected; Assert.Equal(expected, Path.GetFullPath(input)); } @@ -705,7 +744,7 @@ namespace System.IO.Tests [InlineData('?')] public static void GetFullPath_Windows_Wildcards(char wildcard) { - AssertExtensions.Throws<ArgumentException>("path", () => Path.GetFullPath("test" + wildcard + "ing")); + AssertExtensions.Throws<ArgumentException>("path", null, () => Path.GetFullPath("test" + wildcard + "ing")); } // Windows-only P/Invoke to create 8.3 short names from long names |