1
1
function Test-PSBuildPester {
2
+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute (
3
+ ' PSReviewUnusedParameter' ,
4
+ ' CodeCoverageThreshold' ,
5
+ Justification = ' Used inside a foreach method call.'
6
+ )]
2
7
<#
3
8
. SYNOPSIS
4
9
Execute Pester tests for module.
@@ -27,11 +32,11 @@ function Test-PSBuildPester {
27
32
. PARAMETER ImportModule
28
33
Import module from OutDir prior to running Pester tests.
29
34
. 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
31
36
32
37
Run Pester tests in ./tests and save results to ./out/testResults.xml
33
38
#>
34
- [cmdletbinding ()]
39
+ [CmdletBinding ()]
35
40
param (
36
41
[parameter (Mandatory )]
37
42
[string ]$Path ,
@@ -76,18 +81,18 @@ function Test-PSBuildPester {
76
81
77
82
Import-Module Pester - MinimumVersion 5.0 .0
78
83
$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
83
88
$configuration.TestResult.OutputFormat = $OutputFormat
84
89
85
90
if ($CodeCoverage.IsPresent ) {
86
91
$configuration.CodeCoverage.Enabled = $true
87
92
if ($CodeCoverageFiles.Count -gt 0 ) {
88
93
$configuration.CodeCoverage.Path = $CodeCoverageFiles
89
94
}
90
- $configuration.CodeCoverage.OutputPath = $CodeCoverageOutputFile
95
+ $configuration.CodeCoverage.OutputPath = $CodeCoverageOutputFile
91
96
$configuration.CodeCoverage.OutputFormat = $CodeCoverageOutputFileFormat
92
97
}
93
98
@@ -103,25 +108,25 @@ function Test-PSBuildPester {
103
108
$textInfo = (Get-Culture ).TextInfo
104
109
[xml ]$testCoverage = Get-Content $CodeCoverageOutputFile
105
110
$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
+ })
113
118
114
119
$ccFailMsgs = @ ()
115
120
$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
+ })
121
126
Write-Host " `n "
122
127
$ccFailMsgs.Foreach ({
123
- Write-Error $_
124
- })
128
+ Write-Error $_
129
+ })
125
130
} else {
126
131
Write-Error " Code coverage file [$CodeCoverageOutputFile ] not found."
127
132
}
0 commit comments