diff --git a/Build/Tasks/Test.ps1 b/Build/Tasks/Test.ps1 index d5bc29b..e0434e2 100644 --- a/Build/Tasks/Test.ps1 +++ b/Build/Tasks/Test.ps1 @@ -27,6 +27,12 @@ Task 'Test' -Depends 'ImportStagingModule' { throw "Failed '$($TestResults.FailedCount)' tests, build failed" } + # Also fail if a test file or block failed outside a test (e.g. during Discovery). Those tests never run, + # so FailedCount misses them and the only symptom would otherwise be a collapsed coverage figure. + if ($TestResults.FailedContainersCount -gt 0 -or $TestResults.FailedBlocksCount -gt 0) { + throw "Failed '$($TestResults.FailedContainersCount)' test files and '$($TestResults.FailedBlocksCount)' blocks, build failed" + } + # Surface the coverage result as a pipeline output variable so a later stage (which runs in a # separate, discarded workspace) can apply it to README.md without re-running the tests. if ($env:GITHUB_OUTPUT) { diff --git a/Tests/Common/Help.Tests.ps1 b/Tests/Common/Help.Tests.ps1 index 9002c2c..1a1d8f2 100644 --- a/Tests/Common/Help.Tests.ps1 +++ b/Tests/Common/Help.Tests.ps1 @@ -11,7 +11,8 @@ if (-not $env:BHModulePath) { $env:BHModulePath = Join-Path $env:BHProjectPath $ if (-not $env:BHPSModuleManifest) { $env:BHPSModuleManifest = Join-Path $env:BHModulePath "$env:BHProjectName.psd1" } # Import module -if (-not (Get-Module -Name $env:BHProjectName -ListAvailable)) { +# Reuse the module if it's already loaded (e.g. the staged build), as re-importing it fails on Windows PowerShell 5.1. +if (-not (Get-Module -Name $env:BHProjectName)) { Import-Module -Name $env:BHPSModuleManifest -ErrorAction 'Stop' -Force } $commands = Get-Command -Module $env:BHProjectName -CommandType Cmdlet, Function -ErrorAction 'Stop' # Not alias diff --git a/Tests/Private/Get-KeyedChange.Tests.ps1 b/Tests/Private/Get-KeyedChange.Tests.ps1 index 3be1023..6184682 100644 --- a/Tests/Private/Get-KeyedChange.Tests.ps1 +++ b/Tests/Private/Get-KeyedChange.Tests.ps1 @@ -1,5 +1,8 @@ $PSVersion = $PSVersionTable.PSVersion.Major +# Remove any copy already loaded (e.g. the staged build) first: Windows PowerShell 5.1 can't re-import +# Watch.types.ps1xml over an existing one ("The member ToString is already present"), which fails Discovery. +Get-Module Watch | Remove-Module -Force Import-Module "$PSScriptRoot/../../Watch" -Force Describe "Get-KeyedChange PS$PSVersion" { diff --git a/Tests/Private/Get-PipelineScriptBlock.Tests.ps1 b/Tests/Private/Get-PipelineScriptBlock.Tests.ps1 index 6a74df5..c2c8ecf 100644 --- a/Tests/Private/Get-PipelineScriptBlock.Tests.ps1 +++ b/Tests/Private/Get-PipelineScriptBlock.Tests.ps1 @@ -1,5 +1,8 @@ $PSVersion = $PSVersionTable.PSVersion.Major +# Remove any copy already loaded (e.g. the staged build) first: Windows PowerShell 5.1 can't re-import +# Watch.types.ps1xml over an existing one ("The member ToString is already present"), which fails Discovery. +Get-Module Watch | Remove-Module -Force Import-Module "$PSScriptRoot/../../Watch" -Force Describe "Get-PipelineScriptBlock PS$PSVersion" { diff --git a/Tests/Private/Get-PipelineText.Tests.ps1 b/Tests/Private/Get-PipelineText.Tests.ps1 index 32b8988..35896f0 100644 --- a/Tests/Private/Get-PipelineText.Tests.ps1 +++ b/Tests/Private/Get-PipelineText.Tests.ps1 @@ -1,5 +1,8 @@ $PSVersion = $PSVersionTable.PSVersion.Major +# Remove any copy already loaded (e.g. the staged build) first: Windows PowerShell 5.1 can't re-import +# Watch.types.ps1xml over an existing one ("The member ToString is already present"), which fails Discovery. +Get-Module Watch | Remove-Module -Force Import-Module "$PSScriptRoot/../../Watch" -Force Describe "Get-PipelineText PS$PSVersion" { diff --git a/Tests/Private/Get-PropertyChange.Tests.ps1 b/Tests/Private/Get-PropertyChange.Tests.ps1 index f34aa3e..d0fc145 100644 --- a/Tests/Private/Get-PropertyChange.Tests.ps1 +++ b/Tests/Private/Get-PropertyChange.Tests.ps1 @@ -1,5 +1,8 @@ $PSVersion = $PSVersionTable.PSVersion.Major +# Remove any copy already loaded (e.g. the staged build) first: Windows PowerShell 5.1 can't re-import +# Watch.types.ps1xml over an existing one ("The member ToString is already present"), which fails Discovery. +Get-Module Watch | Remove-Module -Force Import-Module "$PSScriptRoot/../../Watch" -Force Describe "Get-PropertyChange PS$PSVersion" { diff --git a/Tests/Private/Get-UpstreamPipelineText.Tests.ps1 b/Tests/Private/Get-UpstreamPipelineText.Tests.ps1 index c9996e3..e2cae1b 100644 --- a/Tests/Private/Get-UpstreamPipelineText.Tests.ps1 +++ b/Tests/Private/Get-UpstreamPipelineText.Tests.ps1 @@ -1,5 +1,8 @@ $PSVersion = $PSVersionTable.PSVersion.Major +# Remove any copy already loaded (e.g. the staged build) first: Windows PowerShell 5.1 can't re-import +# Watch.types.ps1xml over an existing one ("The member ToString is already present"), which fails Discovery. +Get-Module Watch | Remove-Module -Force Import-Module "$PSScriptRoot/../../Watch" -Force Describe "Get-UpstreamPipelineText PS$PSVersion" { diff --git a/Tests/Private/Get-WatchedProperty.Tests.ps1 b/Tests/Private/Get-WatchedProperty.Tests.ps1 index 22f113c..8bc70fe 100644 --- a/Tests/Private/Get-WatchedProperty.Tests.ps1 +++ b/Tests/Private/Get-WatchedProperty.Tests.ps1 @@ -1,5 +1,8 @@ $PSVersion = $PSVersionTable.PSVersion.Major +# Remove any copy already loaded (e.g. the staged build) first: Windows PowerShell 5.1 can't re-import +# Watch.types.ps1xml over an existing one ("The member ToString is already present"), which fails Discovery. +Get-Module Watch | Remove-Module -Force Import-Module "$PSScriptRoot/../../Watch" -Force Describe "Get-WatchedProperty PS$PSVersion" { diff --git a/Tests/Private/Invoke-WatchedCommand.Tests.ps1 b/Tests/Private/Invoke-WatchedCommand.Tests.ps1 index da5abd7..fc315d7 100644 --- a/Tests/Private/Invoke-WatchedCommand.Tests.ps1 +++ b/Tests/Private/Invoke-WatchedCommand.Tests.ps1 @@ -1,5 +1,8 @@ $PSVersion = $PSVersionTable.PSVersion.Major +# Remove any copy already loaded (e.g. the staged build) first: Windows PowerShell 5.1 can't re-import +# Watch.types.ps1xml over an existing one ("The member ToString is already present"), which fails Discovery. +Get-Module Watch | Remove-Module -Force Import-Module "$PSScriptRoot/../../Watch" -Force Describe "Invoke-WatchedCommand PS$PSVersion" { diff --git a/Tests/Private/New-WildcardMatcher.Tests.ps1 b/Tests/Private/New-WildcardMatcher.Tests.ps1 index 4e6e5ec..1c994b6 100644 --- a/Tests/Private/New-WildcardMatcher.Tests.ps1 +++ b/Tests/Private/New-WildcardMatcher.Tests.ps1 @@ -1,5 +1,8 @@ $PSVersion = $PSVersionTable.PSVersion.Major +# Remove any copy already loaded (e.g. the staged build) first: Windows PowerShell 5.1 can't re-import +# Watch.types.ps1xml over an existing one ("The member ToString is already present"), which fails Discovery. +Get-Module Watch | Remove-Module -Force Import-Module "$PSScriptRoot/../../Watch" -Force Describe "New-WildcardMatcher PS$PSVersion" { diff --git a/Tests/Private/Resolve-WatchedProperty.Tests.ps1 b/Tests/Private/Resolve-WatchedProperty.Tests.ps1 index cd6cc25..6103ed6 100644 --- a/Tests/Private/Resolve-WatchedProperty.Tests.ps1 +++ b/Tests/Private/Resolve-WatchedProperty.Tests.ps1 @@ -1,5 +1,8 @@ $PSVersion = $PSVersionTable.PSVersion.Major +# Remove any copy already loaded (e.g. the staged build) first: Windows PowerShell 5.1 can't re-import +# Watch.types.ps1xml over an existing one ("The member ToString is already present"), which fails Discovery. +Get-Module Watch | Remove-Module -Force Import-Module "$PSScriptRoot/../../Watch" -Force Describe "Resolve-WatchedProperty PS$PSVersion" { diff --git a/Tests/Private/Skip-ExcludedItem.Tests.ps1 b/Tests/Private/Skip-ExcludedItem.Tests.ps1 index da65717..a926e25 100644 --- a/Tests/Private/Skip-ExcludedItem.Tests.ps1 +++ b/Tests/Private/Skip-ExcludedItem.Tests.ps1 @@ -1,5 +1,8 @@ $PSVersion = $PSVersionTable.PSVersion.Major +# Remove any copy already loaded (e.g. the staged build) first: Windows PowerShell 5.1 can't re-import +# Watch.types.ps1xml over an existing one ("The member ToString is already present"), which fails Discovery. +Get-Module Watch | Remove-Module -Force Import-Module "$PSScriptRoot/../../Watch" -Force Describe "Skip-ExcludedItem PS$PSVersion" { diff --git a/Tests/Public/Watch-Command.Tests.ps1 b/Tests/Public/Watch-Command.Tests.ps1 index 64ca186..a6edcbd 100644 --- a/Tests/Public/Watch-Command.Tests.ps1 +++ b/Tests/Public/Watch-Command.Tests.ps1 @@ -1,5 +1,8 @@ $PSVersion = $PSVersionTable.PSVersion.Major +# Remove any copy already loaded (e.g. the staged build) first: Windows PowerShell 5.1 can't re-import +# Watch.types.ps1xml over an existing one ("The member ToString is already present"), which fails Discovery. +Get-Module Watch | Remove-Module -Force Import-Module "$PSScriptRoot/../../Watch" -Force Describe "Watch-Command PS$PSVersion" {