Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure that *.* always means all files in FileMatcher #6235

Merged
merged 1 commit into from Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Shared/FileMatcher.cs
Expand Up @@ -131,7 +131,7 @@ internal FileMatcher(IFileSystem fileSystem, GetFileSystemEntries getFileSystemE
"*",
directory,
false));
IEnumerable<string> filteredEntriesForPath = (pattern != null && pattern != "*")
IEnumerable<string> filteredEntriesForPath = (pattern != null && pattern != "*" && pattern != "*.*")
? allEntriesForPath.Where(o => IsMatch(Path.GetFileName(o), pattern))
: allEntriesForPath;
return stripProjectDirectory
Expand Down
21 changes: 17 additions & 4 deletions src/Shared/UnitTests/FileMatcher_Tests.cs
Expand Up @@ -5,6 +5,7 @@
using Shouldly;
using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -77,9 +78,9 @@ public void GetFilesComplexGlobbingMatching(GetFilesComplexGlobbingMatchingInfo
File.WriteAllBytes(fullPath, new byte[1]);
}

void Verify(string include, string[] excludes, bool shouldHaveNoMatches = false, string customMessage = null)
void VerifyImpl(FileMatcher fileMatcher, string include, string[] excludes, bool shouldHaveNoMatches = false, string customMessage = null)
{
string[] matchedFiles = FileMatcher.Default.GetFiles(testFolder.Path, include, excludes?.ToList());
string[] matchedFiles = fileMatcher.GetFiles(testFolder.Path, include, excludes?.ToList());

if (shouldHaveNoMatches)
{
Expand All @@ -99,6 +100,18 @@ void Verify(string include, string[] excludes, bool shouldHaveNoMatches = false,
}
}

var fileMatcherWithCache = new FileMatcher(FileSystems.Default, new ConcurrentDictionary<string, IReadOnlyList<string>>());

void Verify(string include, string[] excludes, bool shouldHaveNoMatches = false, string customMessage = null)
{
// Verify using the default non-caching FileMatcher.
VerifyImpl(FileMatcher.Default, include, excludes, shouldHaveNoMatches, customMessage);

// Verify using a caching FileMatcher and do it twice to exercise the cache.
VerifyImpl(fileMatcherWithCache, include, excludes, shouldHaveNoMatches, customMessage);
VerifyImpl(fileMatcherWithCache, include, excludes, shouldHaveNoMatches, customMessage);
}

// Normal matching
Verify(info.Include, info.Excludes);

Expand Down Expand Up @@ -153,7 +166,7 @@ public class GetFilesComplexGlobbingMatchingInfo
@"subdirectory\subdirectory.cs",
@"build\baz\foo.cs",
@"readme.txt",
@"licence.md"
@"licence"
};

/// <summary>
Expand Down Expand Up @@ -355,7 +368,7 @@ public static IEnumerable<object[]> GetTestData()
ExpectedMatches = new[]
{
@"readme.txt",
@"licence.md"
@"licence"
}
}
};
Expand Down