Skip to content

Commit 2de7450

Browse files
tablackburnclaude
andcommitted
fix(build): count passed and failed, not merely discovered, tests
Follow-up to the previous gate, which used TotalCount minus NotRunCount. That misses a suite where every test is skipped: skipped tests are neither NotRun nor executed-with-a-result, so the subtraction stays positive and the build passes having run nothing. Measured against Pester 6.1.0: empty test directory Total 0 Passed 0 Failed 0 Skipped 0 NotRun 0 filter matching no test Total 120 Passed 0 Failed 0 Skipped 0 NotRun 120 every test -Skip Total 3 Passed 0 Failed 0 Skipped 3 NotRun 0 Filtering on the per-test .Executed property does not distinguish the third case either -- skipped tests report Executed = $true. Only PassedCount plus FailedCount separates a suite that ran from one that did not, so the gate uses that. Verified all three: all-skipped exits 1, empty directory exits 1, and a normal run with two legitimate skips reports 118 passed and exits 0. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G1CarQG8VibNFxw4cN53Zs
1 parent a8a298b commit 2de7450

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

build.psake.ps1

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,21 @@ Task -Name 'UnitTest' -Depends 'Build' -PreCondition $unitTestPreReqs -Descripti
256256
#
257257
# Test.Enabled is the deliberate opt-out and is handled in the PreCondition;
258258
# reaching here having run nothing is a fault either way.
259-
# Cast before subtracting: when nothing is discovered at all these counts come
260-
# back null, and null arithmetic would otherwise leave the message blank.
261-
$discoveredCount = [int]$testResult.TotalCount
262-
$notRunCount = [int]$testResult.NotRunCount
263-
if (($discoveredCount - $notRunCount) -le 0) {
264-
throw "Pester executed no tests under [$($PSBPreference.Test.RootDir)] (discovered $discoveredCount, not run $notRunCount). Refusing to report success without running tests."
259+
# Count tests that actually produced a result. Measured against Pester 6.1.0,
260+
# three ways to reach "nothing ran" that every failure count reads as success:
261+
#
262+
# empty test directory -> Total 0, Passed 0, Failed 0, Skipped 0, NotRun 0
263+
# filter matching no test -> Total 120, Passed 0, Failed 0, Skipped 0, NotRun 120
264+
# every test -Skip -> Total 3, Passed 0, Failed 0, Skipped 3, NotRun 0
265+
#
266+
# TotalCount minus NotRunCount misses the third, and so does filtering on the
267+
# per-test .Executed property -- skipped tests report Executed = $true. Only
268+
# passed-plus-failed distinguishes a suite that ran from one that did not.
269+
# Casts are deliberate: with nothing discovered these come back null.
270+
$ranCount = [int]$testResult.PassedCount + [int]$testResult.FailedCount
271+
if ($ranCount -le 0) {
272+
$counts = "discovered $([int]$testResult.TotalCount), skipped $([int]$testResult.SkippedCount), not run $([int]$testResult.NotRunCount)"
273+
throw "Pester ran no tests under [$($PSBPreference.Test.RootDir)] ($counts). Refusing to report success without running tests."
265274
}
266275
}
267276
finally {

0 commit comments

Comments
 (0)