Skip to content

Commit b5f9a8a

Browse files
author
Kapil Borle
committed
Add more tests
1 parent dccde57 commit b5f9a8a

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Tests/Rules/UseSupportsShouldProcess.tests.ps1

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,47 @@ function foo {
228228
$violations[0].SuggestedCorrections[0].Text | Should Be $expectedCorrection
229229
}
230230

231+
It "Suggests replacing function parameter declaration with whatif and confirm with a param block" {
232+
$def = @'
233+
function foo ($param1, $whatif, $confirm, $param2) {
234+
}
235+
'@
236+
$s = " "
237+
$expectedCorrection = @'
238+
function foo {
239+
[CmdletBinding(SupportsShouldProcess)]
240+
param(
241+
$param1,
242+
$param2
243+
)
244+
}
245+
'@
246+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
247+
$violations.Count | Should Be 1
248+
$violations[0].SuggestedCorrections[0].Text | Should Be $expectedCorrection
249+
}
250+
251+
It "Suggests replacing function parameter declaration with non-contiguous whatif and confirm with a param block" {
252+
$def = @'
253+
function foo ($param1, $whatif, $param2, $confirm) {
254+
}
255+
'@
256+
$s = " "
257+
$expectedCorrection = @'
258+
function foo {
259+
[CmdletBinding(SupportsShouldProcess)]
260+
param(
261+
$param1,
262+
$param2
263+
)
264+
}
265+
'@
266+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
267+
$violations.Count | Should Be 1
268+
$violations[0].SuggestedCorrections[0].Text | Should Be $expectedCorrection
269+
}
270+
271+
231272
}
232273

233274
}

0 commit comments

Comments
 (0)