Skip to content

Commit 0ab1d4b

Browse files
Copilotnohwnd
andcommitted
Address PR feedback: OS-specific separator handling and fix test username
Co-authored-by: nohwnd <5735905+nohwnd@users.noreply.github.com>
1 parent 94968fe commit 0ab1d4b

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/vstest.console/Internal/FilePatternParser.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.Globalization;
77
using System.IO;
8+
using System.Runtime.InteropServices;
89

910
using Microsoft.Extensions.FileSystemGlobbing;
1011
using Microsoft.Extensions.FileSystemGlobbing.Abstractions;
@@ -98,12 +99,22 @@ private Tuple<string, string> SplitFilePatternOnWildCard(string filePattern)
9899
var splitOnWildCardIndex = filePattern.IndexOfAny(_wildCardCharacters);
99100
var pathBeforeWildCard = filePattern.Substring(0, splitOnWildCardIndex);
100101

101-
// Find the last directory separator (either \ or /) before the wildcard
102-
// On Windows, both \ and / are valid directory separators
103-
// On Unix-like systems, only / is typically valid, but this approach is safe for both
104-
var directorySeparatorIndex = Math.Max(
105-
pathBeforeWildCard.LastIndexOf(Path.DirectorySeparatorChar),
106-
pathBeforeWildCard.LastIndexOf(Path.AltDirectorySeparatorChar));
102+
// Find the last directory separator before the wildcard
103+
// On Windows, we need to check both \ and / as both are valid
104+
// On Unix-like systems, only / is the directory separator
105+
int directorySeparatorIndex;
106+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
107+
{
108+
// On Windows, check both separators and take the last one found
109+
directorySeparatorIndex = Math.Max(
110+
pathBeforeWildCard.LastIndexOf(Path.DirectorySeparatorChar),
111+
pathBeforeWildCard.LastIndexOf(Path.AltDirectorySeparatorChar));
112+
}
113+
else
114+
{
115+
// On Unix-like systems, only use the forward slash
116+
directorySeparatorIndex = pathBeforeWildCard.LastIndexOf(Path.DirectorySeparatorChar);
117+
}
107118

108119
string searchDir = filePattern.Substring(0, directorySeparatorIndex);
109120
string pattern = filePattern.Substring(directorySeparatorIndex + 1);

test/vstest.console.UnitTests/Internal/FilePatternParserTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ public void FilePatternParserShouldCorrectlySplitPatternAndDirectoryWithForwardS
122122

123123
// Test with forward slashes - this should work on all platforms
124124
// This specifically tests the fix for issue #14993
125-
_filePatternParser.GetMatchingFiles("C:/Users/vanidhi/Desktop/a/c/*bc.dll");
125+
_filePatternParser.GetMatchingFiles("C:/Users/someUser/Desktop/a/c/*bc.dll");
126126

127127
// Assert that the pattern is parsed correctly
128128
_mockMatcherHelper.Verify(x => x.AddInclude("*bc.dll"));
129129
// On Windows, the path may be normalized, so we verify the key components are present
130130
_mockMatcherHelper.Verify(x => x.Execute(It.Is<DirectoryInfoWrapper>(y =>
131-
y.FullName.Contains("vanidhi") && y.FullName.Contains("Desktop") &&
131+
y.FullName.Contains("someUser") && y.FullName.Contains("Desktop") &&
132132
y.FullName.Contains("a") && y.FullName.EndsWith("c"))));
133133
}
134134

0 commit comments

Comments
 (0)