Skip to content

Commit b063ac9

Browse files
kalgizSteveL-MSFT
authored andcommitted
Tests fpr PSAvoidPOsitionalParameters rule.
1 parent d1bec74 commit b063ac9

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Tests/Rules/AvoidPositionalParameters.tests.ps1

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,26 @@ Describe "AvoidPositionalParameters" {
2222
It "returns no violations" {
2323
$noViolations.Count | Should -Be 0
2424
}
25-
25+
2626
It "returns no violations for DSC configuration" {
2727
$noViolationsDSC.Count | Should -Be 0
2828
}
2929
}
30-
}
30+
31+
Context "Function defined and called in script, which has 3 or more positional parameters triggers rule." {
32+
$sb=
33+
{
34+
Function Foo {
35+
param(
36+
[Parameter(Mandatory=$true,Position=1)] $A,
37+
[Parameter(Position=2)]$B,
38+
[Parameter(Position=3)]$C)
39+
}
40+
Foo "a" "b" "c"
41+
}
42+
$warnings = Invoke-ScriptAnalyzer -ScriptDefinition "$sb"
43+
$warnings.Count | Should -BeGreaterThan 0
44+
$warning.RuleName | Should -Contain "PSAvoidUsingPositionalParameters"
45+
$warnings.Message | Should -Contain "Cmdlet 'Foo' has positional parameter. Please use named parameters instead of positional parameters when calling a command."
46+
}
47+
}

0 commit comments

Comments
 (0)