-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Make module name matching for get-module -FullyQualifiedName ignore case
#10329
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -573,9 +573,11 @@ private static IEnumerable<ModuleSpecification> GetCandidateModuleSpecs( | |||
| IDictionary<string, ModuleSpecification> moduleSpecTable, | ||||
| PSModuleInfo module) | ||||
| { | ||||
| const WildcardOptions options = WildcardOptions.IgnoreCase | WildcardOptions.CultureInvariant; | ||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got this code from
which is called earlier in the code path. |
||||
| foreach (ModuleSpecification moduleSpec in moduleSpecTable.Values) | ||||
| { | ||||
| if (moduleSpec.Name == module.Name || moduleSpec.Name == module.Path || module.Path.Contains(moduleSpec.Name)) | ||||
| WildcardPattern namePattern = WildcardPattern.Get(moduleSpec.Name, options); | ||||
| if (namePattern.IsMatch(module.Name) || moduleSpec.Name == module.Path || module.Path.Contains(moduleSpec.Name)) | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is path case sensitivity a problem here?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be, but it is not a regression |
||||
| { | ||||
| yield return moduleSpec; | ||||
| } | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,35 @@ Describe "Get-Module -ListAvailable" -Tags "CI" { | |
| @{ ModPath = "$TestDrive\Modules\Zoo\Too\Zoo.psm1"; Name = 'Zoo'; Version = '0.0'; Count = 1 } | ||
| ) | ||
|
|
||
| $listModuleNameTestCases = @( | ||
| @{ | ||
| Name = 'Foo' | ||
| TestCaseName = 'Match case' | ||
| ExpectedName = 'Foo' | ||
| ModuleVersion = '2.0' | ||
| } | ||
| @{ | ||
| Name = 'foo' | ||
| TestCaseName = 'Mismatched case' | ||
| ExpectedName = 'Foo' | ||
| ModuleVersion = '2.0' | ||
| } | ||
| ) | ||
| $loadedModuleNameTestCases = @( | ||
| @{ | ||
| Name = 'Microsoft.PowerShell.Managemen*' | ||
| TestCaseName = 'Wildcard' | ||
| ExpectedName = 'Microsoft.PowerShell.Management' | ||
| ModuleVersion = '6.1.0.0' | ||
| } | ||
| @{ | ||
| Name = 'microsoft.powershell.managemen*' | ||
| TestCaseName = 'Mismatched case' | ||
| ExpectedName = 'Microsoft.PowerShell.Management' | ||
| ModuleVersion = '6.1.0.0' | ||
| } | ||
| ) | ||
|
|
||
| $env:PSModulePath = Join-Path $testdrive "Modules" | ||
| } | ||
|
|
||
|
|
@@ -114,12 +143,38 @@ Describe "Get-Module -ListAvailable" -Tags "CI" { | |
| $modules[4].Path | Should -BeExactly (Resolve-Path "$testdrive\Modules\Zoo\Too\Zoo.psm1").Path | ||
| } | ||
|
|
||
| It "Get-Module -FullyQualifiedName <FullyQualifiedName> -ListAvailable" { | ||
| $moduleSpecification = @{ModuleName = "Foo"; ModuleVersion = "2.0"} | ||
| It "Get-Module -FullyQualifiedName @{ModuleName = '<Name>' ; ModuleVersion = '<ModuleVersion>'} -ListAvailable - <TestCaseName>" -TestCases $listModuleNameTestCases { | ||
| param( | ||
| [Parameter(Mandatory = $true)] | ||
| $Name, | ||
| $TestCaseName, | ||
| [Parameter(Mandatory = $true)] | ||
| $ExpectedName, | ||
| $ModuleVersion | ||
| ) | ||
|
|
||
| $moduleSpecification = @{ModuleName = $name ; ModuleVersion = $ModuleVersion} | ||
| $modules = Get-Module -FullyQualifiedName $moduleSpecification -ListAvailable | ||
| $modules | Should -HaveCount 1 | ||
| $modules.Name | Should -BeExactly "Foo" | ||
| $modules.Version | Should -BeExactly "2.0" | ||
| $modules.Name | Should -BeExactly $ExpectedName | ||
| $modules.Version | Should -BeExactly $ModuleVersion | ||
| } | ||
|
|
||
| It "Get-Module -FullyQualifiedName @{ModuleName = '<Name>' ; ModuleVersion = '<ModuleVersion>'} - <TestCaseName>" -TestCases $loadedModuleNameTestCases { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need the duplicate test? We could add the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to test the other code path for loaded modules
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the case I'd expect that test names say this explicitly and more clear. Otherwise I don't understand why we duplicate the code.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide a suggestion on how to say it more clearly that stating the command line that is being run. To me, this is honestly, about as explicit as we can get.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The difference in both test case names is that one has |
||
| param( | ||
| [Parameter(Mandatory = $true)] | ||
| $Name, | ||
| $TestCaseName, | ||
| [Parameter(Mandatory = $true)] | ||
| $ExpectedName, | ||
| $ModuleVersion | ||
| ) | ||
|
|
||
| $moduleSpecification = @{ModuleName = $name ; ModuleVersion = $ModuleVersion} | ||
| $modules = Get-Module -FullyQualifiedName $moduleSpecification | ||
| $modules | Should -HaveCount 1 | ||
| $modules.Name | Should -BeExactly $ExpectedName | ||
| $modules.Version | Should -BeExactly $ModuleVersion | ||
| } | ||
|
|
||
| It "Get-Module <Name> -Refresh -ListAvailable" { | ||
|
|
@@ -219,7 +274,7 @@ Describe "Get-Module -ListAvailable" -Tags "CI" { | |
|
|
||
| It "'Get-Module -ListAvailable' should not load the module assembly" { | ||
| ## $fullName should be null and thus the result should just be the module's name. | ||
| $result = pwsh -c "`$env:PSModulePath = '$tempModulePath'; `$module = Get-Module -ListAvailable; `$fullName = [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object Location -eq $assemblyPath | Foreach-Object FullName; `$module.Name + `$fullName" | ||
| $result = pwsh -noprofile -c "`$env:PSModulePath = '$tempModulePath'; `$module = Get-Module -ListAvailable; `$fullName = [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object Location -eq $assemblyPath | Foreach-Object FullName; `$module.Name + `$fullName" | ||
| $result | Should -BeExactly "MyModuelTest" | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.