Skip to content

Commit e847cf9

Browse files
author
Kapil Borle
committed
Add test for suppressing external rule
1 parent bbfd1d9 commit e847cf9

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

Tests/Engine/RuleSuppression.tests.ps1

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,31 @@ function SuppressPwdParam()
114114

115115
if (!$testingLibraryUsage)
116116
{
117-
Context "Bad Rule Suppression" {
118-
It "Throws a non-terminating error" {
119-
Invoke-ScriptAnalyzer -ScriptDefinition $ruleSuppressionBad -IncludeRule "PSAvoidUsingUserNameAndPassWordParams" -ErrorVariable errorRecord -ErrorAction SilentlyContinue
120-
$errorRecord.Count | Should Be 1
121-
$errorRecord.FullyQualifiedErrorId | Should match "suppression message attribute error"
122-
}
123-
}
117+
Context "Bad Rule Suppression" {
118+
It "Throws a non-terminating error" {
119+
Invoke-ScriptAnalyzer -ScriptDefinition $ruleSuppressionBad -IncludeRule "PSAvoidUsingUserNameAndPassWordParams" -ErrorVariable errorRecord -ErrorAction SilentlyContinue
120+
$errorRecord.Count | Should Be 1
121+
$errorRecord.FullyQualifiedErrorId | Should match "suppression message attribute error"
122+
}
123+
}
124+
125+
Context "External Rule Suppression" {
126+
$externalRuleSuppression = @'
127+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('CommunityAnalyzerRules\Measure-WriteHost','')]
128+
param() # without the param block, powershell parser throws up!
129+
Write-Host "write-host"
130+
'@
131+
It "Suppresses violation of an external ast rule" {
132+
Invoke-ScriptAnalyzer `
133+
-ScriptDefinition $externalRuleSuppression `
134+
-CustomRulePath "CommunityAnalyzerRules/" `
135+
-OutVariable ruleViolations `
136+
-SuppressedOnly
137+
$ruleViolations.Count | Should Be 1
138+
}
139+
}
140+
141+
124142
}
125143
}
126144

0 commit comments

Comments
 (0)