Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Build/Tasks/Test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion Tests/Common/Help.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Tests/Private/Get-KeyedChange.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down
3 changes: 3 additions & 0 deletions Tests/Private/Get-PipelineScriptBlock.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down
3 changes: 3 additions & 0 deletions Tests/Private/Get-PipelineText.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down
3 changes: 3 additions & 0 deletions Tests/Private/Get-PropertyChange.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down
3 changes: 3 additions & 0 deletions Tests/Private/Get-UpstreamPipelineText.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down
3 changes: 3 additions & 0 deletions Tests/Private/Get-WatchedProperty.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down
3 changes: 3 additions & 0 deletions Tests/Private/Invoke-WatchedCommand.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down
3 changes: 3 additions & 0 deletions Tests/Private/New-WildcardMatcher.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down
3 changes: 3 additions & 0 deletions Tests/Private/Resolve-WatchedProperty.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down
3 changes: 3 additions & 0 deletions Tests/Private/Skip-ExcludedItem.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down
3 changes: 3 additions & 0 deletions Tests/Public/Watch-Command.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down
Loading