@@ -36,13 +36,13 @@ Param (
36
36
$SkipTest ,
37
37
38
38
[string []]
39
- $CommandPath = @ (" $PSScriptRoot \..\..\ functions" , " $PSScriptRoot \.. \..\internal\functions" ),
39
+ $CommandPath = @ (" $global :testroot \..\functions" , " $global :testroot \..\internal\functions" ),
40
40
41
41
[string ]
42
42
$ModuleName = " PSModuleDevelopment" ,
43
43
44
44
[string ]
45
- $ExceptionsFile = " $PSScriptRoot \Help.Exceptions.ps1"
45
+ $ExceptionsFile = " $global :testroot \general \Help.Exceptions.ps1"
46
46
)
47
47
if ($SkipTest ) { return }
48
48
. $ExceptionsFile
@@ -62,138 +62,83 @@ foreach ($command in $commands) {
62
62
63
63
# The module-qualified command fails on Microsoft.PowerShell.Archive cmdlets
64
64
$Help = Get-Help $commandName - ErrorAction SilentlyContinue
65
- $testhelperrors = 0
66
- $testhelpall = 0
67
- Describe " Test help for $commandName " {
68
-
69
- $testhelpall += 1
70
- if ($Help.Synopsis -like ' *`[`<CommonParameters`>`]*' ) {
71
- # If help is not found, synopsis in auto-generated help is the syntax diagram
72
- It " should not be auto-generated" {
73
- $Help.Synopsis | Should Not BeLike ' *`[`<CommonParameters`>`]*'
74
- }
75
- $testhelperrors += 1
76
- }
77
-
78
- $testhelpall += 1
79
- if ([String ]::IsNullOrEmpty($Help.Description.Text )) {
80
- # Should be a description for every function
81
- It " gets description for $commandName " {
82
- $Help.Description | Should Not BeNullOrEmpty
83
- }
84
- $testhelperrors += 1
85
- }
65
+
66
+ Describe " Test help for $commandName " {
86
67
87
- $testhelpall += 1
88
- if ([String ]::IsNullOrEmpty(($Help.Examples.Example | Select-Object - First 1 ).Code)) {
89
- # Should be at least one example
90
- It " gets example code from $commandName " {
91
- ($Help.Examples.Example | Select-Object - First 1 ).Code | Should Not BeNullOrEmpty
92
- }
93
- $testhelperrors += 1
94
- }
68
+ # If help is not found, synopsis in auto-generated help is the syntax diagram
69
+ It " should not be auto-generated" - TestCases @ { Help = $Help } {
70
+ $Help.Synopsis | Should -Not - BeLike ' *`[`<CommonParameters`>`]*'
71
+ }
95
72
96
- $testhelpall += 1
97
- if ([String ]::IsNullOrEmpty(($Help.Examples.Example.Remarks | Select-Object - First 1 ).Text)) {
98
- # Should be at least one example description
99
- It " gets example help from $commandName " {
100
- ($Help.Examples.Example.Remarks | Select-Object - First 1 ).Text | Should Not BeNullOrEmpty
101
- }
102
- $testhelperrors += 1
103
- }
73
+ # Should be a description for every function
74
+ It " gets description for $commandName " - TestCases @ { Help = $Help } {
75
+ $Help.Description | Should -Not - BeNullOrEmpty
76
+ }
104
77
105
- if ($testhelperrors -eq 0 ) {
106
- It " Ran silently $testhelpall tests" {
107
- $testhelperrors | Should be 0
108
- }
109
- }
78
+ # Should be at least one example
79
+ It " gets example code from $commandName " - TestCases @ { Help = $Help } {
80
+ ($Help.Examples.Example | Select-Object - First 1 ).Code | Should -Not - BeNullOrEmpty
81
+ }
82
+
83
+ # Should be at least one example description
84
+ It " gets example help from $commandName " - TestCases @ { Help = $Help } {
85
+ ($Help.Examples.Example.Remarks | Select-Object - First 1 ).Text | Should -Not - BeNullOrEmpty
86
+ }
110
87
111
- $testparamsall = 0
112
- $testparamserrors = 0
113
88
Context " Test parameter help for $commandName " {
114
89
115
- $Common = ' Debug' , ' ErrorAction' , ' ErrorVariable' , ' InformationAction' , ' InformationVariable' , ' OutBuffer' , ' OutVariable' ,
116
- ' PipelineVariable' , ' Verbose' , ' WarningAction' , ' WarningVariable'
90
+ $common = ' Debug' , ' ErrorAction' , ' ErrorVariable' , ' InformationAction' , ' InformationVariable' , ' OutBuffer' , ' OutVariable' , ' PipelineVariable' , ' Verbose' , ' WarningAction' , ' WarningVariable'
117
91
118
92
$parameters = $command.ParameterSets.Parameters | Sort-Object - Property Name - Unique | Where-Object Name -notin $common
119
93
$parameterNames = $parameters.Name
120
94
$HelpParameterNames = $Help.Parameters.Parameter.Name | Sort-Object - Unique
121
95
foreach ($parameter in $parameters ) {
122
96
$parameterName = $parameter.Name
123
97
$parameterHelp = $Help.parameters.parameter | Where-Object Name -EQ $parameterName
98
+
99
+ # Should be a description for every parameter
100
+ It " gets help for parameter: $parameterName : in $commandName " - TestCases @ { parameterHelp = $parameterHelp } {
101
+ $parameterHelp.Description.Text | Should -Not - BeNullOrEmpty
102
+ }
124
103
125
- $testparamsall += 1
126
- if ([String ]::IsNullOrEmpty($parameterHelp.Description.Text )) {
127
- # Should be a description for every parameter
128
- It " gets help for parameter: $parameterName : in $commandName " {
129
- $parameterHelp.Description.Text | Should Not BeNullOrEmpty
130
- }
131
- $testparamserrors += 1
132
- }
133
-
134
- $testparamsall += 1
135
104
$codeMandatory = $parameter.IsMandatory.toString ()
136
- if ($parameterHelp.Required -ne $codeMandatory ) {
137
- # Required value in Help should match IsMandatory property of parameter
138
- It " help for $parameterName parameter in $commandName has correct Mandatory value" {
139
- $parameterHelp.Required | Should Be $codeMandatory
140
- }
141
- $testparamserrors += 1
142
- }
105
+ It " help for $parameterName parameter in $commandName has correct Mandatory value" - TestCases @ { parameterHelp = $parameterHelp ; codeMandatory = $codeMandatory } {
106
+ $parameterHelp.Required | Should - Be $codeMandatory
107
+ }
143
108
144
109
if ($HelpTestSkipParameterType [$commandName ] -contains $parameterName ) { continue }
145
110
146
111
$codeType = $parameter.ParameterType.Name
147
112
148
- $testparamsall += 1
149
113
if ($parameter.ParameterType.IsEnum ) {
150
114
# Enumerations often have issues with the typename not being reliably available
151
115
$names = $parameter.ParameterType ::GetNames($parameter.ParameterType )
152
- if ($parameterHelp.parameterValueGroup.parameterValue -ne $names ) {
153
- # Parameter type in Help should match code
154
- It " help for $commandName has correct parameter type for $parameterName " {
155
- $parameterHelp.parameterValueGroup.parameterValue | Should be $names
156
- }
157
- $testparamserrors += 1
158
- }
116
+ # Parameter type in Help should match code
117
+ It " help for $commandName has correct parameter type for $parameterName " - TestCases @ { parameterHelp = $parameterHelp ; names = $names } {
118
+ $parameterHelp.parameterValueGroup.parameterValue | Should - be $names
119
+ }
159
120
}
160
121
elseif ($parameter.ParameterType.FullName -in $HelpTestEnumeratedArrays ) {
161
122
# Enumerations often have issues with the typename not being reliably available
162
123
$names = [Enum ]::GetNames($parameter.ParameterType.DeclaredMembers [0 ].ReturnType)
163
- if ($parameterHelp.parameterValueGroup.parameterValue -ne $names ) {
164
- # Parameter type in Help should match code
165
- It " help for $commandName has correct parameter type for $parameterName " {
166
- $parameterHelp.parameterValueGroup.parameterValue | Should be $names
167
- }
168
- $testparamserrors += 1
169
- }
124
+ It " help for $commandName has correct parameter type for $parameterName " - TestCases @ { parameterHelp = $parameterHelp ; names = $names } {
125
+ $parameterHelp.parameterValueGroup.parameterValue | Should - be $names
126
+ }
170
127
}
171
128
else {
172
129
# To avoid calling Trim method on a null object.
173
130
$helpType = if ($parameterHelp.parameterValue ) { $parameterHelp.parameterValue.Trim () }
174
- if ($helpType -ne $codeType ) {
175
- # Parameter type in Help should match code
176
- It " help for $commandName has correct parameter type for $parameterName " {
177
- $helpType | Should be $codeType
178
- }
179
- $testparamserrors += 1
180
- }
131
+ # Parameter type in Help should match code
132
+ It " help for $commandName has correct parameter type for $parameterName " - TestCases @ { helpType = $helpType ; codeType = $codeType } {
133
+ $helpType | Should - be $codeType
134
+ }
181
135
}
182
136
}
183
137
foreach ($helpParm in $HelpParameterNames ) {
184
- $testparamsall += 1
185
- if ($helpParm -notin $parameterNames ) {
186
- # Shouldn't find extra parameters in help.
187
- It " finds help parameter in code: $helpParm " {
188
- $helpParm -in $parameterNames | Should Be $true
189
- }
190
- $testparamserrors += 1
191
- }
192
- }
193
- if ($testparamserrors -eq 0 ) {
194
- It " Ran silently $testparamsall tests" {
195
- $testparamserrors | Should be 0
196
- }
138
+ # Shouldn't find extra parameters in help.
139
+ It " finds help parameter in code: $helpParm " - TestCases @ { helpParm = $helpParm ; parameterNames = $parameterNames } {
140
+ $helpParm -in $parameterNames | Should - Be $true
141
+ }
197
142
}
198
143
}
199
144
}
0 commit comments