Skip to content

Commit e35bec6

Browse files
PoshAJPoshAJ
PoshAJ
authored and
PoshAJ
committed
Add Tests for foreach Assignment
1 parent 1761cf0 commit e35bec6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Tests/Rules/AvoidAssignmentToAutomaticVariable.tests.ps1

+9
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ Describe "AvoidAssignmentToAutomaticVariables" {
7171
$warnings.RuleName | Should -Be $ruleName
7272
}
7373

74+
It "Using Variable <VariableName> as foreach name produces warning of Severity <ExpectedSeverity>" -TestCases $testCases_AutomaticVariables {
75+
param ($VariableName, $ExpectedSeverity)
76+
77+
[System.Array] $warnings = Invoke-ScriptAnalyzer -ScriptDefinition "foreach (`$$VariableName in `$foo) {}" -ExcludeRule PSReviewUnusedParameter
78+
$warnings.Count | Should -Be 1
79+
$warnings.Severity | Should -Be $ExpectedSeverity
80+
$warnings.RuleName | Should -Be $ruleName
81+
}
82+
7483
It "Using Variable <VariableName> as parameter name produces warning of Severity error" -TestCases $testCases_AutomaticVariables {
7584
param ($VariableName, $ExpectedSeverity)
7685

0 commit comments

Comments
 (0)