Skip to content
Draft
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
9 changes: 6 additions & 3 deletions src/Pester.RSpec.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ function PostProcess-RspecTestRun ($TestRun) {
$b.Result = if ($b.Skip) {
"Skipped"
}
elseif (0 -lt $b.ErrorRecord.Count) {
"Failed"
}
elseif ($b.Passed) {
"Passed"
}
Expand Down Expand Up @@ -206,12 +209,12 @@ function PostProcess-RspecTestRun ($TestRun) {
$b.result = if ($b.Skip) {
"Skipped"
}
elseif ($b.Passed) {
"Passed"
}
elseif (0 -lt $b.ErrorRecord.Count) {
"Failed"
}
elseif ($b.Passed) {
"Passed"
}
elseif (-not $discoveryOnly -and $b.ShouldRun -and (-not $b.Executed -or -not $b.Passed)) {
"Failed"
}
Expand Down
44 changes: 44 additions & 0 deletions tst/Pester.RSpec.ts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2966,4 +2966,48 @@ i -PassThru:$PassThru {
$ex.Exception.Message | Verify-Like '*Unbound scriptblock*'
}
}

# Regression test for https://github.com/pester/Pester/issues/2538
# When a container has discovery errors (e.g. syntax error in BeforeAll), the
# overall result must be Failed, not Passed. Before this fix, errors were checked
# after Passed, so a container with both Passed=true and ErrorRecord was marked Passed.
b "Discovery errors mark container as Failed" {
t "container with discovery error has result Failed" {
$sb = {
Describe 'Has discovery error' {
BeforeAll {
throw 'deliberate discovery error'
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not prove anything, before all runs during run, you need BeforeDiscovery, and in other test you need to cover a naked error without any block.

}
It 'should not run' {
$true | Should -Be $true
}
}
}

$r = Invoke-Pester -Configuration ([PesterConfiguration]@{
Run = @{ ScriptBlock = $sb; PassThru = $true }
Output = @{ Verbosity = 'None' }
})

$r.Result | Verify-Equal 'Failed'
$r.Containers[0].Result | Verify-Equal 'Failed'
}

t "container without errors still passes" {
$sb = {
Describe 'All good' {
It 'passes' {
$true | Should -Be $true
}
}
}

$r = Invoke-Pester -Configuration ([PesterConfiguration]@{
Run = @{ ScriptBlock = $sb; PassThru = $true }
Output = @{ Verbosity = 'None' }
})

$r.Result | Verify-Equal 'Passed'
}
}
}
Loading