Skip to content

Tests for Get-Module - #27790

Open
Guillermo López-Anglada (guillermooo) wants to merge 17 commits into
PowerShell:masterfrom
guillermooo:users/guillermo/feature/add-tests-get-module-paths-1-1
Open

Tests for Get-Module#27790
Guillermo López-Anglada (guillermooo) wants to merge 17 commits into
PowerShell:masterfrom
guillermooo:users/guillermo/feature/add-tests-get-module-paths-1-1

Conversation

@guillermooo

@guillermooo Guillermo López-Anglada (guillermooo) commented Aug 9, 2026

Copy link
Copy Markdown

PR Summary

Tests for Get-Module to document current behavior.

PR Context

Related (in order):

(I tried creating a stacked PR but couldn't make it work here.)

PR Checklist

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@guillermooo Guillermo López-Anglada (guillermooo) changed the title Users/guillermo/feature/add tests get module paths 1 1 Tests for Get-Module Aug 9, 2026
@guillermooo
Guillermo López-Anglada (guillermooo) marked this pull request as ready for review August 9, 2026 20:11
Copilot AI lite review requested due to automatic review settings August 9, 2026 20:11
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 Describe block covering absolute-path arguments for -FullyQualifiedName and -Name.
  • Adds cases for missing script modules vs missing manifest modules, including under $env:PSModulePath.
  • Adds coverage for “basename without extension” behavior when a .psm1 exists.
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"). Use Join-Path so 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: -Because is not an error-message matcher for Should -Throw. Use -ErrorId and build the path portably with Join-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:PSModulePath split also hard-codes ';'. Use [System.IO.Path]::PathSeparator here 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 the Should -Throw -Because pattern is not validating the thrown error. Use Join-Path for 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 -Because to 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 thread test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 Outdated
Comment thread test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 Outdated
@daxian-dbw Dongbo Wang (daxian-dbw) added the CL-Test Indicates that a PR should be marked as a test change in the Change Log label Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Test Indicates that a PR should be marked as a test change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants