1
1
Import-Module PSScriptAnalyzer
2
- $violationMessage = " Cmdlet 'Get-Command' has positional parameter. Please use named parameters instead of positional parameters when calling a command."
3
- $violationName = " PSAvoidUsingPositionalParameters"
4
- $directory = Split-Path - Parent $MyInvocation.MyCommand.Path
5
- $violations = Invoke-ScriptAnalyzer $directory \AvoidPositionalParameters.ps1 | Where-Object {$_.RuleName -eq $violationName }
6
- $noViolations = Invoke-ScriptAnalyzer $directory \AvoidPositionalParametersNoViolations.ps1 | Where-Object {$_.RuleName -eq $violationName }
7
- $noViolationsDSC = Invoke-ScriptAnalyzer - ErrorAction SilentlyContinue $directory \serviceconfigdisabled.ps1 | Where-Object {$_.RuleName -eq $violationName }
8
2
9
3
Describe " AvoidPositionalParameters" {
4
+ BeforeAll {
5
+ $directory = $PSScriptRoot
6
+ $violationName = " PSAvoidUsingPositionalParameters"
7
+ $violation = Invoke-ScriptAnalyzer - ScriptDefinition ' Get-Command "abc" 4 4.3'
8
+ $noViolations = Invoke-ScriptAnalyzer $directory \AvoidPositionalParametersNoViolations.ps1 | Where-Object {$_.RuleName -eq $violationName }
9
+ $noViolationsDSC = Invoke-ScriptAnalyzer - ErrorAction SilentlyContinue $directory \serviceconfigdisabled.ps1 | Where-Object {$_.RuleName -eq $violationName }
10
+ }
10
11
Context " When there are violations" {
11
12
It " has 1 avoid positional parameters violation" {
12
- $violations.Count | Should - Be 1
13
- }
14
-
15
- It " has the correct description message" {
16
- $violations [0 ].Message | Should -Match $violationMessage
13
+ @ ($violation ).Count | Should - Be 1
14
+ $violation.RuleName | Should - Be $violationName
17
15
}
18
-
19
16
}
20
17
21
18
Context " When there are no violations" {
@@ -27,4 +24,4 @@ Describe "AvoidPositionalParameters" {
27
24
$noViolationsDSC.Count | Should - Be 0
28
25
}
29
26
}
30
- }
27
+ }
0 commit comments