Last active
May 16, 2021 14:01
-
-
Save nohwnd/3a29c8f4afc21329a146b5cba953d503 to your computer and use it in GitHub Desktop.
Compare CC in Pester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function a () { | |
if ($true) { | |
"yes" | |
$a = 10 | |
} | |
else { | |
"no" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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