From 8ac8ae7000a6c6a75b2abf1897573cd1faef0f0b Mon Sep 17 00:00:00 2001 From: Mark Visschers Date: Sun, 26 Oct 2025 09:09:11 +0100 Subject: [PATCH 1/9] fixes refresh of update --- private/Update-QuickPath.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/private/Update-QuickPath.ps1 b/private/Update-QuickPath.ps1 index ed5f583..74b1ab9 100644 --- a/private/Update-QuickPath.ps1 +++ b/private/Update-QuickPath.ps1 @@ -1,7 +1,8 @@ function Update-QuickPath { try { + Remove-Module quickpath -Force -ErrorAction SilentlyContinue Update-Module -Name quickpath -Force -ErrorAction Stop - Import-Module quickpath -Force -ErrorAction Stop + Import-Module quickpath -Force -Global -ErrorAction Stop Write-Host "quickpath updated from gallery and reloaded." -ForegroundColor Green } catch { From f905a07a25f97ff1996fc370b19c939e44e18ba5 Mon Sep 17 00:00:00 2001 From: Mark Visschers Date: Sun, 26 Oct 2025 09:32:02 +0100 Subject: [PATCH 2/9] fixes refresh logic --- private/Update-QuickPath.ps1 | 69 ++++++++++++-------------------- tests/Update-QuickPath.Tests.ps1 | 23 ++++------- 2 files changed, 34 insertions(+), 58 deletions(-) diff --git a/private/Update-QuickPath.ps1 b/private/Update-QuickPath.ps1 index 74b1ab9..1d1c51e 100644 --- a/private/Update-QuickPath.ps1 +++ b/private/Update-QuickPath.ps1 @@ -1,34 +1,17 @@ function Update-QuickPath { - try { - Remove-Module quickpath -Force -ErrorAction SilentlyContinue - Update-Module -Name quickpath -Force -ErrorAction Stop - Import-Module quickpath -Force -Global -ErrorAction Stop - Write-Host "quickpath updated from gallery and reloaded." -ForegroundColor Green - } - catch { - Write-Error "Failed to update quickpath from gallery: $($_.Exception.Message)" - throw - } - # [CmdletBinding()] - # param( - # [ValidateSet('Patch', 'Minor', 'Major')] - # [string]$Increment = 'Patch', + param( + [ValidateSet('Patch', 'Minor', 'Major')] + [string]$Increment = 'Patch', + [switch]$FromGallery + ) - # [switch]$SkipTests, - - # # Force update from the PowerShell Gallery instead of local source - # [switch]$FromGallery - # ) - - # try { - # Write-Host "Updating quickpath..." -ForegroundColor Cyan - - # if ($FromGallery) { - - # Update-QuickPathFromGallery - # return - # } + Write-Host "Updating quickpath..." -ForegroundColor Cyan + if ($FromGallery) { + Update-QuickPathFromGallery + return + } + # $buildFile = Get-BuildFile # if (-not $buildFile) { @@ -55,23 +38,23 @@ function Update-QuickPath { # Write-Host "quickpath has been built, tested, and reloaded." -ForegroundColor Green # } - # catch { - # Write-Error "Failed to update quickpath: $($_.Exception.Message)" - # throw - # } + } -# function Update-QuickPathFromGallery { -# try { -# Update-Module -Name quickpath -Force -ErrorAction Stop -# Import-Module quickpath -Force -ErrorAction Stop -# Write-Host "quickpath updated from gallery and reloaded." -ForegroundColor Green -# } -# catch { -# Write-Error "Failed to update quickpath from gallery: $($_.Exception.Message)" -# throw -# } -# } +function Update-QuickPathFromGallery { + try { + if (Get-Module -Name quickpath) { + Remove-Module quickpath -Force -ErrorAction SilentlyContinue + } + Update-Module -Name quickpath -Force -ErrorAction Stop + Import-Module quickpath -Force -ErrorAction Stop + Write-Host "quickpath updated from gallery and reloaded." -ForegroundColor Green + } + catch { + Write-Error "Failed to update 'quickpath' from gallery: $($_.Exception.Message)" + throw + } +} # function Get-BuildFile { # $startPath = (Get-Location).Path diff --git a/tests/Update-QuickPath.Tests.ps1 b/tests/Update-QuickPath.Tests.ps1 index e488bc0..809dffd 100644 --- a/tests/Update-QuickPath.Tests.ps1 +++ b/tests/Update-QuickPath.Tests.ps1 @@ -3,28 +3,21 @@ Context 'Update-QuickPath' { BeforeAll { . $PSScriptRoot\..\private\Update-QuickPath.ps1 } - It 'Should call Update-Module and Import-Module' { + BeforeEach { + Mock Remove-Module Mock Update-Module Mock Import-Module - Mock Write-Host - Update-QuickPath - - Assert-MockCalled -CommandName Update-Module -Times 1 -Exactly -Scope It -ParameterFilter { - $Name -eq 'quickpath' -and $Force -eq $true -and $ErrorAction -eq 'Stop' - } - - Assert-MockCalled -CommandName Import-Module -Times 1 -Exactly -Scope It -ParameterFilter { - $Name -eq 'quickpath' -and $Force -eq $true -and $ErrorAction -eq 'Stop' - } + } + It 'Should be updated from gallery when FromGallery is set' { + Mock Update-QuickPathFromGallery + Update-QuickPath -FromGallery - Assert-MockCalled -CommandName Write-Host -Times 1 -Exactly -Scope It -ParameterFilter { - $Object -eq "quickpath updated from gallery and reloaded." -and $ForegroundColor -eq 'Green' - } + Assert-MockCalled -CommandName Update-QuickPathFromGallery -Times 1 -Exactly -Scope It } It 'Should handle errors from Update-Module' { Mock Update-Module { throw [System.Exception]::new("Update failed") } Mock Write-Error - { Update-QuickPath } | Should -Throw + { Update-QuickPath -FromGallery } | Should -Throw Assert-MockCalled -CommandName Write-Error -Times 1 -Exactly -Scope It } From cfc5a13c7007c68f98137354eb72dd0d72990794 Mon Sep 17 00:00:00 2001 From: Mark Visschers Date: Sun, 26 Oct 2025 21:41:52 +0100 Subject: [PATCH 3/9] fixes update task --- private/Get-Commands.ps1 | 2 +- private/Get-MyModuleVersion.ps1 | 40 ++++++++++++++++++++------------- private/Update-QuickPath.ps1 | 20 ++++++++++------- quickpath.build.ps1 | 12 +++++++++- quickpath.psd1 | 2 +- 5 files changed, 50 insertions(+), 26 deletions(-) diff --git a/private/Get-Commands.ps1 b/private/Get-Commands.ps1 index 590509a..3346efe 100644 --- a/private/Get-Commands.ps1 +++ b/private/Get-Commands.ps1 @@ -28,7 +28,7 @@ function Get-Commands { [Command]::new("list", { Write-Host "TODO: Output todo list" }) ) ) - [Command]::new("version", { Write-Host (Get-MyModuleVersion) }) + [Command]::new("version", "Get-MyModuleVersion" ) [Command]::new("update", "Update-QuickPath") ) } diff --git a/private/Get-MyModuleVersion.ps1 b/private/Get-MyModuleVersion.ps1 index 156c6d7..e652c9a 100644 --- a/private/Get-MyModuleVersion.ps1 +++ b/private/Get-MyModuleVersion.ps1 @@ -1,19 +1,29 @@ function Get-MyModuleVersion { - # Get all installed versions of the module - $moduleName = $MyInvocation.MyCommand.Module.Name - $modules = Get-Module -Name $moduleName -ListAvailable + try { + # Prefer the loaded module’s version + $m = Get-Module -Name quickpath -ErrorAction SilentlyContinue + if ($m) { + Write-Host $m.Version.ToString() + return + } - if ($modules) { - # Filter to only include modules from the current module path, to avoid listing multiple versions in different paths - $currentPath = (Get-Module -Name $moduleName).ModuleBase + # Fallback: use the module that defines qp (works even if imported by manifest) + $qpCmd = Get-Command -Name qp -ErrorAction SilentlyContinue + if ($qpCmd -and $qpCmd.Module) { + Write-Host $qpCmd.Module.Version.ToString() + return + } - $modules = $modules | Where-Object { $_.ModuleBase -eq $currentPath } - - # Sort by version and select the latest one - $latestModule = $modules | Sort-Object Version -Descending | Select-Object -First 1 - return $latestModule.Version - } else { - throw "Module 'YourModuleName' is not installed." + # Last resort: read from the manifest next to the module base + $moduleBase = $ExecutionContext.SessionState.Module.ModuleBase + $manifest = Join-Path $moduleBase 'quickpath.psd1' + if (Test-Path $manifest) { + $data = Test-ModuleManifest -Path $manifest -ErrorAction Stop + Write-Host $data.Version.ToString() + return + } } -} - + catch { + Write-Error "Could not determine module version: $($_.Exception.Message)" + } +} \ No newline at end of file diff --git a/private/Update-QuickPath.ps1 b/private/Update-QuickPath.ps1 index 1d1c51e..2a23090 100644 --- a/private/Update-QuickPath.ps1 +++ b/private/Update-QuickPath.ps1 @@ -1,7 +1,5 @@ function Update-QuickPath { param( - [ValidateSet('Patch', 'Minor', 'Major')] - [string]$Increment = 'Patch', [switch]$FromGallery ) @@ -12,6 +10,16 @@ function Update-QuickPath { return } + $outManifest = Join-Path (Split-Path $buildFile -Parent) 'output\quickpath\quickpath.psd1' + if (Test-Path $outManifest) { + Remove-Module quickpath -Force -ErrorAction SilentlyContinue + Import-Module $outManifest -Force -ErrorAction SilentlyContinue + } + else { + Write-Warning "Could not find built quickpath module at '$outManifest'. Please run the build script or update from gallery." + } + + Write-Host "quickpath has been built, tested, and reloaded." -ForegroundColor Green # $buildFile = Get-BuildFile # if (-not $buildFile) { @@ -31,12 +39,7 @@ function Update-QuickPath { # Invoke-Build -File $buildFile -Increment $Increment -Task $tasks # # As an extra safety, try re-importing the freshly built manifest - # $outManifest = Join-Path (Split-Path $buildFile -Parent) 'output\quickpath\quickpath.psd1' - # if (Test-Path $outManifest) { - # Import-Module $outManifest -Force -ErrorAction SilentlyContinue - # } - - # Write-Host "quickpath has been built, tested, and reloaded." -ForegroundColor Green + # } } @@ -46,6 +49,7 @@ function Update-QuickPathFromGallery { if (Get-Module -Name quickpath) { Remove-Module quickpath -Force -ErrorAction SilentlyContinue } + Remove-Module -Name quickpath -Force -ErrorAction SilentlyContinue Update-Module -Name quickpath -Force -ErrorAction Stop Import-Module quickpath -Force -ErrorAction Stop Write-Host "quickpath updated from gallery and reloaded." -ForegroundColor Green diff --git a/quickpath.build.ps1 b/quickpath.build.ps1 index 333adca..bf99dd1 100644 --- a/quickpath.build.ps1 +++ b/quickpath.build.ps1 @@ -1,8 +1,11 @@ param( - [string]$Increment = "Patch", # Can be "Patch", "Minor", or "Major" + [ValidateSet('Patch', 'Minor', 'Major')] + [string]$Increment = "Patch", [string]$Output = "Normal" ) +. $PSScriptRoot/private/Update-QuickPath.ps1 + function Update-Version { $psd1Path = 'quickpath.psd1' @@ -88,7 +91,14 @@ task Publish -Jobs Package, { task Refresh -Jobs Build, { Write-Host 'Refreshing module...' + Remove-Module quickpath -Force -ErrorAction SilentlyContinue Import-Module './output/quickpath/quickpath.psd1' -Force } +task Update -Jobs Build, Test, { + Write-Host 'Updating module...' + + Update-QuickPath +} + task . Clean, Build, Test, Package \ No newline at end of file diff --git a/quickpath.psd1 b/quickpath.psd1 index e14ba28..29f4ec1 100644 --- a/quickpath.psd1 +++ b/quickpath.psd1 @@ -12,7 +12,7 @@ RootModule = 'quickpath.psm1' # Version number of this module. - ModuleVersion = '0.14.3' + ModuleVersion = '0.16.14' # ID used to uniquely identify this module GUID = '376719b2-2cdd-47e8-b82b-b01870c08ac8' From 9123b8d93ee9016492554f04c4248891bfadca16 Mon Sep 17 00:00:00 2001 From: Mark Visschers Date: Mon, 27 Oct 2025 01:50:51 +0100 Subject: [PATCH 4/9] fixes quickpath update --- private/Update-QuickPath.ps1 | 79 ++++++++++-------------------------- quickpath.psd1 | 2 +- 2 files changed, 22 insertions(+), 59 deletions(-) diff --git a/private/Update-QuickPath.ps1 b/private/Update-QuickPath.ps1 index 2a23090..36573b1 100644 --- a/private/Update-QuickPath.ps1 +++ b/private/Update-QuickPath.ps1 @@ -10,46 +10,14 @@ function Update-QuickPath { return } - $outManifest = Join-Path (Split-Path $buildFile -Parent) 'output\quickpath\quickpath.psd1' - if (Test-Path $outManifest) { - Remove-Module quickpath -Force -ErrorAction SilentlyContinue - Import-Module $outManifest -Force -ErrorAction SilentlyContinue - } - else { - Write-Warning "Could not find built quickpath module at '$outManifest'. Please run the build script or update from gallery." - } - - Write-Host "quickpath has been built, tested, and reloaded." -ForegroundColor Green - # $buildFile = Get-BuildFile - - # if (-not $buildFile) { - # Write-Verbose "Build script not found near '$startPath'; falling back to gallery update." - # Update-QuickPathFromGallery - # return - # } - - # ValidateOrInstallTools - - # # Build argument list for Invoke-Build - # $tasks = @() - # if (-not $SkipTests) { $tasks += 'Test' } - # $tasks += 'Refresh' - - # # Execute build in the current session so Import-Module in Refresh affects this session - # Invoke-Build -File $buildFile -Increment $Increment -Task $tasks - - # # As an extra safety, try re-importing the freshly built manifest - - # } - + Update-QuickPathFromBuild } function Update-QuickPathFromGallery { try { - if (Get-Module -Name quickpath) { + if (Get-Module quickpath) { Remove-Module quickpath -Force -ErrorAction SilentlyContinue } - Remove-Module -Name quickpath -Force -ErrorAction SilentlyContinue Update-Module -Name quickpath -Force -ErrorAction Stop Import-Module quickpath -Force -ErrorAction Stop Write-Host "quickpath updated from gallery and reloaded." -ForegroundColor Green @@ -60,28 +28,23 @@ function Update-QuickPathFromGallery { } } -# function Get-BuildFile { -# $startPath = (Get-Location).Path -# $dir = $startPath -# $buildFile = $null -# for ($i = 0; $i -lt 6; $i++) { -# $candidate = Join-Path $dir 'quickpath.build.ps1' -# if (Test-Path $candidate) { $buildFile = $candidate; break } -# $parent = Split-Path $dir -Parent -# if ([string]::IsNullOrEmpty($parent) -or $parent -eq $dir) { break } -# $dir = $parent -# } -# return $buildFile -# } +function Update-QuickPathFromBuild { + try { + $quickPathManifest = Join-Path -Path $PSScriptRoot -ChildPath "..\output\quickpath\quickpath.psd1" + if ( -not (Test-Path $quickPathManifest)) { + Write-Warning "Built quickpath module not found at '$quickPathManifest'. Please run 'Invoke-Build Build' first." + return + } -# function ValidateOrInstallTools { -# # Ensure required tools are available -# if (-not (Get-Module -ListAvailable -Name InvokeBuild)) { -# Write-Verbose "Installing InvokeBuild..." -# Install-Module -Name InvokeBuild -Scope CurrentUser -Force -ErrorAction Stop -# } -# if (-not (Get-Module -ListAvailable -Name Pester)) { -# Write-Verbose "Installing Pester..." -# Install-Module -Name Pester -Scope CurrentUser -Force -ErrorAction Stop -# } -# } \ No newline at end of file + if (Get-Module quickpath) { + Remove-Module quickpath -Force -ErrorAction SilentlyContinue + } + + Import-Module $quickPathManifest -Force -ErrorAction Stop + Write-Host "quickpath has been built, tested, and reloaded." -ForegroundColor Green + } + catch { + Write-Error "An error occurred while updating from build: $($_.Exception.Message)" + throw + } +} diff --git a/quickpath.psd1 b/quickpath.psd1 index 29f4ec1..b748116 100644 --- a/quickpath.psd1 +++ b/quickpath.psd1 @@ -12,7 +12,7 @@ RootModule = 'quickpath.psm1' # Version number of this module. - ModuleVersion = '0.16.14' + ModuleVersion = '0.16.19' # ID used to uniquely identify this module GUID = '376719b2-2cdd-47e8-b82b-b01870c08ac8' From 0f33b8ed273c01a2fa9eda4af21591bca20a63cd Mon Sep 17 00:00:00 2001 From: Mark Visschers Date: Mon, 27 Oct 2025 01:55:07 +0100 Subject: [PATCH 5/9] fixes module name usage --- private/Update-QuickPath.ps1 | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/private/Update-QuickPath.ps1 b/private/Update-QuickPath.ps1 index 36573b1..79071ee 100644 --- a/private/Update-QuickPath.ps1 +++ b/private/Update-QuickPath.ps1 @@ -15,33 +15,35 @@ function Update-QuickPath { function Update-QuickPathFromGallery { try { - if (Get-Module quickpath) { - Remove-Module quickpath -Force -ErrorAction SilentlyContinue + $moduleName = $MyInvocation.MyCommand.Module.Name + if (Get-Module $moduleName) { + Remove-Module $moduleName -Force -ErrorAction SilentlyContinue } - Update-Module -Name quickpath -Force -ErrorAction Stop - Import-Module quickpath -Force -ErrorAction Stop - Write-Host "quickpath updated from gallery and reloaded." -ForegroundColor Green + Update-Module -Name $moduleName -Force -ErrorAction Stop + Import-Module $moduleName -Force -ErrorAction Stop + Write-Host "$moduleName updated from gallery and reloaded." -ForegroundColor Green } catch { - Write-Error "Failed to update 'quickpath' from gallery: $($_.Exception.Message)" + Write-Error "Failed to update '$moduleName' from gallery: $($_.Exception.Message)" throw } } function Update-QuickPathFromBuild { try { + $moduleName = $MyInvocation.MyCommand.Module.Name $quickPathManifest = Join-Path -Path $PSScriptRoot -ChildPath "..\output\quickpath\quickpath.psd1" if ( -not (Test-Path $quickPathManifest)) { Write-Warning "Built quickpath module not found at '$quickPathManifest'. Please run 'Invoke-Build Build' first." return } - if (Get-Module quickpath) { - Remove-Module quickpath -Force -ErrorAction SilentlyContinue + if (Get-Module $moduleName) { + Remove-Module $moduleName -Force -ErrorAction SilentlyContinue } Import-Module $quickPathManifest -Force -ErrorAction Stop - Write-Host "quickpath has been built, tested, and reloaded." -ForegroundColor Green + Write-Host "$moduleName has been built, tested, and reloaded." -ForegroundColor Green } catch { Write-Error "An error occurred while updating from build: $($_.Exception.Message)" From ea4f8de5f24071753a82b7831c6c3660b00c05a6 Mon Sep 17 00:00:00 2001 From: Mark Visschers Date: Mon, 27 Oct 2025 02:26:31 +0100 Subject: [PATCH 6/9] adds tests for Get-MyModuleVersion function --- private/Get-Commands.ps1 | 2 +- private/Get-MyModuleVersion.ps1 | 58 ++++++++++++++++++-------- tests/Get-ModuleVersion.Tests.ps1 | 68 +++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 18 deletions(-) create mode 100644 tests/Get-ModuleVersion.Tests.ps1 diff --git a/private/Get-Commands.ps1 b/private/Get-Commands.ps1 index 3346efe..38b7e21 100644 --- a/private/Get-Commands.ps1 +++ b/private/Get-Commands.ps1 @@ -28,7 +28,7 @@ function Get-Commands { [Command]::new("list", { Write-Host "TODO: Output todo list" }) ) ) - [Command]::new("version", "Get-MyModuleVersion" ) + [Command]::new("version", { Write-Host (Get-MyModuleVersion) } ) [Command]::new("update", "Update-QuickPath") ) } diff --git a/private/Get-MyModuleVersion.ps1 b/private/Get-MyModuleVersion.ps1 index e652c9a..b432c63 100644 --- a/private/Get-MyModuleVersion.ps1 +++ b/private/Get-MyModuleVersion.ps1 @@ -1,29 +1,53 @@ function Get-MyModuleVersion { try { - # Prefer the loaded module’s version - $m = Get-Module -Name quickpath -ErrorAction SilentlyContinue - if ($m) { - Write-Host $m.Version.ToString() - return + $moduleName = "quickpath" + $commandName = "qp" + + $module = Get-Module -Name $moduleName -ErrorAction SilentlyContinue + if ($module) { + return $module.Version } - # Fallback: use the module that defines qp (works even if imported by manifest) - $qpCmd = Get-Command -Name qp -ErrorAction SilentlyContinue - if ($qpCmd -and $qpCmd.Module) { - Write-Host $qpCmd.Module.Version.ToString() - return + $module = Get-ModuleFromCommand($commandName) + if ($module) { + return $module.Version } - # Last resort: read from the manifest next to the module base - $moduleBase = $ExecutionContext.SessionState.Module.ModuleBase - $manifest = Join-Path $moduleBase 'quickpath.psd1' - if (Test-Path $manifest) { - $data = Test-ModuleManifest -Path $manifest -ErrorAction Stop - Write-Host $data.Version.ToString() - return + $module = Get-ModuleFromManifest($moduleName) + if ($module) { + return $module.Version } } catch { Write-Error "Could not determine module version: $($_.Exception.Message)" } + + Write-Error "Module version could not be found." +} + +function Get-ModuleFromCommand { + param ( + [string]$commandName + ) + + $qpCommand = Get-Command -Name $commandName -ErrorAction SilentlyContinue + if ($qpCommand -and $qpCommand.Module) { + return $qpCommand.Module + } + + return $null +} + +function Get-ModuleFromManifest { + param( + [string]$moduleName = "quickpath" + ) + $manifest = "$PSScriptRoot\..\output\$moduleName\$moduleName.psd1" + + if (Test-Path $manifest) { + $data = Test-ModuleManifest -Path $manifest -ErrorAction Stop + return $data + } + + return $null } \ No newline at end of file diff --git a/tests/Get-ModuleVersion.Tests.ps1 b/tests/Get-ModuleVersion.Tests.ps1 new file mode 100644 index 0000000..07d1230 --- /dev/null +++ b/tests/Get-ModuleVersion.Tests.ps1 @@ -0,0 +1,68 @@ +Describe "Get-ModuleVersion" { + BeforeAll { + . $PSScriptRoot\..\private\Get-MyModuleVersion.ps1 + } + It "Get Loaded Module version" { + $expectedVersion = "1.2.3" + Mock Get-Module { + [PSCustomObject]@{ + Version = [version]$expectedVersion + } + } + + $actualVersion = Get-MyModuleVersion + + $actualVersion | Should -Be $expectedVersion + } + It "Get Module version from command" { + $expectedVersion = "2.3.4" + Mock Get-Module { + return $null + } + Mock Get-Command { + [PSCustomObject]@{ + Module = [PSCustomObject]@{ + Version = [version]$expectedVersion + } + } + } + + $actualVersion = Get-MyModuleVersion + + $actualVersion | Should -Be $expectedVersion + } + It "Get Module version from manifest" { + $expectedVersion = "3.4.5" + Mock Get-Module { + return $null + } + Mock Get-Command { + return $null + } + Mock Test-ModuleManifest { + [PSCustomObject]@{ + Version = [version]$expectedVersion + } + } + + $actualVersion = Get-MyModuleVersion + + $actualVersion | Should -Be $expectedVersion + } + It 'Failed to find module version, writes error' { + Mock Get-Module { + return $null + } + Mock Get-Command { + return $null + } + Mock Test-ModuleManifest { + return $null + } + Mock Write-Error {} + + Get-MyModuleVersion + + Assert-MockCalled Write-Error -Exactly 1 + } +} \ No newline at end of file From 3f64dd9da61b44be6e1d448d0500bcbd5fb0cf12 Mon Sep 17 00:00:00 2001 From: Mark Visschers Date: Mon, 27 Oct 2025 02:26:47 +0100 Subject: [PATCH 7/9] fixes name for update --- private/Update-QuickPath.ps1 | 4 ++-- quickpath.psd1 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/private/Update-QuickPath.ps1 b/private/Update-QuickPath.ps1 index 79071ee..8ff28bb 100644 --- a/private/Update-QuickPath.ps1 +++ b/private/Update-QuickPath.ps1 @@ -15,7 +15,7 @@ function Update-QuickPath { function Update-QuickPathFromGallery { try { - $moduleName = $MyInvocation.MyCommand.Module.Name + $moduleName = "quickpath" if (Get-Module $moduleName) { Remove-Module $moduleName -Force -ErrorAction SilentlyContinue } @@ -31,7 +31,7 @@ function Update-QuickPathFromGallery { function Update-QuickPathFromBuild { try { - $moduleName = $MyInvocation.MyCommand.Module.Name + $moduleName = "quickpath" $quickPathManifest = Join-Path -Path $PSScriptRoot -ChildPath "..\output\quickpath\quickpath.psd1" if ( -not (Test-Path $quickPathManifest)) { Write-Warning "Built quickpath module not found at '$quickPathManifest'. Please run 'Invoke-Build Build' first." diff --git a/quickpath.psd1 b/quickpath.psd1 index b748116..e2df229 100644 --- a/quickpath.psd1 +++ b/quickpath.psd1 @@ -12,7 +12,7 @@ RootModule = 'quickpath.psm1' # Version number of this module. - ModuleVersion = '0.16.19' + ModuleVersion = '0.16.28' # ID used to uniquely identify this module GUID = '376719b2-2cdd-47e8-b82b-b01870c08ac8' From de16fa4a567caa3477348d4aa5619961ae299f88 Mon Sep 17 00:00:00 2001 From: Mark Visschers Date: Mon, 27 Oct 2025 02:35:22 +0100 Subject: [PATCH 8/9] adds exception tests --- private/Get-MyModuleVersion.ps1 | 3 +-- tests/Get-ModuleVersion.Tests.ps1 | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/private/Get-MyModuleVersion.ps1 b/private/Get-MyModuleVersion.ps1 index b432c63..f7ecf8a 100644 --- a/private/Get-MyModuleVersion.ps1 +++ b/private/Get-MyModuleVersion.ps1 @@ -17,12 +17,11 @@ function Get-MyModuleVersion { if ($module) { return $module.Version } + Write-Error "Module version could not be found." } catch { Write-Error "Could not determine module version: $($_.Exception.Message)" } - - Write-Error "Module version could not be found." } function Get-ModuleFromCommand { diff --git a/tests/Get-ModuleVersion.Tests.ps1 b/tests/Get-ModuleVersion.Tests.ps1 index 07d1230..fa29669 100644 --- a/tests/Get-ModuleVersion.Tests.ps1 +++ b/tests/Get-ModuleVersion.Tests.ps1 @@ -56,8 +56,18 @@ Describe "Get-ModuleVersion" { Mock Get-Command { return $null } - Mock Test-ModuleManifest { - return $null + Mock Test-Path { + return $false + } + Mock Write-Error {} + + Get-MyModuleVersion + + Assert-MockCalled Write-Error -Exactly 1 + } + It 'Catches exception and writes error' { + Mock Get-Module { + throw "Some error" } Mock Write-Error {} From 2a344a5421e79392dfe2a54b6c74e472b6d11369 Mon Sep 17 00:00:00 2001 From: Mark Visschers Date: Mon, 27 Oct 2025 02:40:00 +0100 Subject: [PATCH 9/9] adds tests for update script --- tests/Update-QuickPath.Tests.ps1 | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/Update-QuickPath.Tests.ps1 b/tests/Update-QuickPath.Tests.ps1 index 809dffd..4057d81 100644 --- a/tests/Update-QuickPath.Tests.ps1 +++ b/tests/Update-QuickPath.Tests.ps1 @@ -21,4 +21,38 @@ Context 'Update-QuickPath' { Assert-MockCalled -CommandName Write-Error -Times 1 -Exactly -Scope It } + It 'Should be updated from build when FromGallery is not set' { + Mock Update-QuickPathFromBuild + Update-QuickPath + + Assert-MockCalled -CommandName Update-QuickPathFromBuild -Times 1 -Exactly -Scope It + } + It 'Should handle missing built module in Update-QuickPathFromBuild' { + Mock Test-Path { $false } + Mock Write-Warning + Update-QuickPathFromBuild + + Assert-MockCalled -CommandName Write-Warning -Times 1 -Exactly -Scope It + } + It 'Should handle errors during build update' { + Mock Test-Path { $true } + Mock Import-Module { throw [System.Exception]::new("Import failed") } + Mock Write-Error + { Update-QuickPathFromBuild } | Should -Throw + + Assert-MockCalled -CommandName Write-Error -Times 1 -Exactly -Scope It + } + It 'Should remove existing module before updating from gallery' { + Mock Get-Module { @{ Name = "quickpath" } } + Update-QuickPath -FromGallery + + Assert-MockCalled -CommandName Remove-Module -ParameterFilter { $Name -eq "quickpath" } -Times 1 -Exactly -Scope It + } + It 'Should remove existing module before updating from build' { + Mock Get-Module { @{ Name = "quickpath" } } + Mock Test-Path { $true } + Update-QuickPathFromBuild + + Assert-MockCalled -CommandName Remove-Module -ParameterFilter { $Name -eq "quickpath" } -Times 1 -Exactly -Scope It + } }