Skip to content

Commit 32cb3dc

Browse files
committed
Tests fpr PSAvoidPOsitionalParameters rule.
1 parent d90054b commit 32cb3dc

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Tests/Rules/AvoidPositionalParameters.tests.ps1

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

0 commit comments

Comments
 (0)