Skip to content

Commit

Permalink
Add Tests for foreach Assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
PoshAJ authored and PoshAJ committed Aug 10, 2024
1 parent 1761cf0 commit e35bec6
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Tests/Rules/AvoidAssignmentToAutomaticVariable.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ Describe "AvoidAssignmentToAutomaticVariables" {
$warnings.RuleName | Should -Be $ruleName
}

It "Using Variable <VariableName> as foreach name produces warning of Severity <ExpectedSeverity>" -TestCases $testCases_AutomaticVariables {
param ($VariableName, $ExpectedSeverity)

[System.Array] $warnings = Invoke-ScriptAnalyzer -ScriptDefinition "foreach (`$$VariableName in `$foo) {}" -ExcludeRule PSReviewUnusedParameter
$warnings.Count | Should -Be 1
$warnings.Severity | Should -Be $ExpectedSeverity
$warnings.RuleName | Should -Be $ruleName
}

It "Using Variable <VariableName> as parameter name produces warning of Severity error" -TestCases $testCases_AutomaticVariables {
param ($VariableName, $ExpectedSeverity)

Expand Down

0 comments on commit e35bec6

Please sign in to comment.