Skip to content

Commit 788a79b

Browse files
author
Kapil Borle
committed
Fix failing tests for PSv4/PSv3
1 parent 51a7e44 commit 788a79b

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

Tests/Engine/GetScriptAnalyzerRule.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Describe "Test Name parameters" {
6262
It "get Rules with no parameters supplied" {
6363
$defaultRules = Get-ScriptAnalyzerRule
6464
$expectedNumRules = 45
65-
if ((Test-PSEditionCoreClr) -or (Test-PSVersionV3))
65+
if ((Test-PSEditionCoreClr) -or (Test-PSVersionV3) -or (Test-PSVersionV4))
6666
{
6767
# for PSv3 PSAvoidGlobalAliases is not shipped because
6868
# it uses StaticParameterBinder.BindCommand which is

Tests/Rules/AvoidGlobalAliases.tests.ps1

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
11
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
22
$testRootDirectory = Split-Path -Parent $directory
33
Import-Module (Join-Path $testRootDirectory 'PSScriptAnalyzerTestHelper.psm1')
4-
if ((Test-PSVersionV3))
5-
{
6-
return
7-
}
8-
94
Import-Module PSScriptAnalyzer
105

116
$AvoidGlobalAliasesError = "Avoid creating aliases with a Global scope."
127
$violationName = "PSAvoidGlobalAliases"
138
$violations = Invoke-ScriptAnalyzer $directory\AvoidGlobalAliases.psm1 | Where-Object {$_.RuleName -eq $violationName}
149
$noViolations = Invoke-ScriptAnalyzer $directory\AvoidGlobalAliasesNoViolations.ps1 | Where-Object {$_.RuleName -eq $violationName}
15-
10+
$IsV3OrV4 = (Test-PSVersionV3) -or (Test-PSVersionV4)
1611

1712
Describe "$violationName " {
1813
Context "When there are violations" {
19-
It "Has 4 avoid global alias violations" {
14+
It "Has 4 avoid global alias violations" -Skip:$IsV3OrV4 {
2015
$violations.Count | Should Be 4
2116
}
2217

23-
It "Has the correct description message" {
18+
It "Has the correct description message" -Skip:$IsV3OrV4 {
2419
$violations[0].Message | Should Match $AvoidGlobalAliasesError
2520
}
2621
}
2722

2823
Context "When there are no violations" {
29-
It "Returns no violations" {
24+
It "Returns no violations" -Skip:$IsV3OrV4 {
3025
$noViolations.Count | Should Be 0
3126
}
3227
}

Tests/Rules/PSCredentialType.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ $noViolations = Invoke-ScriptAnalyzer $directory\PSCredentialTypeNoViolations.ps
1111
Describe "PSCredentialType" {
1212
Context "When there are violations" {
1313
$expectedViolations = 1
14-
if (Test-PSVersionV3 -or Test-PSVersionV4) {
14+
if ((Test-PSVersionV3) -or (Test-PSVersionV4)) {
1515
$expectedViolations = 2
1616
}
1717
It ("has {0} PSCredential type violation" -f $expectedViolations) {

Tests/Rules/UseShouldProcessCorrectly.tests.ps1

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
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."
32
$violationName = "PSShouldProcess"
43
$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+
59
$violations = Invoke-ScriptAnalyzer $directory\BadCmdlet.ps1 | Where-Object {$_.RuleName -eq $violationName}
610
$noViolations = Invoke-ScriptAnalyzer $directory\GoodCmdlet.ps1 | Where-Object {$_.RuleName -eq $violationName}
11+
$IsV3OrV4 = (Test-PSVersionV3) -or (Test-PSVersionV4)
712

813
Describe "UseShouldProcessCorrectly" {
914
Context "When there are violations" {
@@ -172,7 +177,8 @@ function Remove-Foo {
172177
$violations.Count | Should Be 0
173178
}
174179

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 {
176182
$scriptDef = @'
177183
function Install-Foo {
178184
[CmdletBinding(SupportsShouldProcess)]
@@ -223,7 +229,8 @@ function Install-ModuleWithDeps {
223229
$violations.Count | Should Be 0
224230
}
225231

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 {
227234
$scriptDef = @'
228235
function Install-ModuleWithDeps {
229236
[CmdletBinding(SupportsShouldProcess)]

0 commit comments

Comments
 (0)