Skip to content

Commit e00df8a

Browse files
authored
Use Path.Join instead of Path.Combine (#13090)
It is faster, and more predictable. Most changes are in test code. Tweak behavior in AssemblyNamesTypeResolutionService to use API based program files and add separator for proper contains checking. No need to use both paths, it will always be current process specific. ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/dotnet/winforms/pull/13090)
1 parent d05024e commit e00df8a

File tree

33 files changed

+167
-174
lines changed

33 files changed

+167
-174
lines changed

src/Common/tests/TestUtilities/FileCleanupTestBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public string TestDirectory
1616
{
1717
if (_testDirectory is null)
1818
{
19-
_testDirectory = Path.Combine(Path.GetTempPath(), GetUniqueName());
19+
_testDirectory = Path.Join(Path.GetTempPath(), GetUniqueName());
2020
Directory.CreateDirectory(_testDirectory);
2121
}
2222

@@ -43,7 +43,7 @@ protected virtual void Dispose(bool disposing)
4343
}
4444
}
4545

46-
public string GetTestFilePath() => Path.Combine(TestDirectory, GetTestFileName());
46+
public string GetTestFilePath() => Path.Join(TestDirectory, GetTestFileName());
4747

4848
public static string GetTestFileName() => GetUniqueName();
4949

src/Common/tests/TestUtilities/TempFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,6 @@ private void DeleteFile()
8181
private static string GetFilePath(string? memberName, int lineNumber)
8282
{
8383
string file = $"{IO.Path.GetRandomFileName()}_{memberName}_{lineNumber}";
84-
return IO.Path.Combine(IO.Path.GetTempPath(), file);
84+
return IO.Path.Join(IO.Path.GetTempPath(), file);
8585
}
8686
}

src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Logging/FileLogTraceListener.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Namespace Microsoft.VisualBasic.Logging
166166
Debug.Fail("Unrecognized LogFileCreationSchedule")
167167
End Select
168168

169-
Return Path.Combine(basePath, fileName)
169+
Return Path.Join(basePath, fileName)
170170
End Get
171171
End Property
172172

src/Microsoft.VisualBasic.Forms/tests/UnitTests/System/Windows/Forms/FileLogTraceListenerTests.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Namespace Microsoft.VisualBasic.Forms.Tests
4545
listener.DiskSpaceExhaustedBehavior = DiskSpaceExhaustedOption.ThrowException
4646
listener.DiskSpaceExhaustedBehavior.Should.Be(DiskSpaceExhaustedOption.ThrowException)
4747

48-
listener.FullLogFileName.Should.BeEquivalentTo(Path.Combine(testDirectory, $"{expectedBaseFileName}.log"))
48+
listener.FullLogFileName.Should.BeEquivalentTo(Path.Join(testDirectory, $"{expectedBaseFileName}.log"))
4949

5050
listener.LogFileCreationSchedule.Should.Be(LogFileCreationScheduleOption.None)
5151
listener.LogFileCreationSchedule = LogFileCreationScheduleOption.Daily

src/Microsoft.VisualBasic.Forms/tests/UnitTests/System/Windows/Forms/VbFileCleanupTestBaseTests.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Namespace Microsoft.VisualBasic.Forms.Tests
3232

3333
<WinFormsFact>
3434
Public Sub DirectoryIsAccessibleWithNonexistentPath()
35-
Dim directoryPath As String = Path.Combine(CreateTempDirectory(), GetUniqueFileName)
35+
Dim directoryPath As String = Path.Join(CreateTempDirectory(), GetUniqueFileName)
3636
DirectoryIsAccessible(directoryPath).Should.BeFalse()
3737
End Sub
3838

src/Microsoft.VisualBasic.Forms/tests/UnitTests/System/Windows/TestUtilities/VbFileCleanupTestBase.vb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Namespace Microsoft.VisualBasic.Forms.Tests
99
Public MustInherit Class VbFileCleanupTestBase
1010
Implements IDisposable
1111

12-
Private Shared ReadOnly s_baseTempPath As String = Path.Combine(Path.GetTempPath, "DownLoadTest9d9e3a8-7a46-4333-a0eb-4faf76994801")
12+
Private Shared ReadOnly s_baseTempPath As String = Path.Join(Path.GetTempPath, "DownLoadTest9d9e3a8-7a46-4333-a0eb-4faf76994801")
1313
Friend Const DefaultFileName As String = "Testing.Txt"
1414
Friend ReadOnly _testDirectories As New HashSet(Of String)
1515

@@ -46,7 +46,7 @@ Namespace Microsoft.VisualBasic.Forms.Tests
4646
''' If size = -1 no file is create but the full path is returned.
4747
''' </returns>
4848
Friend Shared Function CreateTempFile(sourceDirectoryName As String, Optional filename As String = DefaultFileName, Optional size As Integer = -1) As String
49-
Dim filenameWithPath As String = Path.Combine(sourceDirectoryName, filename)
49+
Dim filenameWithPath As String = Path.Join(sourceDirectoryName, filename)
5050

5151
If size >= 0 Then
5252
Using destinationStream As FileStream = File.Create(filenameWithPath)
@@ -68,7 +68,7 @@ Namespace Microsoft.VisualBasic.Forms.Tests
6868
If Not info.Exists Then
6969
Return False
7070
End If
71-
Dim path As String = IO.Path.Combine(directoryPath, GetUniqueFileName())
71+
Dim path As String = IO.Path.Join(directoryPath, GetUniqueFileName())
7272
Using stream As FileStream = File.Create(path)
7373
stream.Close()
7474
End Using
@@ -82,7 +82,7 @@ Namespace Microsoft.VisualBasic.Forms.Tests
8282
End Function
8383

8484
Friend Shared Function GetUniqueFileNameWithPath(testDirectory As String) As String
85-
Return Path.Combine(testDirectory, GetUniqueFileName())
85+
Return Path.Join(testDirectory, GetUniqueFileName())
8686
End Function
8787

8888
''' <summary>
@@ -96,9 +96,9 @@ Namespace Microsoft.VisualBasic.Forms.Tests
9696
Friend Function CreateTempDirectory(<CallerMemberName> Optional memberName As String = Nothing, Optional lineNumber As Integer = -1) As String
9797
Dim folder As String
9898
If lineNumber > 0 Then
99-
folder = Path.Combine(BaseTempPath, $"{memberName}{lineNumber}")
99+
folder = Path.Join(BaseTempPath, $"{memberName}{lineNumber}")
100100
Else
101-
folder = Path.Combine(BaseTempPath, memberName)
101+
folder = Path.Join(BaseTempPath, memberName)
102102
End If
103103

104104
If _testDirectories.Add(folder) Then

src/Microsoft.VisualBasic/tests/IntegrationTests/Microsoft.VisualBasic.IntegrationTests/InteractionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void Shell_ArgumentNullException()
104104
[Fact]
105105
public void Shell_FileNotFoundException()
106106
{
107-
string path = Path.Combine(Path.GetTempPath(), GetUniqueName());
107+
string path = Path.Join(Path.GetTempPath(), GetUniqueName());
108108
// Exception.ToString() called to verify message is constructed successfully.
109109
_ = Assert.Throws<FileNotFoundException>(() => Interaction.Shell(path)).ToString();
110110
}

src/Microsoft.VisualBasic/tests/UnitTests/Microsoft/VisualBasic/Devices/AudioTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void PlayEmptyFileNameAudioMode_Throws(string fileName)
4949
[InvalidEnumData<AudioPlayMode>]
5050
public void PlayModeInvalid_Throws(AudioPlayMode audioPlayMode)
5151
{
52-
string location = Path.Combine(Path.GetTempPath(), GetUniqueName());
52+
string location = Path.Join(Path.GetTempPath(), GetUniqueName());
5353
Audio audio = new();
5454
Action testCode = () => audio.Play(location, audioPlayMode);
5555
testCode.Should().Throw<InvalidEnumArgumentException>();

0 commit comments

Comments
 (0)