From 73272905b538ce781edda438877815d83db22fcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Sun, 9 Aug 2026 15:59:10 +0200 Subject: [PATCH 01/31] Add `Describe` --- .../Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index fddd7a12ea6..25d02bdc1db 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -280,6 +280,9 @@ Describe "Get-Module -ListAvailable" -Tags "CI" { } } +Describe 'Get-Module -ListAvaiable -(FullyQualifiedName|Name) when argument is absolute path' -Tags "CI" { +} + Describe 'Get-Module -ListAvailable with path' -Tags "CI" { BeforeAll { $moduleName = 'Banana' From f542dbe7941d2176f72a12c4037df537e24c2184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Sun, 9 Aug 2026 15:59:29 +0200 Subject: [PATCH 02/31] Add `BeforeAll` --- .../Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index 25d02bdc1db..b9b27dc9a68 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -281,6 +281,9 @@ Describe "Get-Module -ListAvailable" -Tags "CI" { } Describe 'Get-Module -ListAvaiable -(FullyQualifiedName|Name) when argument is absolute path' -Tags "CI" { + BeforeAll { + $psModulePath = ($env:PSModulePath -split ';')[0] + } } Describe 'Get-Module -ListAvailable with path' -Tags "CI" { From b4f6c5c9e954684b45a03fd5bb24d3ed54ebf38f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Sun, 9 Aug 2026 15:59:39 +0200 Subject: [PATCH 03/31] Add test --- .../Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index b9b27dc9a68..1242b0796fd 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -284,6 +284,13 @@ Describe 'Get-Module -ListAvaiable -(FullyQualifiedName|Name) when argume BeforeAll { $psModulePath = ($env:PSModulePath -split ';')[0] } + + 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]) + } } Describe 'Get-Module -ListAvailable with path' -Tags "CI" { From a8390fe95601a7fe6440c8a8b4831bbd0925eaea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Sun, 9 Aug 2026 15:59:47 +0200 Subject: [PATCH 04/31] Add test --- .../Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index 1242b0796fd..20916d88d9f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -291,6 +291,13 @@ Describe 'Get-Module -ListAvaiable -(FullyQualifiedName|Name) when argume Get-Module -ListAvailable -FullyQualifiedName $path | Should -BeOfType ([System.Management.Automation.PSModuleInfo]) Get-Module -ListAvailable -Name $path | Should -BeOfType ([System.Management.Automation.PSModuleInfo]) } + + 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]) + } } Describe 'Get-Module -ListAvailable with path' -Tags "CI" { From 2eaf4399b1c6980e59f4a1e6d772e1f060af91de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Sun, 9 Aug 2026 15:59:57 +0200 Subject: [PATCH 05/31] Add test --- .../Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index 20916d88d9f..c9a23005b88 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -298,6 +298,13 @@ Describe 'Get-Module -ListAvaiable -(FullyQualifiedName|Name) when argume Get-Module -ListAvailable -FullyQualifiedName $path | Should -BeOfType ([System.Management.Automation.PSModuleInfo]) Get-Module -ListAvailable -Name $path | Should -BeOfType ([System.Management.Automation.PSModuleInfo]) } + + 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*' + } } Describe 'Get-Module -ListAvailable with path' -Tags "CI" { From e946e4d1b0c68add4dd74476728ea615fe2e7ca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Sun, 9 Aug 2026 16:00:08 +0200 Subject: [PATCH 06/31] Add test --- .../Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index c9a23005b88..50ead6d9802 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -305,6 +305,13 @@ Describe 'Get-Module -ListAvaiable -(FullyQualifiedName|Name) when argume { 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*' } + + 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*' + } } Describe 'Get-Module -ListAvailable with path' -Tags "CI" { From 8448b34f0bdbc348f6c035b2cc16829b6f291ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Sun, 9 Aug 2026 16:00:34 +0200 Subject: [PATCH 07/31] Add new `Context` --- .../Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index 50ead6d9802..cf23cbb3887 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -312,6 +312,9 @@ Describe 'Get-Module -ListAvaiable -(FullyQualifiedName|Name) when argume { 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*' } + + Context 'Locating existing script module' { + } } Describe 'Get-Module -ListAvailable with path' -Tags "CI" { From 231af68a5c6f714024bc8d886e3882eada9eafd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Sun, 9 Aug 2026 16:00:51 +0200 Subject: [PATCH 08/31] Add `BeforeAll` and `AfterAll` --- .../Get-Module.Tests.ps1 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index cf23cbb3887..068f4b1f119 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -314,6 +314,24 @@ Describe 'Get-Module -ListAvaiable -(FullyQualifiedName|Name) when argume } Context 'Locating existing script module' { + BeforeAll { + $psModulePath = ($env:PSModulePath -split ';')[0] + + # Script modules + # + # Under $env:PSModulePath. TODO: Is this a supported scenario? + $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 + } + + AfterAll { + Remove-Item $inPSModulePathLooseFilePath + Remove-Item $inPSModulePathLooseFilePathPwd + } } } From 6b75ee814cd1ec38701672d9a7b42285dd0b321c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Sun, 9 Aug 2026 16:01:03 +0200 Subject: [PATCH 09/31] Add test --- .../Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index 068f4b1f119..d69e11ddc54 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -332,6 +332,13 @@ Describe 'Get-Module -ListAvaiable -(FullyQualifiedName|Name) when argume Remove-Item $inPSModulePathLooseFilePath Remove-Item $inPSModulePathLooseFilePathPwd } + + # TODO: This looks like a bug. + It 'wrongly writes error instead of returning module information for existing script module under $env:PSModulePath using basename' { + 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*' + } } } From 2b52fb6d8e9ce2f36f1f52e2e54a32cf3a3e9e2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Sun, 9 Aug 2026 16:01:15 +0200 Subject: [PATCH 10/31] Add test --- .../Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index d69e11ddc54..598db5a504b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -339,6 +339,13 @@ Describe 'Get-Module -ListAvaiable -(FullyQualifiedName|Name) when argume { 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*' } + + # TODO: This looks like a bug. + It 'wrongly writes error instead of returning module information for existing script module using basename' { + 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*' + } } } From 6258e72179508920a2f65f28c43b4a6d0b2266b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Mon, 10 Aug 2026 06:40:33 +0200 Subject: [PATCH 11/31] Review: Avoid Windows-only convention --- .../Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index 598db5a504b..c5c0268af50 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -282,7 +282,7 @@ Describe "Get-Module -ListAvailable" -Tags "CI" { Describe 'Get-Module -ListAvaiable -(FullyQualifiedName|Name) when argument is absolute path' -Tags "CI" { BeforeAll { - $psModulePath = ($env:PSModulePath -split ';')[0] + $psModulePath = ($env:PSModulePath -split [System.IO.Path]::PathSeparator)[0] } It 'wrongly returns module information instead of $null or error for missing script module' { @@ -315,7 +315,7 @@ Describe 'Get-Module -ListAvaiable -(FullyQualifiedName|Name) when argume Context 'Locating existing script module' { BeforeAll { - $psModulePath = ($env:PSModulePath -split ';')[0] + $psModulePath = ($env:PSModulePath -split [System.IO.Path]::PathSeparator)[0] # Script modules # From 95e9342c701ebbecdfaafade2b106927c4d7b0cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Mon, 10 Aug 2026 06:46:16 +0200 Subject: [PATCH 12/31] Review: Use `Join-Path` --- .../Get-Module.Tests.ps1 | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index c5c0268af50..ebb55897926 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -286,28 +286,28 @@ Describe 'Get-Module -ListAvaiable -(FullyQualifiedName|Name) when argume } It 'wrongly returns module information instead of $null or error for missing script module' { - $path = [System.IO.Path]::GetFullPath("$pwd\missing.psm1") + $path = [System.IO.Path]::GetFullPath((Join-Path $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]) } 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") + $path = [System.IO.Path]::GetFullPath((Join-Path $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]) } It 'writes error for missing manifest module' { - $path = [System.IO.Path]::GetFullPath("$pwd\missing") + $path = [System.IO.Path]::GetFullPath((Join-Path $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*' } It 'writes error for missing manifest module under $env:PSModulePath' { - $path = [System.IO.Path]::GetFullPath("$psModulePath\missing") + $path = [System.IO.Path]::GetFullPath((Join-Path $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*' @@ -335,16 +335,16 @@ Describe 'Get-Module -ListAvaiable -(FullyQualifiedName|Name) when argume # TODO: This looks like a bug. It 'wrongly writes error instead of returning module information for existing script module under $env:PSModulePath using basename' { - 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-Path (Join-Path $psModulePath loose.psm1) | Should -BeTrue + { Get-Module -ListAvailable -Name (Join-Path $psModulePath loose) -ErrorAction Stop } | Should -Throw -Because '*Update the Name parameter*' + { Get-Module -ListAvailable -FullyQualifiedName (Join-Path $psModulePath loose) -ErrorAction Stop } | Should -Throw -Because '*Update the Name parameter*' } # TODO: This looks like a bug. It 'wrongly writes error instead of returning module information for existing script module using basename' { - 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*' + Test-Path (Join-Path $pwd loose.psm1) | Should -BeTrue + { Get-Module -ListAvailable -Name (Join-Path $pwd loose) -ErrorAction Stop } | Should -Throw -Because '*Update the Name parameter*' + { Get-Module -ListAvailable -FullyQualifiedName (Join-Path $pwd loose) -ErrorAction Stop } | Should -Throw -Because '*Update the Name parameter*' } } } From 8dbc54d802b2facd1fa605fa47701601757f414b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Mon, 10 Aug 2026 07:09:11 +0200 Subject: [PATCH 13/31] Review: Fix `Should -Throw` tests --- .../Get-Module.Tests.ps1 | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index ebb55897926..a4a823554b5 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -302,15 +302,23 @@ Describe 'Get-Module -ListAvaiable -(FullyQualifiedName|Name) when argume It 'writes error for missing manifest module' { $path = [System.IO.Path]::GetFullPath((Join-Path $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*' + + $err = { Get-Module -ListAvailable -FullyQualifiedName $path -ErrorAction Stop } | Should -Throw -PassThru + $err.Exception.Message | Should -BeLike '*Update the Name parameter*' + + $err = { Get-Module -ListAvailable -Name $path -ErrorAction Stop } | Should -Throw -PassThru + $err.Exception.Message | Should -BeLike '*Update the Name parameter*' } It 'writes error for missing manifest module under $env:PSModulePath' { $path = [System.IO.Path]::GetFullPath((Join-Path $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*' + + $err = { Get-Module -ListAvailable -FullyQualifiedName $path -ErrorAction Stop } | Should -Throw -PassThru + $err.Exception.Message | Should -BeLike '*Update the Name parameter*' + + $err = { Get-Module -ListAvailable -Name $path -ErrorAction Stop } | Should -Throw -PassThru + $err.Exception.Message | Should -BeLike '*Update the Name parameter*' } Context 'Locating existing script module' { @@ -336,15 +344,23 @@ Describe 'Get-Module -ListAvaiable -(FullyQualifiedName|Name) when argume # TODO: This looks like a bug. It 'wrongly writes error instead of returning module information for existing script module under $env:PSModulePath using basename' { Test-Path (Join-Path $psModulePath loose.psm1) | Should -BeTrue - { Get-Module -ListAvailable -Name (Join-Path $psModulePath loose) -ErrorAction Stop } | Should -Throw -Because '*Update the Name parameter*' - { Get-Module -ListAvailable -FullyQualifiedName (Join-Path $psModulePath loose) -ErrorAction Stop } | Should -Throw -Because '*Update the Name parameter*' + + $err = { Get-Module -ListAvailable -Name (Join-Path $psModulePath loose) -ErrorAction Stop } | Should -Throw -PassThru + $err.Exception.Message | Should -BeLike '*Update the Name parameter*' + + $err = { Get-Module -ListAvailable -FullyQualifiedName (Join-Path $psModulePath loose) -ErrorAction Stop } | Should -Throw -PassThru + $err.Exception.Message | Should -BeLike '*Update the Name parameter*' } # TODO: This looks like a bug. It 'wrongly writes error instead of returning module information for existing script module using basename' { Test-Path (Join-Path $pwd loose.psm1) | Should -BeTrue - { Get-Module -ListAvailable -Name (Join-Path $pwd loose) -ErrorAction Stop } | Should -Throw -Because '*Update the Name parameter*' - { Get-Module -ListAvailable -FullyQualifiedName (Join-Path $pwd loose) -ErrorAction Stop } | Should -Throw -Because '*Update the Name parameter*' + + $err = { Get-Module -ListAvailable -Name (Join-Path $pwd loose) -ErrorAction Stop } | Should -Throw -PassThru + $err.Exception.Message | Should -BeLike '*Update the Name parameter*' + + $err = { Get-Module -ListAvailable -FullyQualifiedName (Join-Path $pwd loose) -ErrorAction Stop } | Should -Throw -PassThru + $err.Exception.Message | Should -BeLike '*Update the Name parameter*' } } } From bb7d1db6d305e4b5c76adc2e8922d6ac08f867ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Mon, 10 Aug 2026 07:10:23 +0200 Subject: [PATCH 14/31] Review: Typo --- .../Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index a4a823554b5..5211077b96b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -280,7 +280,7 @@ Describe "Get-Module -ListAvailable" -Tags "CI" { } } -Describe 'Get-Module -ListAvaiable -(FullyQualifiedName|Name) when argument is absolute path' -Tags "CI" { +Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argument is absolute path' -Tags "CI" { BeforeAll { $psModulePath = ($env:PSModulePath -split [System.IO.Path]::PathSeparator)[0] } From 0b6503e61fef5d604bc6e0acb547c62438941c7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Mon, 10 Aug 2026 07:15:09 +0200 Subject: [PATCH 15/31] Review: Use dedicated $env:PSModulePath for tests --- .../Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index 5211077b96b..05c0b615702 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -282,7 +282,13 @@ Describe "Get-Module -ListAvailable" -Tags "CI" { Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argument is absolute path' -Tags "CI" { BeforeAll { - $psModulePath = ($env:PSModulePath -split [System.IO.Path]::PathSeparator)[0] + $oldPSModulePath = $env:PSModulePath + $psModulePath = New-Item -ItemType Directory (Join-Path $TestDrive modules) + $env:PSModulePath = $psModulePath + } + + AfterAll { + $env:PSModulePath = $oldPSModulePath } It 'wrongly returns module information instead of $null or error for missing script module' { From c6d6a31faf4ce0814ddf64d71f8bd29318dedf4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Mon, 10 Aug 2026 07:18:33 +0200 Subject: [PATCH 16/31] Refactor --- .../Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index 05c0b615702..2017872ba16 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -329,7 +329,7 @@ Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argum Context 'Locating existing script module' { BeforeAll { - $psModulePath = ($env:PSModulePath -split [System.IO.Path]::PathSeparator)[0] + $psModulePath = $env:PSModulePath # Script modules # From 45075a96eb1496d6af5401fb57e06f7777a24a16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Mon, 10 Aug 2026 21:58:49 +0200 Subject: [PATCH 17/31] Fix name --- .../Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index 2017872ba16..5ff8e078008 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -338,13 +338,13 @@ Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argum New-Item -ItemType File -Force $inPSModulePathLooseFilePath > $null # # Under $pwd - $inPSModulePathLooseFilePathPwd = Join-Path $pwd 'loose.psm1' - New-Item -ItemType File -Force $inPSModulePathLooseFilePathPwd > $null + $inCwdLooseFilePath = Join-Path $pwd 'loose.psm1' + New-Item -ItemType File -Force $inCwdLooseFilePath > $null } AfterAll { Remove-Item $inPSModulePathLooseFilePath - Remove-Item $inPSModulePathLooseFilePathPwd + Remove-Item $inCwdLooseFilePath } # TODO: This looks like a bug. From 0f4e5fbeefabb75e04240c5981b8637802e99f31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Tue, 11 Aug 2026 07:05:59 +0200 Subject: [PATCH 18/31] Refactor: Use single variable for the same data --- .../Get-Module.Tests.ps1 | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index 5ff8e078008..18aea8ccc16 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -283,8 +283,7 @@ Describe "Get-Module -ListAvailable" -Tags "CI" { Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argument is absolute path' -Tags "CI" { BeforeAll { $oldPSModulePath = $env:PSModulePath - $psModulePath = New-Item -ItemType Directory (Join-Path $TestDrive modules) - $env:PSModulePath = $psModulePath + $env:PSModulePath = New-Item -ItemType Directory (Join-Path $TestDrive modules) } AfterAll { @@ -299,7 +298,7 @@ Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argum } It 'wrongly returns module information instead of $null or error for missing script module under $env:PSModulePath' { - $path = [System.IO.Path]::GetFullPath((Join-Path $psModulePath missing.psm1)) + $path = [System.IO.Path]::GetFullPath((Join-Path $env: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]) @@ -317,7 +316,7 @@ Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argum } It 'writes error for missing manifest module under $env:PSModulePath' { - $path = [System.IO.Path]::GetFullPath((Join-Path $psModulePath missing)) + $path = [System.IO.Path]::GetFullPath((Join-Path $env:PSModulePath missing)) Test-Path $path | Should -BeFalse $err = { Get-Module -ListAvailable -FullyQualifiedName $path -ErrorAction Stop } | Should -Throw -PassThru @@ -329,12 +328,12 @@ Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argum Context 'Locating existing script module' { BeforeAll { - $psModulePath = $env:PSModulePath + $env:PSModulePath = $env:PSModulePath # Script modules # # Under $env:PSModulePath. TODO: Is this a supported scenario? - $inPSModulePathLooseFilePath = Join-Path $psModulePath 'loose.psm1' + $inPSModulePathLooseFilePath = Join-Path $env:PSModulePath 'loose.psm1' New-Item -ItemType File -Force $inPSModulePathLooseFilePath > $null # # Under $pwd @@ -349,12 +348,12 @@ Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argum # TODO: This looks like a bug. It 'wrongly writes error instead of returning module information for existing script module under $env:PSModulePath using basename' { - Test-Path (Join-Path $psModulePath loose.psm1) | Should -BeTrue + Test-Path (Join-Path $env:PSModulePath loose.psm1) | Should -BeTrue - $err = { Get-Module -ListAvailable -Name (Join-Path $psModulePath loose) -ErrorAction Stop } | Should -Throw -PassThru + $err = { Get-Module -ListAvailable -Name (Join-Path $env:PSModulePath loose) -ErrorAction Stop } | Should -Throw -PassThru $err.Exception.Message | Should -BeLike '*Update the Name parameter*' - $err = { Get-Module -ListAvailable -FullyQualifiedName (Join-Path $psModulePath loose) -ErrorAction Stop } | Should -Throw -PassThru + $err = { Get-Module -ListAvailable -FullyQualifiedName (Join-Path $env:PSModulePath loose) -ErrorAction Stop } | Should -Throw -PassThru $err.Exception.Message | Should -BeLike '*Update the Name parameter*' } From c56d882160b3819cbb704da71bef9b65798e9c17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Tue, 11 Aug 2026 07:06:24 +0200 Subject: [PATCH 19/31] Consistent formatting --- .../Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index 18aea8ccc16..0e519f43d64 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -293,6 +293,7 @@ Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argum It 'wrongly returns module information instead of $null or error for missing script module' { $path = [System.IO.Path]::GetFullPath((Join-Path $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]) } @@ -300,6 +301,7 @@ Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argum It 'wrongly returns module information instead of $null or error for missing script module under $env:PSModulePath' { $path = [System.IO.Path]::GetFullPath((Join-Path $env: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]) } From 8a0a003db3c3eda8e20a0cd1d227267e09b2d510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Tue, 11 Aug 2026 07:09:07 +0200 Subject: [PATCH 20/31] Refactor: Consolidate variables --- .../Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index 0e519f43d64..23947810929 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -351,22 +351,24 @@ Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argum # TODO: This looks like a bug. It 'wrongly writes error instead of returning module information for existing script module under $env:PSModulePath using basename' { Test-Path (Join-Path $env:PSModulePath loose.psm1) | Should -BeTrue + $path = Join-Path $env:PSModulePath loose - $err = { Get-Module -ListAvailable -Name (Join-Path $env:PSModulePath loose) -ErrorAction Stop } | Should -Throw -PassThru + $err = { Get-Module -ListAvailable -Name $path -ErrorAction Stop } | Should -Throw -PassThru $err.Exception.Message | Should -BeLike '*Update the Name parameter*' - $err = { Get-Module -ListAvailable -FullyQualifiedName (Join-Path $env:PSModulePath loose) -ErrorAction Stop } | Should -Throw -PassThru + $err = { Get-Module -ListAvailable -FullyQualifiedName $path -ErrorAction Stop } | Should -Throw -PassThru $err.Exception.Message | Should -BeLike '*Update the Name parameter*' } # TODO: This looks like a bug. It 'wrongly writes error instead of returning module information for existing script module using basename' { Test-Path (Join-Path $pwd loose.psm1) | Should -BeTrue + $path = Join-Path $pwd loose - $err = { Get-Module -ListAvailable -Name (Join-Path $pwd loose) -ErrorAction Stop } | Should -Throw -PassThru + $err = { Get-Module -ListAvailable -Name $path -ErrorAction Stop } | Should -Throw -PassThru $err.Exception.Message | Should -BeLike '*Update the Name parameter*' - $err = { Get-Module -ListAvailable -FullyQualifiedName (Join-Path $pwd loose) -ErrorAction Stop } | Should -Throw -PassThru + $err = { Get-Module -ListAvailable -FullyQualifiedName $path -ErrorAction Stop } | Should -Throw -PassThru $err.Exception.Message | Should -BeLike '*Update the Name parameter*' } } From c2bf6cff4d382e8b50fcf2e6a07e8100e4587020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Tue, 11 Aug 2026 07:40:58 +0200 Subject: [PATCH 21/31] Cleanup --- .../Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index 23947810929..17bc6e2526a 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -330,8 +330,6 @@ Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argum Context 'Locating existing script module' { BeforeAll { - $env:PSModulePath = $env:PSModulePath - # Script modules # # Under $env:PSModulePath. TODO: Is this a supported scenario? From 7dd54977b4a0fa611d17260b3b8142a99ba2a98f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Tue, 11 Aug 2026 07:42:39 +0200 Subject: [PATCH 22/31] Add test --- .../Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index 17bc6e2526a..9f4daa703fd 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -369,6 +369,19 @@ Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argum $err = { Get-Module -ListAvailable -FullyQualifiedName $path -ErrorAction Stop } | Should -Throw -PassThru $err.Exception.Message | Should -BeLike '*Update the Name parameter*' } + + It 'returns module information for existing script module using file name' { + $path = Join-Path $pwd loose.psm1 + Test-Path $path | Should -BeTrue + + $actual = Get-Module -ListAvailable -Name $path + $actual | Should -HaveCount 1 + $actual[0].Path | Should -BeExactly $path + + $actual = Get-Module -ListAvailable -FullyQualifiedName $path + $actual | Should -HaveCount 1 + $actual[0].Path | Should -BeExactly $path + } } } From 92c622fd5f0816b46d51ba05bb1c3ca4ee66fda5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Tue, 11 Aug 2026 07:43:09 +0200 Subject: [PATCH 23/31] Add test --- .../Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index 9f4daa703fd..ee2566e287a 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -382,6 +382,19 @@ Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argum $actual | Should -HaveCount 1 $actual[0].Path | Should -BeExactly $path } + + It 'returns module information for existing script module under $env:PSModulePath using file name' { + $path = Join-Path $env:PSModulePath loose.psm1 + Test-Path $path | Should -BeTrue + + $actual = Get-Module -ListAvailable -Name $path + $actual | Should -HaveCount 1 + $actual[0].Path | Should -BeExactly $path + + $actual = Get-Module -ListAvailable -FullyQualifiedName $path + $actual | Should -HaveCount 1 + $actual[0].Path | Should -BeExactly $path + } } } From 4087b48801de1bf9b4350ecd2e9d34f4ce8a8bad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Tue, 11 Aug 2026 07:43:26 +0200 Subject: [PATCH 24/31] Add `Context` --- .../Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index ee2566e287a..535ef997cea 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -396,6 +396,9 @@ Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argum $actual[0].Path | Should -BeExactly $path } } + + Context 'When argument contains wildcards' { + } } Describe 'Get-Module -ListAvailable with path' -Tags "CI" { From 3dbf91e4a324f036a17e9675e64c5cdfd3e631d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Tue, 11 Aug 2026 07:43:43 +0200 Subject: [PATCH 25/31] Add `BeforeAll` and `AfterAll` --- .../Get-Module.Tests.ps1 | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index 535ef997cea..7e637e01f3f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -398,6 +398,61 @@ Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argum } Context 'When argument contains wildcards' { + BeforeAll { + # Manifest modules under $env:PSModulePath + # + # Versioned, manifest + $inPSModulePathWithManifestFileName = 'existing' + $inPSModulePatWithManifestDirectory = Join-Path $env:PSModulePath $inPSModulePathWithManifestFileName '0.0.1' + $inPSModulePathWithManifestFilePath = Join-Path $inPSModulePatWithManifestDirectory "$inPSModulePathWithManifestFileName.psm1" + New-Item -ItemType File -Force $inPSModulePathWithManifestFilePath > $null + New-ModuleManifest -Path (Join-Path $inPSModulePatWithManifestDirectory "$inPSModulePathWithManifestFileName.psd1") + # + # Versioned, manifest + $inPSModulePathWithManifestFileName2 = 'existing2' + $inPSModulePatWithManifestDirectory2 = Join-Path $env:PSModulePath $inPSModulePathWithManifestFileName2 '0.0.1' + $inPSModulePathWithManifestFilePath2 = Join-Path $inPSModulePatWithManifestDirectory2 "$inPSModulePathWithManifestFileName2.psm1" + New-Item -ItemType File -Force $inPSModulePathWithManifestFilePath2 > $null + New-ModuleManifest -Path (Join-Path $inPSModulePatWithManifestDirectory2 "$inPSModulePathWithManifestFileName2.psd1") + + # Manifest modules under $pwd + # + # Versioned, manifest + $inCwdhWithManifestFileName = 'existing' + $inCwdWithManifestDirectory = Join-Path $pwd $inCwdhWithManifestFileName '0.0.1' + $inCwdWithManifestFilePath = Join-Path $inCwdWithManifestDirectory "$inCwdhWithManifestFileName.psm1" + New-Item -ItemType File -Force $inCwdWithManifestFilePath > $null + New-ModuleManifest -Path (Join-Path $inCwdWithManifestDirectory "$inCwdhWithManifestFileName.psd1") + # + # Versioned, manifest + $inCwdWithManifestFileName2 = 'existing2' + $inCwdWithManifestDirectory2 = Join-Path $pwd $inCwdWithManifestFileName2 '0.0.1' + $inCwdWithManifestFilePath2 = Join-Path $inCwdWithManifestDirectory2 "$inCwdWithManifestFileName2.psm1" + New-Item -ItemType File -Force $inCwdWithManifestFilePath2 > $null + New-ModuleManifest -Path (Join-Path $inCwdWithManifestDirectory2 "$inCwdWithManifestFileName2.psd1") + + # Script modules + # + # Under $env:PSModulePath. TODO: Is this a supported scenario? + $inPSModulePathLooseFilePath = Join-Path $env:PSModulePath 'loose.psm1' + New-Item -ItemType File -Force $inPSModulePathLooseFilePath > $null + # + # + # Under $pwd + $inCwdFilePath = Join-Path $pwd 'loose.psm1' + New-Item -ItemType File -Force $inCwdFilePath > $null + } + + AfterAll { + Remove-Item -Force -Recurse $inPSModulePatWithManifestDirectory + Remove-Item -Force -Recurse $inPSModulePatWithManifestDirectory2 + + Remove-Item -Force -Recurse $inCwdWithManifestDirectory + Remove-Item -Force -Recurse $inCwdWithManifestDirectory2 + + Remove-Item $inPSModulePathLooseFilePath + Remove-Item $inCwdFilePath + } } } From dbf05874b590a66837817808a7d52500a0e8cc82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Tue, 11 Aug 2026 07:43:49 +0200 Subject: [PATCH 26/31] Add test --- .../Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index 7e637e01f3f..9f2fe400f39 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -453,6 +453,18 @@ Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argum Remove-Item $inPSModulePathLooseFilePath Remove-Item $inCwdFilePath } + + It 'returns existing manifest modules under $env:PSModulePath when using the -Name parameter' { + $moduleManifestPath1 = Join-Path $env:PSModulePath existing 0.0.1,existing.psd1 + $moduleManifestPath2 = Join-Path $env:PSModulePath existing2 0.0.1,existing2.psd1 + Test-Path $moduleManifestPath1 | Should -BeTrue + Test-Path $moduleManifestPath2 | Should -BeTrue + + $actual = Get-Module -ListAvailable -Name (Join-Path $env:PSModulePath 'existing*') + $actual | Should -HaveCount 2 + $actual[0].Path | Should -BeExactly $moduleManifestPath1 + $actual[1].Path | Should -BeExactly $moduleManifestPath2 + } } } From 592a4a116c76815bac687837662b8b3735d3e891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Tue, 11 Aug 2026 07:43:56 +0200 Subject: [PATCH 27/31] Add test --- .../Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index 9f2fe400f39..c7046e2c4e2 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -465,6 +465,12 @@ Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argum $actual[0].Path | Should -BeExactly $moduleManifestPath1 $actual[1].Path | Should -BeExactly $moduleManifestPath2 } + + # TODO: This looks like a bug. + It 'wrongly returns $null for existing manifest modules under $env:PSModulePath when using the -FullyQualifiedName parameter' { + $actual = Get-Module -ListAvailable -FullyQualifiedName (Join-Path $env:PSModulePath 'existing*') + $actual | Should -Be $null + } } } From 11edc827f8428f8b184de74df7f0dfaf4fea70f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Tue, 11 Aug 2026 07:44:01 +0200 Subject: [PATCH 28/31] Add test --- .../Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index c7046e2c4e2..9256b428c5d 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -471,6 +471,18 @@ Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argum $actual = Get-Module -ListAvailable -FullyQualifiedName (Join-Path $env:PSModulePath 'existing*') $actual | Should -Be $null } + + It 'returns existing manifest modules when using the -Name parameter' { + $moduleManifestPath1 = Join-Path $pwd existing 0.0.1,existing.psd1 + $moduleManifestPath2 = Join-Path $pwd existing2 0.0.1,existing2.psd1 + Test-Path $moduleManifestPath1 | Should -BeTrue + Test-Path $moduleManifestPath2 | Should -BeTrue + + $actual = Get-Module -ListAvailable -Name (Join-Path $pwd 'existing*') + $actual | Should -HaveCount 2 + $actual[0].Path | Should -BeExactly $moduleManifestPath1 + $actual[1].Path | Should -BeExactly $moduleManifestPath2 + } } } From 8e822c668d833665cd17fd620ff36c72b331a051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Tue, 11 Aug 2026 07:44:08 +0200 Subject: [PATCH 29/31] Add test --- .../Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index 9256b428c5d..010ab76e0a5 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -483,6 +483,12 @@ Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argum $actual[0].Path | Should -BeExactly $moduleManifestPath1 $actual[1].Path | Should -BeExactly $moduleManifestPath2 } + + # TODO: This looks like a bug. + It 'wrongly returns $null for existing manifest modules when using the -FullyQualifiedName parameter' { + $actual = Get-Module -ListAvailable -FullyQualifiedName (Join-Path $pwd 'existing*') + $actual | Should -Be $null + } } } From f385bcddc0b988819085c7af01da539ece39bc2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Tue, 11 Aug 2026 07:44:13 +0200 Subject: [PATCH 30/31] Add test --- .../Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index 010ab76e0a5..fb3be7ed048 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -489,6 +489,12 @@ Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argum $actual = Get-Module -ListAvailable -FullyQualifiedName (Join-Path $pwd 'existing*') $actual | Should -Be $null } + + It 'returns module information for existing script module under $env:PSModulePath' { + $actual = Get-Module -ListAvailable -Name (Join-Path $env:PSModulePath 'loose*') + $actual | Should -HaveCount 1 + $actual[0].Path | Should -BeExactly (Join-Path $env:PSModulePath loose.psm1) + } } } From 5154898d2372d771e6147591adfb7738e9d30404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20L=C3=B3pez?= Date: Tue, 11 Aug 2026 07:44:18 +0200 Subject: [PATCH 31/31] Add test --- .../Microsoft.PowerShell.Core/Get-Module.Tests.ps1 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 index fb3be7ed048..72e5dd45812 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Get-Module.Tests.ps1 @@ -495,6 +495,19 @@ Describe 'Get-Module -ListAvailable -(FullyQualifiedName|Name) when argum $actual | Should -HaveCount 1 $actual[0].Path | Should -BeExactly (Join-Path $env:PSModulePath loose.psm1) } + + It 'returns module information for existing script module using file name' { + $path = Join-Path $pwd loose.psm1 + Test-Path $path | Should -BeTrue + + $actual = Get-Module -ListAvailable -Name $path + $actual | Should -HaveCount 1 + $actual[0].Path | Should -BeExactly $path + + $actual = Get-Module -ListAvailable -FullyQualifiedName $path + $actual | Should -HaveCount 1 + $actual[0].Path | Should -BeExactly $path + } } }