Skip to content

Instantly share code, notes, and snippets.

@nohwnd
Last active May 16, 2021 14:01
Show Gist options
  • Save nohwnd/3a29c8f4afc21329a146b5cba953d503 to your computer and use it in GitHub Desktop.
Save nohwnd/3a29c8f4afc21329a146b5cba953d503 to your computer and use it in GitHub Desktop.
Compare CC in Pester
$c = New-PesterConfiguration
# your Path
$c.Run.Path = "."
$c.Run.PassThru = $true
# detailed prints the CC report, but that is very verbose
# use only for tiny codebases
# $c.Output.Verbosity = "Detailed"
# optional, slows down the execution a lot on bigger runs
# $c.Debug.WriteDebugMessages = $true
# $c.Debug.WriteDebugMessagesFrom = "CodeCoverage"
$c.CodeCoverage.Enabled = $true
# makes it easier to visualize this in VSCode, if this fails
# comment this line out to use Jacoco
$c.CodeCoverage.OutputFormat = "CoverageGutters"
# use tracer CC
$c.CodeCoverage.UseBreakpoints = $false
$c.CodeCoverage.OutputPath = "coverage-with-tracer.xml"
$pp = Invoke-Pester -Configuration $c
# # use normal CC
$c.CodeCoverage.UseBreakpoints = $true
$c.CodeCoverage.OutputPath = "coverage-with-breakpoints.xml"
$bb = Invoke-Pester -Configuration $c
# compare the outputs
"is different?: " + ($bb.CodeCoverage.CommandsMissed.Count -ne $pp.CodeCoverage.CommandsMissed.Count)
"is less?: " + ($bb.CodeCoverage.CommandsMissed.Count -lt $pp.CodeCoverage.CommandsMissed.Count)
$bm = $bb.CodeCoverage.CommandsMissed
$pm = $pp.CodeCoverage.CommandsMissed
$m = $bm | foreach { $h = @{} } { $h["$($_.File)-$($_.Line)-$($_.StartColumn)"] = $_ } { $h }
$diff = $pm | where { -not $m.ContainsKey("$($_.File)-$($_.Line)-$($_.StartColumn)") }
"difference count?: " + $diff.Count
$diff | ft
function a () {
if ($true) {
"yes"
$a = 10
}
else {
"no"
}
}
Describe "A" {
BeforeAll {
. "$PSScriptRoot/yesno.ps1"
}
It "B" {
a
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment