Tests for Get-Module - #27790
Open
Guillermo López-Anglada (guillermooo) wants to merge 10 commits into
Open
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Get-Module
Guillermo López-Anglada (guillermooo)
marked this pull request as ready for review
August 9, 2026 20:11
Guillermo López-Anglada (guillermooo)
requested a review
from a team
as a code owner
August 9, 2026 20:11
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Copilot started reviewing on behalf of
Guillermo López-Anglada (guillermooo)
August 9, 2026 20:12
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Pester coverage for Get-Module -ListAvailable path-like inputs to document current (and sometimes surprising) resolution behavior, in support of issue #27716.
Changes:
- Adds a new
Describeblock covering absolute-path arguments for-FullyQualifiedNameand-Name. - Adds cases for missing script modules vs missing manifest modules, including under
$env:PSModulePath. - Adds coverage for “basename without extension” behavior when a
.psm1exists.
Suppressed comments (5)
test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1:299
- These path literals use Windows-style
\separators (e.g."$psModulePath\missing.psm1"). UseJoin-Pathso the test behaves consistently across platforms.
It 'wrongly returns module information instead of $null or error for missing script module under $env:PSModulePath' {
$path = [System.IO.Path]::GetFullPath("$psModulePath\missing.psm1")
Test-Path $path | Should -BeFalse
Get-Module -ListAvailable -FullyQualifiedName $path | Should -BeOfType ([System.Management.Automation.PSModuleInfo])
Get-Module -ListAvailable -Name $path | Should -BeOfType ([System.Management.Automation.PSModuleInfo])
test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1:313
- Same issue here:
-Becauseis not an error-message matcher forShould -Throw. Use-ErrorIdand build the path portably withJoin-Path.
It 'writes error for missing manifest module under $env:PSModulePath' {
$path = [System.IO.Path]::GetFullPath("$psModulePath\missing")
Test-Path $path | Should -BeFalse
{ Get-Module -ListAvailable -FullyQualifiedName $path -ErrorAction Stop } | Should -Throw -Because '*Update the Name parameter*'
{ Get-Module -ListAvailable -Name $path -ErrorAction Stop } | Should -Throw -Because '*Update the Name parameter*'
test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1:319
- This second
$env:PSModulePathsplit also hard-codes';'. Use[System.IO.Path]::PathSeparatorhere as well to avoid breaking non-Windows CI runs.
$psModulePath = ($env:PSModulePath -split ';')[0]
test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1:340
- These assertions again use Windows-style
\separators, and theShould -Throw -Becausepattern is not validating the thrown error. UseJoin-Pathfor the path construction and assert-ErrorId(or-ExpectedMessage) for the throw.
Test-Path "$psModulePath\loose.psm1" | Should -BeTrue
{ Get-Module -ListAvailable -Name "$psModulePath\loose" -ErrorAction Stop } | Should -Throw -Because '*Update the Name parameter*'
{ Get-Module -ListAvailable -FullyQualifiedName "$psModulePath\loose" -ErrorAction Stop } | Should -Throw -Because '*Update the Name parameter*'
test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1:347
- Same portability + assertion issue as above: avoid
"$pwd\..."and don’t use-Becauseto try to match the error message.
Test-Path "$pwd\loose.psm1" | Should -BeTrue
{ Get-Module -ListAvailable -Name "$pwd\loose" -ErrorAction Stop } | Should -Throw -Because '*Update the Name parameter*'
{ Get-Module -ListAvailable -FullyQualifiedName "$pwd\loose" -ErrorAction Stop } | Should -Throw -Because '*Update the Name parameter*'
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+284
to
+286
| BeforeAll { | ||
| $psModulePath = ($env:PSModulePath -split ';')[0] | ||
| } |
Comment on lines
+288
to
+293
| It 'wrongly returns module information instead of $null or error for missing script module' { | ||
| $path = [System.IO.Path]::GetFullPath("$pwd\missing.psm1") | ||
| Test-Path $path | Should -BeFalse | ||
| Get-Module -ListAvailable -FullyQualifiedName $path | Should -BeOfType ([System.Management.Automation.PSModuleInfo]) | ||
| Get-Module -ListAvailable -Name $path | Should -BeOfType ([System.Management.Automation.PSModuleInfo]) | ||
| } |
Comment on lines
+302
to
+307
| It 'writes error for missing manifest module' { | ||
| $path = [System.IO.Path]::GetFullPath("$pwd\missing") | ||
| Test-Path $path | Should -BeFalse | ||
| { Get-Module -ListAvailable -FullyQualifiedName $path -ErrorAction Stop } | Should -Throw -Because '*Update the Name parameter*' | ||
| { Get-Module -ListAvailable -Name $path -ErrorAction Stop } | Should -Throw -Because '*Update the Name parameter*' | ||
| } |
Comment on lines
+323
to
+328
| $inPSModulePathLooseFilePath = Join-Path $psModulePath 'loose.psm1' | ||
| New-Item -ItemType File -Force $inPSModulePathLooseFilePath > $null | ||
| # | ||
| # Under $pwd | ||
| $inPSModulePathLooseFilePathPwd = Join-Path $pwd 'loose.psm1' | ||
| New-Item -ItemType File -Force $inPSModulePathLooseFilePathPwd > $null |
| } | ||
| } | ||
|
|
||
| Describe 'Get-Module -ListAvaiable -(FullyQualifiedName|Name) <path> when argument is absolute path' -Tags "CI" { |
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.
PR Summary
Tests for
Get-Moduleto document current behavior.Get-Module -ListAvailable -FullyQualifiedNamemodule resolution feels inconsistent #27716PR Context
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header