diff --git a/src/vstest.console/Internal/FilePatternParser.cs b/src/vstest.console/Internal/FilePatternParser.cs index 804739ca7e..315f9a9059 100644 --- a/src/vstest.console/Internal/FilePatternParser.cs +++ b/src/vstest.console/Internal/FilePatternParser.cs @@ -28,6 +28,7 @@ public class FilePatternParser private readonly Matcher _matcher; private readonly IFileHelper _fileHelper; private readonly char[] _wildCardCharacters = ['*']; + private readonly char[] _directorySeparatorCharacters = [Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar]; public FilePatternParser() : this(new Matcher(), new FileHelper()) @@ -96,7 +97,7 @@ private Tuple SplitFilePatternOnWildCard(string filePattern) { // Split the pattern based on first wild card character found. var splitOnWildCardIndex = filePattern.IndexOfAny(_wildCardCharacters); - var directorySeparatorIndex = filePattern.Substring(0, splitOnWildCardIndex).LastIndexOf(Path.DirectorySeparatorChar); + var directorySeparatorIndex = filePattern.Substring(0, splitOnWildCardIndex).LastIndexOfAny(_directorySeparatorCharacters); string searchDir = filePattern.Substring(0, directorySeparatorIndex); string pattern = filePattern.Substring(directorySeparatorIndex + 1); diff --git a/test/vstest.console.UnitTests/Internal/FilePatternParserTests.cs b/test/vstest.console.UnitTests/Internal/FilePatternParserTests.cs index 571936d859..ed42ad2aca 100644 --- a/test/vstest.console.UnitTests/Internal/FilePatternParserTests.cs +++ b/test/vstest.console.UnitTests/Internal/FilePatternParserTests.cs @@ -43,6 +43,18 @@ public void FilePatternParserShouldCorrectlySplitPatternAndDirectory() _mockMatcherHelper.Verify(x => x.Execute(It.Is(y => y.FullName.Equals(TranslatePath(@"C:\Users\vanidhi\Desktop\a\c"))))); } + [TestMethod] + public void FilePatternParserShouldCorrectlySplitPatternAndDirectoryWithAlternateSeparator() + { + var patternMatchingResult = new PatternMatchingResult(new List()); + _mockMatcherHelper.Setup(x => x.Execute(It.IsAny())).Returns(patternMatchingResult); + _filePatternParser.GetMatchingFiles(TranslatePath(@"C:/Users/vanidhi/Desktop/a/c/*bc.dll")); + + // Assert + _mockMatcherHelper.Verify(x => x.AddInclude(TranslatePath(@"*bc.dll"))); + _mockMatcherHelper.Verify(x => x.Execute(It.Is(y => y.FullName.Equals(TranslatePath(@"C:\Users\vanidhi\Desktop\a\c"))))); + } + [TestMethod] public void FilePatternParserShouldCorrectlySplitWithArbitraryDirectoryDepth() {