Repository navigation
fix: limit the three-character extension rule to .NET Framework - #1611
Open
mohsinaliwork686-rgb wants to merge 1 commit into
Open
mohsinaliwork686-rgb wants to merge 1 commit into
mohsinaliwork686-rgb wants to merge 1 commit into
Conversation
Contributor
|
Tick the box to add this pull request to the merge queue (same as
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #895
On .NET Core and .NET 5+,
MockFileSystemmatched a three-character extension against longer ones:*.xlsfoundbook.xlsx,*.txtfoundb.txt2and*.giffoundc.gifx, inDirectory.GetFiles,EnumerateFiles,GetDirectoriesand everything built on them (DirectoryInfo.GetFilesand so on). The realDirectorythere returns onlybook.xls. TheEnumerateFilesdocs describe the longer match as .NET Framework only, and their table givesbook.xlsfor .NET 5+ andbook.xls, book.xlsxfor .NET Framework.What was wrong
When the search pattern ends in a three-character extension with no wildcards in it,
MockDirectory.GetFilesInternalbuilds a second pattern (pathPatternSpecial) that allows one more character after the extension. That copies .NET Framework, but it was built on every runtime.What changed
The second pattern is now only built on .NET Framework.
MockDirectoryhas a private staticIsNetFrameworkflag, set fromRuntimeInformation.FrameworkDescriptionthe same way Testably.Abstractions does it for this case (Testably/Testably.Abstractions#530). On .NET Core and .NET 5+,*.xlsnow matches only.xls, like the realDirectory. On .NET Framework nothing changes, as asked on the issue. Since the docs call the longer match .NET Framework only, .NET Core gets the .NET 5+ result too.It's a runtime check rather than
#if NETFRAMEWORKbecause thenetstandard2.0andnetstandard2.1builds can run on either. A project on .NET Framework 4.6.1 to 4.7.1 getsnetstandard2.0, and a .NET Core 3.1 or .NET 5 project getsnetstandard2.1.RuntimeInformationis already used inCommonExceptions, so there's no new dependency.How it's tested
The two existing tests that expect
*.gifto findc.gifx(MockDirectory_GetFiles_ShouldFilterByExtensionBasedSearchPatternWithThreeCharacterLongFileExtension_RespectingAllDirectorySearchOptionand..._RespectingTopDirectorySearchOption) now compile only for .NET Framework (#if NETFRAMEWORK), so net472 keeps checking the old behaviour. For the other frameworks I added these toMockDirectoryTests:.giffilesEnumerateFileswith the cases from the issue:*.txtwitha.txtandb.txt2, and*.xlswithbook.xlsandbook.xlsxGetDirectories("*.gif")with foldersb.gifandb.gifx, because directory search goes through the same methodThey fail on
mainand pass with the fix. I also checked each expected result against the realDirectoryon .NET 8, 9 and 10 on macOS, and it returns only the exact extension every time.I ran this on macOS (12.7) with the .NET 9 and 10 SDKs and the .NET 8, 9 and 10 runtimes, and on Linux in the
mcr.microsoft.com/dotnet/sdk:11.0.100container for net11.0, because the .NET 11 SDK doesn't start on that macOS version. The Release build of the solution has no warnings or errors. The Wrappers, TestingHelpers and Parity tests all pass on net11.0 (Linux) and on net10.0, net9.0 and net8.0 (macOS), and on each of those the five new test cases fail without the change and pass with it. The API tests pass for every target: net472, netstandard2.0, netstandard2.1, net6.0, net8.0, net9.0 and net10.0 on macOS, and net11.0 in the container.I couldn't run net472 or the Windows tests, because .NET Framework doesn't run on macOS or Linux. I did build the TestingHelpers tests for net472 to make sure the
#if NETFRAMEWORKpart compiles, and the net472 assembly has the two old tests and none of the new ones. On .NET Framework the flag istrue, so the second pattern is built exactly as before. CI covers Windows and net472.One thing I left alone: the mock's .NET Framework rule isn't exact either. It allows only one extra character, so
*.xlsfindsbook.xlsxbut notbook.xlsxx. It also applies without a*or with a?elsewhere in the pattern, sobook.xlsand?ook.xlsfindbook.xlsxtoo, which the docs say .NET Framework doesn't do. I didn't touch it, since the issue asked to keep .NET Framework as it is. Should I tighten it in a separate PR?