From c69f346d342e14cebf421febc564ff970b4431e4 Mon Sep 17 00:00:00 2001 From: MisterTriangle <134567824+MisterTriangle@users.noreply.github.com> Date: Tue, 25 Aug 2026 07:19:40 -0400 Subject: [PATCH 1/2] test: Add Clear-PSBuildOutputFolder coverage --- tests/Clear-PSBuildOutputFolder.tests.ps1 | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/Clear-PSBuildOutputFolder.tests.ps1 diff --git a/tests/Clear-PSBuildOutputFolder.tests.ps1 b/tests/Clear-PSBuildOutputFolder.tests.ps1 new file mode 100644 index 0000000..d0059d0 --- /dev/null +++ b/tests/Clear-PSBuildOutputFolder.tests.ps1 @@ -0,0 +1,22 @@ +Describe 'Clear-PSBuildOutputFolder' { + + BeforeAll { + $script:moduleRoot = Split-Path -Path $PSScriptRoot -Parent + Import-Module -Name ([IO.Path]::Combine($script:moduleRoot, 'Output', 'PowerShellBuild')) -Force + } + + It 'removes the output folder when it exists' { + $outputPath = Join-Path -Path $TestDrive -ChildPath 'Output' + New-Item -Path $outputPath -ItemType Directory -Force > $null + + Clear-PSBuildOutputFolder -Path $outputPath + + Test-Path -Path $outputPath | Should -BeFalse + } + + It 'does not throw when the output folder does not exist' { + $outputPath = Join-Path -Path $TestDrive -ChildPath 'MissingOutput' + + { Clear-PSBuildOutputFolder -Path $outputPath } | Should -Not -Throw + } +} From 1ebbaa2115f11a1a310a53e16bd53a385e5ccd44 Mon Sep 17 00:00:00 2001 From: MisterTriangle <134567824+MisterTriangle@users.noreply.github.com> Date: Wed, 26 Aug 2026 18:48:15 -0400 Subject: [PATCH 2/2] test: Cover recursive removal and path guard --- tests/Clear-PSBuildOutputFolder.tests.ps1 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/Clear-PSBuildOutputFolder.tests.ps1 b/tests/Clear-PSBuildOutputFolder.tests.ps1 index d0059d0..b7c605e 100644 --- a/tests/Clear-PSBuildOutputFolder.tests.ps1 +++ b/tests/Clear-PSBuildOutputFolder.tests.ps1 @@ -7,13 +7,24 @@ Describe 'Clear-PSBuildOutputFolder' { It 'removes the output folder when it exists' { $outputPath = Join-Path -Path $TestDrive -ChildPath 'Output' + $nestedPath = Join-Path -Path $outputPath -ChildPath 'Nested' + $nestedFilePath = Join-Path -Path $nestedPath -ChildPath 'marker.txt' New-Item -Path $outputPath -ItemType Directory -Force > $null + New-Item -Path $nestedPath -ItemType Directory -Force > $null + New-Item -Path $nestedFilePath -ItemType File -Force > $null Clear-PSBuildOutputFolder -Path $outputPath Test-Path -Path $outputPath | Should -BeFalse } + It 'refuses a path short enough to be a drive root' { + Mock -CommandName 'Test-Path' -ModuleName 'PowerShellBuild' -MockWith { $false } + + { Clear-PSBuildOutputFolder -Path 'C:\' } | + Should -Throw -ExpectedMessage '*must be longer than 3 characters.*' + } + It 'does not throw when the output folder does not exist' { $outputPath = Join-Path -Path $TestDrive -ChildPath 'MissingOutput'