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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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 #