Skip to content

Commit f7e4637

Browse files
committed
add tests to PSUseDeclaredVarsMoreThanAssignments to check that it flags a variable that is assigned twice but still never used.
1 parent 667aea5 commit f7e4637

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Tests/Rules/UseDeclaredVarsMoreThanAssignments.tests.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ function MyFunc2() {
4949
Get-Count | `
5050
Should Be 0
5151
}
52+
53+
It "flags a variable that is defined twice but never used" {
54+
Invoke-ScriptAnalyzer -ScriptDefinition '$myvar=1;$myvar=2' -IncludeRule $violationName | `
55+
Get-Count | `
56+
Should Be 1
57+
}
58+
59+
It "does not flag a variable that is defined twice but gets assigned to another variable and flags the other variable instead" {
60+
$results = Invoke-ScriptAnalyzer -ScriptDefinition '$myvar=1;$myvar=2;$mySecondvar=$myvar' -IncludeRule $violationName
61+
$results | Get-Count | Should Be 1
62+
$results[0].Extent | Should Be '$mySecondvar'
63+
}
5264
}
5365

5466
Context "When there are no violations" {

0 commit comments

Comments
 (0)