Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/vstest.console/Internal/FilePatternParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -96,7 +97,7 @@ private Tuple<string, string> 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);
Expand Down
12 changes: 12 additions & 0 deletions test/vstest.console.UnitTests/Internal/FilePatternParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ public void FilePatternParserShouldCorrectlySplitPatternAndDirectory()
_mockMatcherHelper.Verify(x => x.Execute(It.Is<DirectoryInfoWrapper>(y => y.FullName.Equals(TranslatePath(@"C:\Users\vanidhi\Desktop\a\c")))));
}

[TestMethod]
public void FilePatternParserShouldCorrectlySplitPatternAndDirectoryWithAlternateSeparator()
{
var patternMatchingResult = new PatternMatchingResult(new List<FilePatternMatch>());
_mockMatcherHelper.Setup(x => x.Execute(It.IsAny<DirectoryInfoWrapper>())).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<DirectoryInfoWrapper>(y => y.FullName.Equals(TranslatePath(@"C:\Users\vanidhi\Desktop\a\c")))));
}

[TestMethod]
public void FilePatternParserShouldCorrectlySplitWithArbitraryDirectoryDepth()
{
Expand Down