@@ -5,13 +5,13 @@ Import-Module PSScriptAnalyzer
5
5
Import-Module (Join-Path $testRootDirectory " PSScriptAnalyzerTestHelper.psm1" )
6
6
7
7
$ruleConfiguration = @ {
8
- Enable = $true
8
+ Enable = $true
9
9
CheckHashtable = $true
10
10
}
11
11
12
12
$settings = @ {
13
13
IncludeRules = @ (" PSAlignAssignmentStatement" )
14
- Rules = @ {
14
+ Rules = @ {
15
15
PSAlignAssignmentStatement = $ruleConfiguration
16
16
}
17
17
}
@@ -26,30 +26,30 @@ $hashtable = @{
26
26
}
27
27
'@
28
28
29
- # Expected output after correction should be the following
30
- # $hashtable = @{
31
- # property1 = "value"
32
- # anotherProperty = "another value"
33
- # }
29
+ # Expected output after correction should be the following
30
+ # $hashtable = @{
31
+ # property1 = "value"
32
+ # anotherProperty = "another value"
33
+ # }
34
34
35
35
$violations = Invoke-ScriptAnalyzer - ScriptDefinition $def - Settings $settings
36
36
$violations.Count | Should Be 1
37
37
Test-CorrectionExtentFromContent $def $violations 1 ' ' ' '
38
38
}
39
39
40
- It " Should find violation when assignment statements are not aligned (whitespace needs to be removed)" {
40
+ It " Should find violation when assignment statements are not aligned (whitespace needs to be removed)" {
41
41
$def = @'
42
42
$hashtable = @{
43
43
property1 = "value"
44
44
anotherProperty = "another value"
45
45
}
46
46
'@
47
47
48
- # Expected output should be the following
49
- # $hashtable = @{
50
- # property1 = "value"
51
- # anotherProperty = "another value"
52
- # }
48
+ # Expected output should be the following
49
+ # $hashtable = @{
50
+ # property1 = "value"
51
+ # anotherProperty = "another value"
52
+ # }
53
53
54
54
$violations = Invoke-ScriptAnalyzer - ScriptDefinition $def - Settings $settings
55
55
$violations.Count | Should Be 1
@@ -87,5 +87,37 @@ Configuration MyDscConfiguration {
87
87
'@
88
88
Invoke-ScriptAnalyzer - ScriptDefinition $def - Settings $settings | Get-Count | Should Be 2
89
89
}
90
+ }
91
+
92
+ Context " When assignment statements are in DSC Configuration that has parse errors" {
93
+ It " Sdhould find violations when assignment statements are not aligned" {
94
+ $def = @'
95
+ Configuration Sample_ChangeDescriptionAndPermissions
96
+ {
97
+ Import-DscResource -Module NonExistentModule
98
+ # A Configuration block can have zero or more Node blocks
99
+ Node $NodeName
100
+ {
101
+ # Next, specify one or more resource blocks
102
+
103
+ NonExistentModule MySMBShare
104
+ {
105
+ Ensure = "Present"
106
+ Name = "MyShare"
107
+ Path = "C:\Demo\Temp"
108
+ ReadAccess = "author"
109
+ FullAccess = "some other author"
110
+ Description = "This is an updated description for this share"
111
+ }
112
+ }
90
113
}
114
+ '@
115
+ # This invocation will throw parse error caused by "Undefined DSC resource" because
116
+ # NonExistentModule is not really avaiable to load. Therefore we set erroraction to
117
+ # SilentlyContinue
118
+ Invoke-ScriptAnalyzer - ScriptDefinition $def - Settings $settings - ErrorAction SilentlyContinue |
119
+ Get-Count |
120
+ Should Be 4
121
+ }
122
+ }
91
123
}
0 commit comments