Skip to content

Commit f7a0995

Browse files
author
Kapil Borle
committed
Fix tests in InvokeScriptAnalyzer.tests.ps1
1 parent 93e41cf commit f7a0995

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

Tests/Engine/InvokeScriptAnalyzer.tests.ps1

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ if (!(Get-Module PSScriptAnalyzer) -and !$testingLibraryUsage)
99
$sa = Get-Command Invoke-ScriptAnalyzer
1010
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
1111
$singularNouns = "PSUseSingularNouns"
12+
$approvedVerb = "PSUseApprovedVerbs"
1213
$rules = Get-ScriptAnalyzerRule -Name ($singularNouns, "PSUseApprovedVerbs")
1314
$avoidRules = Get-ScriptAnalyzerRule -Name "PSAvoid*"
1415
$useRules = "PSUse*"
@@ -242,13 +243,19 @@ Describe "Test ExcludeRule" {
242243
Describe "Test IncludeRule" {
243244
Context "When used correctly" {
244245
It "includes 1 rule" {
245-
$violations = Invoke-ScriptAnalyzer $directory\..\Rules\BadCmdlet.ps1 -IncludeRule $singularNouns | Where-Object {$_.RuleName -eq $singularNouns}
246+
$violations = Invoke-ScriptAnalyzer $directory\..\Rules\BadCmdlet.ps1 -IncludeRule $approvedVerb | Where-Object {$_.RuleName -eq $approvedVerb}
246247
$violations.Count | Should Be 1
247248
}
248249

249-
It "includes 2 rules" {
250+
It "includes the given rules" {
251+
# CoreCLR version of PSScriptAnalyzer does not contain PSUseSingularNouns rule
252+
$expectedNumViolations = 2
253+
if ((Test-PSEditionCoreCLR))
254+
{
255+
$expectedNumViolations = 1
256+
}
250257
$violations = Invoke-ScriptAnalyzer $directory\..\Rules\BadCmdlet.ps1 -IncludeRule $rules
251-
$violations.Count | Should Be 2
258+
$violations.Count | Should Be $expectedNumViolations
252259
}
253260
}
254261

@@ -266,14 +273,20 @@ Describe "Test IncludeRule" {
266273
}
267274

268275
it "includes 2 wildcardrules" {
276+
# CoreCLR version of PSScriptAnalyzer does not contain PSUseSingularNouns rule
277+
$expectedNumViolations = 4
278+
if ((Test-PSEditionCoreCLR))
279+
{
280+
$expectedNumViolations = 3
281+
}
269282
$includeWildcard = Invoke-ScriptAnalyzer $directory\..\Rules\BadCmdlet.ps1 -IncludeRule $avoidRules
270283
$includeWildcard += Invoke-ScriptAnalyzer $directory\..\Rules\BadCmdlet.ps1 -IncludeRule $useRules
271-
$includeWildcard.Count | Should be 4
284+
$includeWildcard.Count | Should be $expectedNumViolations
272285
}
273286
}
274287
}
275288

276-
Describe "Test Exclude And Include" {
289+
Describe "Test Exclude And Include" {1
277290
It "Exclude and Include different rules" {
278291
$violations = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -IncludeRule "PSAvoidUsingEmptyCatchBlock" -ExcludeRule "PSAvoidUsingPositionalParameters"
279292
$violations.Count | Should be 1

0 commit comments

Comments
 (0)