Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,11 @@ private static IEnumerable<ModuleSpecification> GetCandidateModuleSpecs(
IDictionary<string, ModuleSpecification> moduleSpecTable,
PSModuleInfo module)
{
const WildcardOptions options = WildcardOptions.IgnoreCase | WildcardOptions.CultureInvariant;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got this code from

const WildcardOptions options = WildcardOptions.IgnoreCase | WildcardOptions.CultureInvariant;

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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is path case sensitivity a problem here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be, but it is not a regression

{
yield return moduleSpec;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down Expand Up @@ -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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the duplicate test? We could add the $loadedModuleNameTestCases in previous test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to test the other code path for loaded modules

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

@TravisEz13 TravisEz13 Aug 11, 2019

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference in both test case names is that one has -ListAvailable the other does not. I think that makes it clear which code path is being tested.

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" {
Expand Down Expand Up @@ -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"
}
}
Expand Down