11function Test-PSBuildPester {
2+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute (
3+ ' PSReviewUnusedParameter' ,
4+ ' CodeCoverageThreshold' ,
5+ Justification = ' Used inside a foreach method call.'
6+ )]
27 <#
38 . SYNOPSIS
49 Execute Pester tests for module.
@@ -27,11 +32,11 @@ function Test-PSBuildPester {
2732 . PARAMETER ImportModule
2833 Import module from OutDir prior to running Pester tests.
2934 . EXAMPLE
30- PS> Test-PSBuildPester -Path ./tests -ModuleName Mymodule -OutputPath ./out/testResults.xml
35+ PS> Test-PSBuildPester -Path ./tests -ModuleName MyModule -OutputPath ./out/testResults.xml
3136
3237 Run Pester tests in ./tests and save results to ./out/testResults.xml
3338 #>
34- [cmdletbinding ()]
39+ [CmdletBinding ()]
3540 param (
3641 [parameter (Mandatory )]
3742 [string ]$Path ,
@@ -76,18 +81,18 @@ function Test-PSBuildPester {
7681
7782 Import-Module Pester - MinimumVersion 5.0 .0
7883 $configuration = [PesterConfiguration ]::Default
79- $configuration.Output.Verbosity = ' Detailed'
80- $configuration.Run.PassThru = $true
81- $configuration.TestResult.Enabled = -not [string ]::IsNullOrEmpty($OutputPath )
82- $configuration.TestResult.OutputPath = $OutputPath
84+ $configuration.Output.Verbosity = ' Detailed'
85+ $configuration.Run.PassThru = $true
86+ $configuration.TestResult.Enabled = -not [string ]::IsNullOrEmpty($OutputPath )
87+ $configuration.TestResult.OutputPath = $OutputPath
8388 $configuration.TestResult.OutputFormat = $OutputFormat
8489
8590 if ($CodeCoverage.IsPresent ) {
8691 $configuration.CodeCoverage.Enabled = $true
8792 if ($CodeCoverageFiles.Count -gt 0 ) {
8893 $configuration.CodeCoverage.Path = $CodeCoverageFiles
8994 }
90- $configuration.CodeCoverage.OutputPath = $CodeCoverageOutputFile
95+ $configuration.CodeCoverage.OutputPath = $CodeCoverageOutputFile
9196 $configuration.CodeCoverage.OutputFormat = $CodeCoverageOutputFileFormat
9297 }
9398
@@ -103,25 +108,25 @@ function Test-PSBuildPester {
103108 $textInfo = (Get-Culture ).TextInfo
104109 [xml ]$testCoverage = Get-Content $CodeCoverageOutputFile
105110 $ccReport = $testCoverage.report.counter.ForEach ({
106- $total = [int ]$_.missed + [int ]$_.covered
107- $perc = [Math ]::Truncate([int ]$_.covered / $total )
108- [ pscustomobject ]@ {
109- name = $textInfo.ToTitleCase ($_.Type.ToLower ())
110- percent = $perc
111- }
112- })
111+ $total = [int ]$_.missed + [int ]$_.covered
112+ $percent = [Math ]::Truncate([int ]$_.covered / $total )
113+ [ PSCustomObject ]@ {
114+ name = $textInfo.ToTitleCase ($_.Type.ToLower ())
115+ percent = $percent
116+ }
117+ })
113118
114119 $ccFailMsgs = @ ()
115120 $ccReport.ForEach ({
116- ' Type: [{0}]: {1:p}' -f $_.name , $_.percent
117- if ($_.percent -lt $CodeCoverageThreshold ) {
118- $ccFailMsgs += (' Code coverage: [{0}] is [{1:p}], which is less than the threshold of [{2:p}]' -f $_.name , $_.percent , $CodeCoverageThreshold )
119- }
120- })
121+ ' Type: [{0}]: {1:p}' -f $_.name , $_.percent
122+ if ($_.percent -lt $CodeCoverageThreshold ) {
123+ $ccFailMsgs += (' Code coverage: [{0}] is [{1:p}], which is less than the threshold of [{2:p}]' -f $_.name , $_.percent , $CodeCoverageThreshold )
124+ }
125+ })
121126 Write-Host " `n "
122127 $ccFailMsgs.Foreach ({
123- Write-Error $_
124- })
128+ Write-Error $_
129+ })
125130 } else {
126131 Write-Error " Code coverage file [$CodeCoverageOutputFile ] not found."
127132 }
0 commit comments