@@ -37,7 +37,7 @@ $s$s$s$s$s$s$s$s
3737 $violations [0 ].SuggestedCorrections[0 ].Text | Should Be $expectedCorrection
3838 }
3939
40- It " Should return valid correction text if whatif the first parameter" {
40+ It " Should return valid correction text if whatif is the first parameter" {
4141 $def = @'
4242function foo {
4343 param(
@@ -86,7 +86,7 @@ function foo {
8686 }
8787
8888
89- It " Should return valid correction text if whatif the last parameter" {
89+ It " Should return valid correction text if whatif the last parameter" {
9090 $def = @'
9191function foo {
9292 param(
@@ -160,12 +160,52 @@ $s$s$s$s$s$s$s$s
160160 # Test-CorrectionExtentFromContent $def $violation 2 $expectedViolationText ''
161161 }
162162
163- It " Suggests adding SupportsShouldProcess attribute" {
164-
163+ It " Suggests adding SupportsShouldProcess attribute, when no argument is present" {
164+ $def = @'
165+ function foo {
166+ [CmdletBinding()]
167+ param(
168+ [bool] $confirm,
169+ [bool] $whatif
170+ )
171+ }
172+ '@
173+ $s = " "
174+ $expectedCorrection = @"
175+ function foo {
176+ [CmdletBinding(SupportsShouldProcess)]
177+ param(
178+ $s$s$s$s$s$s$s$s
179+ )
180+ }
181+ "@
182+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $def - Settings $settings
183+ $violations.Count | Should Be 1
184+ $violations [0 ].SuggestedCorrections[0 ].Text | Should Be $expectedCorrection
165185 }
166186
167- It " Suggests removing the manually added parameters" {
168-
187+ It " Suggests adding SupportsShouldProcess attribute, when arguments are present" {
188+ $def = @'
189+ function foo {
190+ [CmdletBinding(ConfirmImpact="High")]
191+ param(
192+ [bool] $confirm,
193+ [bool] $whatif
194+ )
195+ }
196+ '@
197+ $s = " "
198+ $expectedCorrection = @"
199+ function foo {
200+ [CmdletBinding(SupportsShouldProcess, ConfirmImpact="High")]
201+ param(
202+ $s$s$s$s$s$s$s$s
203+ )
204+ }
205+ "@
206+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $def - Settings $settings
207+ $violations.Count | Should Be 1
208+ $violations [0 ].SuggestedCorrections[0 ].Text | Should Be $expectedCorrection
169209 }
170210 }
171211}
0 commit comments