Skip to content

CodeCoverageThreshold still gates every JaCoCo report counter (CLASS/METHOD/INSTRUCTION/LINE), so a realistic module cannot scope a line-coverage gate #231

Open

Description

@tablackburn

Follow-up to the resolved #138 (truncation fixed on main by #165). The remaining half of the threshold-gate problem is still present at HEAD (main @ 3ea9e82): the gate compares EVERY report-level JaCoCo counter against the single CodeCoverageThreshold value.

PowerShellBuild/Public/Test-PSBuildPester.ps1, lines 125-145 (current main):

$ccReport = $testCoverage.report.counter.ForEach({ ... })      # line 125
...
$ccReport.ForEach({                                            # line 140
    '{0}: [{1}]: {2:p}' -f $LocalizedData.Type, $_.name, $_.percent
    if ($_.percent -lt $CodeCoverageThreshold) {               # line 142
        $ccFailMsgs += ($LocalizedData.CodeCoverageLessThanThreshold -f ...)
    }
})

$testCoverage.report.counter is the report-level counter list from the JaCoCo XML: INSTRUCTION, LINE, METHOD, CLASS. These counters measure different things and diverge widely on real modules, so one scalar threshold cannot express a sane gate. Example: LINE = 60% but CLASS = 37.5% (3 of 8 source files exercised) - a 0.45 threshold should pass on lines, yet the build still fails on CLASS, with no way to say "gate LINE only". In practice consumers either set the threshold to 0 or turn coverage off, which defeats the feature.

Suggested fix (either is sufficient):

  • Add a parameter such as [string[]]$CodeCoverageGateCounters = @('LINE') selecting which counter types enforce the threshold, keeping the other counters printed for information.
  • Or gate only LINE and demote the other counters to display-only.

Notes:

  • fix: Report real code coverage percentages in Test-PSBuildPester #165 is merged but unreleased: v0.8.2 (latest tag) still contains the [Math]::Truncate line, so gallery consumers need a release before either fix reaches them.
  • Pester 6.1.0's own CodeCoverage.CoveragePercentTarget is display-only (colors the console line; exit code derives solely from failed tests), so delegating this gate to Pester would not enforce anything today.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions