Skip to content

Test-PSBuildPester coverage threshold math truncates every percentage to zero #138

Description

@tablackburn

Test-PSBuildPester computes each coverage percentage like this when building its threshold report:

$percent = [Math]::Truncate([int]$_.missed + [int]$_.covered ? ...)
$percent = [Math]::Truncate([int]$_.covered / $total)

[Math]::Truncate of a fractional value is 0, so $percent is 0 for any coverage below exactly 100%. Two user-facing consequences:

  1. The printed per-counter report always shows 0.00% (or 100.00%) regardless of real coverage
  2. The CodeCoverageThreshold comparison ($_.percent -lt $CodeCoverageThreshold) fails for any nonzero threshold unless coverage is exactly 100% — so consumers who set, say, 0.8 get a failing build even at 95% coverage

Suggested fix

Compute the ratio as a floating-point value and drop the truncation ($percent = $_.covered / $total), or round to a sensible precision. The {2:p} format string already handles percent rendering.

Notes

  • Related history: Addressing Issue #61 - update CodeCoverage Output File Format to fix error #62 fixed the coverage output path/format; Tests: Test-PSBuildPester #102 added regression tests for output path/format but not for the threshold math — the fix should come with a test-first regression test in tests/Test-PSBuildPester.tests.ps1 (a subprocess scenario with partial coverage and a threshold below it must pass; a threshold above it must fail)
  • Found while evaluating repository-side coverage tracking; the shipped coverage measurement works, it is the report/threshold arithmetic that is wrong

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions