Skip to content

Commit 034191f

Browse files
author
Kapil Borle
committed
Add test to check SuppressRule error behavior
1 parent 2b5c26a commit 034191f

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

Tests/Engine/RuleSuppression.tests.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ $directory = Split-Path -Parent $MyInvocation.MyCommand.Path
1010
$violationsUsingScriptDefinition = Invoke-ScriptAnalyzer -ScriptDefinition (Get-Content -Raw "$directory\RuleSuppression.ps1")
1111
$violations = Invoke-ScriptAnalyzer "$directory\RuleSuppression.ps1"
1212

13+
$ruleSuppressionBad = @'
14+
Function do-something
15+
{
16+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingUserNameAndPassWordParams", "username")]
17+
Param(
18+
$username,
19+
$password
20+
)
21+
}
22+
'@
23+
1324
Describe "RuleSuppressionWithoutScope" {
1425
Context "Function" {
1526
It "Does not raise violations" {
@@ -37,6 +48,14 @@ Describe "RuleSuppressionWithoutScope" {
3748
$suppression.Count | Should Be 1
3849
}
3950
}
51+
52+
Context "Bad Rule Suppression" {
53+
It "Throws a non-terminating error" {
54+
Invoke-ScriptAnalyzer -ScriptDefinition $ruleSuppressionBad -IncludeRule "PSAvoidUsingUserNameAndPassWordParams" -ErrorVariable errorRecord 2>$null
55+
$errorRecord.Count | Should Be 1
56+
$errorRecord.FullyQualifiedErrorId | Should match "suppression message attribute error"
57+
}
58+
}
4059
}
4160

4261
Describe "RuleSuppressionWithScope" {

0 commit comments

Comments
 (0)