Skip to content

Commit 9cf3d04

Browse files
author
Kapil Borle
committed
Add rule suppression test case
1 parent b551211 commit 9cf3d04

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Tests/Engine/RuleSuppression.tests.ps1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ $securePassword = ConvertTo-SecureString $decryptedPassword -AsPlainText -Force
3030
}
3131
'@
3232

33+
# If function doesn't starts at offset 0, then the test case fails before commit b551211
34+
$ruleSuppressionAvoidUsernameAndPassword = @'
35+
36+
function SuppressUserAndPwdRule()
37+
{
38+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingUserNameAndPassWordParams", "")]
39+
[CmdletBinding()]
40+
param
41+
(
42+
[System.String] $username,
43+
[System.Boolean] $password
44+
)
45+
}
46+
'@
47+
3348
Describe "RuleSuppressionWithoutScope" {
3449
Context "Function" {
3550
It "Does not raise violations" {
@@ -38,6 +53,16 @@ Describe "RuleSuppressionWithoutScope" {
3853
$suppression = $violationsUsingScriptDefinition | Where-Object { $_.RuleName -eq "PSProvideCommentHelp" }
3954
$suppression.Count | Should Be 0
4055
}
56+
57+
It "Suppresses rule with extent created using ScriptExtent constructor" {
58+
Invoke-ScriptAnalyzer `
59+
-ScriptDefinition $ruleSuppressionAvoidUsernameAndPassword `
60+
-IncludeRule "PSAvoidUsingUserNameAndPassWordParams" `
61+
-OutVariable ruleViolations `
62+
-SuppressedOnly
63+
$ruleViolations.Count | Should Be 1
64+
}
65+
4166
}
4267

4368
Context "Script" {

0 commit comments

Comments
 (0)