Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 24334bf

Browse files
authored
Test updates for dotnet/coreclr#16447 (#27270)
* Test updates for dotnet/coreclr#16447 * Move variant test to own method. Add GetFileName tests for volume separators.
1 parent d5351fe commit 24334bf

File tree

2 files changed

+91
-21
lines changed

2 files changed

+91
-21
lines changed

src/System.Runtime.Extensions/tests/System/IO/PathTests.cs

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,20 @@ public static void ChangeExtension(string path, string newExtension, string expe
3636
}
3737

3838
[Fact]
39-
public static void GetDirectoryName_EmptyThrows()
39+
[SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework)]
40+
public static void GetDirectoryName_EmptyThrows_Desktop()
4041
{
4142
AssertExtensions.Throws<ArgumentException>("path", null, () => Path.GetDirectoryName(string.Empty));
4243
}
4344

45+
[Fact]
46+
[ActiveIssue(27269)]
47+
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
48+
public static void GetDirectoryName_Empty_Core()
49+
{
50+
Assert.Null(Path.GetDirectoryName(string.Empty));
51+
}
52+
4453
[Theory,
4554
InlineData(" "),
4655
InlineData("\r\n")]
@@ -60,19 +69,10 @@ public static void GetDirectoryName_SpaceOrControlCharsThrowOnWindows(string pat
6069
}
6170

6271
[Fact]
63-
public static void GetDirectoryName_SpaceThrowOnWindows_Core()
72+
[ActiveIssue(27269)]
73+
public static void GetDirectoryName_Space_Core()
6474
{
65-
string path = " ";
66-
Action action = () => Path.GetDirectoryName(path);
67-
if (PlatformDetection.IsWindows)
68-
{
69-
AssertExtensions.Throws<ArgumentException>("path", null, () => Path.GetDirectoryName(path));
70-
}
71-
else
72-
{
73-
// This is a valid path on Unix
74-
action();
75-
}
75+
Assert.Null(Path.GetDirectoryName(" "));
7676
}
7777

7878
public static TheoryData<string> GetDirectoryName_NonControl_Test_Data => new TheoryData<string>
@@ -116,14 +116,17 @@ public static void GetDirectoryName(string path, string expected)
116116
{ @"..\..\files.txt", @"..\.." },
117117
{ @"C:\", null },
118118
{ @"C:", null },
119+
// { @"dir\\baz", "dir" }, https://github.com/dotnet/corefx/issues/27269
120+
{ @"C:\foo", @"C:\" },
121+
{ @"\foo", @"\" },
122+
{ @"C:foo", @"C:" }
119123
};
120124

121125
public static TheoryData<string, string> GetDirectoryName_Windows_string_Test_Data => new TheoryData<string, string>
122126
{
123-
{ @" C:\dir\baz", @"C:\dir" },
124-
{ @"dir\\baz", "dir" },
127+
// { @" C:\dir\baz", @"C:\dir" }, https://github.com/dotnet/corefx/issues/27269
125128
{ @" dir\baz", " dir" },
126-
{ @" C:\dir\baz", @"C:\dir" },
129+
// { @" C:\dir\baz", @"C:\dir" }, https://github.com/dotnet/corefx/issues/27269
127130
};
128131

129132
[PlatformSpecific(TestPlatforms.Windows)] // Tests Windows-specific paths
@@ -133,6 +136,19 @@ public static void GetDirectoryName_Windows(string path, string expected)
133136
Assert.Equal(expected, Path.GetDirectoryName(path));
134137
}
135138

139+
[PlatformSpecific(TestPlatforms.Windows)]
140+
public static void GetDirectoryName_WindowsDevicePath()
141+
{
142+
if (PathFeatures.IsUsingLegacyPathNormalization())
143+
{
144+
Assert.Equal(@"\\?\C:", Path.GetDirectoryName(@"\\?\C:\foo"));
145+
}
146+
else
147+
{
148+
Assert.Equal(@"\\?\C:\", Path.GetDirectoryName(@"\\?\C:\foo"));
149+
}
150+
}
151+
136152
public static TheoryData<string, string> GetDirectoryName_Unix_Test_Data => new TheoryData<string, string>
137153
{
138154
{ @"dir/baz", @"dir" },
@@ -284,11 +300,20 @@ public static void GetPathRoot_NullReturnsNull()
284300
}
285301

286302
[Fact]
287-
public static void GetPathRoot_EmptyThrows()
303+
[SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework)]
304+
public static void GetPathRoot_EmptyThrows_Desktop()
288305
{
289306
AssertExtensions.Throws<ArgumentException>("path", null, () => Path.GetPathRoot(string.Empty));
290307
}
291308

309+
[Fact]
310+
[ActiveIssue(27269)]
311+
[SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework)]
312+
public static void GetPathRoot_EmptyIsNull_Core()
313+
{
314+
Assert.Null(Path.GetPathRoot(string.Empty));
315+
}
316+
292317
[Fact]
293318
public static void GetPathRoot_Basic()
294319
{
@@ -887,7 +912,6 @@ public static void GetFullPath_Windows_ValidLegacy_ValidExtendedPaths(string pat
887912
// https://github.com/dotnet/corefx/issues/11965
888913
[InlineData(@"\\LOCALHOST\share\test.txt.~SS", @"\\LOCALHOST\share\test.txt.~SS")]
889914
[InlineData(@"\\LOCALHOST\share1", @"\\LOCALHOST\share1")]
890-
[InlineData(@"\\LOCALHOST\share2", @" \\LOCALHOST\share2")]
891915
[InlineData(@"\\LOCALHOST\share3\dir", @"\\LOCALHOST\share3\dir")]
892916
[InlineData(@"\\LOCALHOST\share4", @"\\LOCALHOST\share4\.")]
893917
[InlineData(@"\\LOCALHOST\share5", @"\\LOCALHOST\share5\..")]

src/System.Runtime.Extensions/tests/System/IO/PathTests.netcoreapp.cs

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.Collections.Generic;
6-
using System.Runtime.InteropServices;
7-
using System.Text;
8-
using System.Text.RegularExpressions;
96
using Xunit;
107

118
namespace System.IO.Tests
@@ -46,6 +43,9 @@ public static void GetDirectoryName_CurrentDirectory_Span()
4643
Assert.Equal(string.Empty, new string(Path.GetDirectoryName(Path.GetPathRoot(curDir).AsReadOnlySpan())));
4744
}
4845

46+
47+
48+
4949
[Theory, MemberData(nameof(GetExtension_Test_Data))]
5050
public static void GetExtension_Span(string path, string expected)
5151
{
@@ -58,6 +58,52 @@ public static void GetExtension_Span(string path, string expected)
5858
}
5959
}
6060

61+
public static IEnumerable<object[]> GetFileName_VolumeTestData()
62+
{
63+
yield return new object[] { ":", ":" };
64+
yield return new object[] { ".:", ".:" };
65+
yield return new object[] { ".:.", ".:." }; // Not a valid drive letter
66+
yield return new object[] { "file:", "file:" };
67+
yield return new object[] { ":file", ":file" };
68+
yield return new object[] { "file:exe", "file:exe" };
69+
yield return new object[] { Path.Combine("baz", "file:exe"), "file:exe" };
70+
yield return new object[] { Path.Combine("bar", "baz", "file:exe"), "file:exe" };
71+
}
72+
73+
[ActiveIssue(27269)]
74+
[Theory]
75+
[MemberData(nameof(GetFileName_VolumeTestData))]
76+
public static void GetFileName_Volume(string path, string expected)
77+
{
78+
// We used to break on ':' on Windows. This is a valid file name character for alternate data streams.
79+
// Additionally the character can show up on unix volumes mounted to Windows.
80+
Assert.Equal(expected, Path.GetFileName(path));
81+
Assert.Equal(expected, new string(Path.GetFileName(path.AsReadOnlySpan())));
82+
}
83+
84+
[ActiveIssue(27269)]
85+
[Theory]
86+
[InlineData("B:", "")]
87+
[InlineData("A:.", ".")]
88+
[PlatformSpecific(TestPlatforms.Windows)]
89+
public static void GetFileName_Volume_Windows(string path, string expected)
90+
{
91+
// With a valid drive letter followed by a colon, we have a root, but only on Windows.
92+
Assert.Equal(expected, Path.GetFileName(path));
93+
Assert.Equal(expected, new string(Path.GetFileName(path.AsReadOnlySpan())));
94+
}
95+
96+
[Theory]
97+
[InlineData("B:", "B:")]
98+
[InlineData("A:.", "A:.")]
99+
[PlatformSpecific(TestPlatforms.AnyUnix)]
100+
public static void GetFileName_Volume_Unix(string path, string expected)
101+
{
102+
// No such thing as a drive relative path on Unix.
103+
Assert.Equal(expected, Path.GetFileName(path));
104+
Assert.Equal(expected, new string(Path.GetFileName(path.AsReadOnlySpan())));
105+
}
106+
61107
[Theory]
62108
[MemberData(nameof(GetFileName_TestData))]
63109
public static void GetFileName_Span(string path, string expected)

0 commit comments

Comments
 (0)