|
1 |
| -Import-Module PSScriptAnalyzer |
2 |
| -$violationMessage = "'Verb-Files' has the ShouldProcess attribute but does not call ShouldProcess/ShouldContinue." |
| 1 | +$violationMessage = "'Verb-Files' has the ShouldProcess attribute but does not call ShouldProcess/ShouldContinue." |
3 | 2 | $violationName = "PSShouldProcess"
|
4 | 3 | $directory = Split-Path -Parent $MyInvocation.MyCommand.Path
|
| 4 | +$testRootDirectory = Split-Path -Parent $directory |
| 5 | + |
| 6 | +Import-Module (Join-Path $testRootDirectory 'PSScriptAnalyzerTestHelper.psm1') |
| 7 | +Import-Module PSScriptAnalyzer |
| 8 | + |
5 | 9 | $violations = Invoke-ScriptAnalyzer $directory\BadCmdlet.ps1 | Where-Object {$_.RuleName -eq $violationName}
|
6 | 10 | $noViolations = Invoke-ScriptAnalyzer $directory\GoodCmdlet.ps1 | Where-Object {$_.RuleName -eq $violationName}
|
| 11 | +$IsV3OrV4 = (Test-PSVersionV3) -or (Test-PSVersionV4) |
7 | 12 |
|
8 | 13 | Describe "UseShouldProcessCorrectly" {
|
9 | 14 | Context "When there are violations" {
|
@@ -172,7 +177,8 @@ function Remove-Foo {
|
172 | 177 | $violations.Count | Should Be 0
|
173 | 178 | }
|
174 | 179 |
|
175 |
| - It "finds no violation when caller declares SupportsShouldProcess and callee is a function with ShouldProcess" { |
| 180 | + # Install-Module is present by default only on PSv5 and above |
| 181 | + It "finds no violation when caller declares SupportsShouldProcess and callee is a function with ShouldProcess" -Skip:$IsV3OrV4 { |
176 | 182 | $scriptDef = @'
|
177 | 183 | function Install-Foo {
|
178 | 184 | [CmdletBinding(SupportsShouldProcess)]
|
@@ -223,7 +229,8 @@ function Install-ModuleWithDeps {
|
223 | 229 | $violations.Count | Should Be 0
|
224 | 230 | }
|
225 | 231 |
|
226 |
| - It "finds no violation for a function with self reference and implicit call to ShouldProcess" { |
| 232 | + # Install-Module is present by default only on PSv5 and above |
| 233 | + It "finds no violation for a function with self reference and implicit call to ShouldProcess" -Skip:$IsV3OrV4 { |
227 | 234 | $scriptDef = @'
|
228 | 235 | function Install-ModuleWithDeps {
|
229 | 236 | [CmdletBinding(SupportsShouldProcess)]
|
|
0 commit comments