1
-
1
+ $directory = Split-Path - Parent $MyInvocation.MyCommand.Path
2
+ $testRootDirectory = Split-Path - Parent $directory
3
+
2
4
Import-Module PSScriptAnalyzer
5
+ Import-Module (Join-Path $testRootDirectory " PSScriptAnalyzerTestHelper.psm1" )
6
+
3
7
$violationMessage = " The cmdlet 'Comment' does not have a help comment."
4
8
$violationName = " PSProvideCommentHelp"
5
- $directory = Split-Path - Parent $MyInvocation.MyCommand.Path
6
9
$violations = Invoke-ScriptAnalyzer $directory \BadCmdlet.ps1 | Where-Object {$_.RuleName -eq $violationName }
7
10
8
- if ($PSVersionTable.PSVersion -ge [Version ]' 5.0.0' )
9
- {
11
+ if ($PSVersionTable.PSVersion -ge [Version ]' 5.0.0' ) {
10
12
$dscViolations = Invoke-ScriptAnalyzer - ErrorAction SilentlyContinue $directory \DSCResources\MyDscResource\MyDscResource.psm1 | Where-Object {$_.RuleName -eq $violationName }
11
13
}
12
14
13
15
$noViolations = Invoke-ScriptAnalyzer $directory \GoodCmdlet.ps1 | Where-Object {$_.RuleName -eq $violationName }
14
16
17
+ function Test-Correction {
18
+ param ($scriptDef , $expectedCorrection )
19
+
20
+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDef - IncludeRule $violationName
21
+ $violations.Count | Should Be 1
22
+ $violations [0 ].SuggestedCorrections[0 ].Text | Should Be $expectedCorrection
23
+ }
24
+
15
25
Describe " ProvideCommentHelp" {
16
26
Context " When there are violations" {
17
27
It " has 2 provide comment help violations" {
@@ -26,8 +36,93 @@ Describe "ProvideCommentHelp" {
26
36
$violations [1 ].Extent.Text | Should Be " Comment"
27
37
}
28
38
29
- if ($PSVersionTable.PSVersion -ge [Version ]' 5.0.0' )
30
- {
39
+ It " should return a help snippet correction with 0 parameters" {
40
+ $def = @'
41
+ function foo {
42
+ }
43
+
44
+ Export-ModuleMember -Function foo
45
+ '@
46
+ $expectedCorrection = @'
47
+ <#
48
+ .SYNOPSIS
49
+ Short description
50
+
51
+ .DESCRIPTION
52
+ Long description
53
+
54
+ .EXAMPLE
55
+ An example
56
+
57
+ .NOTES
58
+ General notes
59
+ #>
60
+ '@
61
+ Test-Correction $def $expectedCorrection
62
+ }
63
+
64
+ It " should return a help snippet correction with 1 parameters" {
65
+ $def = @'
66
+ function foo {
67
+ param($param1)
68
+ }
69
+
70
+ Export-ModuleMember -Function foo
71
+ '@
72
+ $expectedCorrection = @'
73
+ <#
74
+ .SYNOPSIS
75
+ Short description
76
+
77
+ .DESCRIPTION
78
+ Long description
79
+
80
+ .PARAMETER param1
81
+ Parameter description
82
+
83
+ .EXAMPLE
84
+ An example
85
+
86
+ .NOTES
87
+ General notes
88
+ #>
89
+ '@
90
+ Test-Correction $def $expectedCorrection
91
+ }
92
+
93
+ It " should return a help snippet correction with 2 parameters" {
94
+ $def = @'
95
+ function foo {
96
+ param($param1, $param2)
97
+ }
98
+
99
+ Export-ModuleMember -Function foo
100
+ '@
101
+ $expectedCorrection = @'
102
+ <#
103
+ .SYNOPSIS
104
+ Short description
105
+
106
+ .DESCRIPTION
107
+ Long description
108
+
109
+ .PARAMETER param1
110
+ Parameter description
111
+
112
+ .PARAMETER param2
113
+ Parameter description
114
+
115
+ .EXAMPLE
116
+ An example
117
+
118
+ .NOTES
119
+ General notes
120
+ #>
121
+ '@
122
+ Test-Correction $def $expectedCorrection
123
+ }
124
+
125
+ if ($PSVersionTable.PSVersion -ge [Version ]' 5.0.0' ) {
31
126
It " Does not count violation in DSC class" {
32
127
$dscViolations.Count | Should Be 0
33
128
}
0 commit comments