Skip to content

Commit 06141fc

Browse files
liamjpetersandyleejordan
authored andcommitted
Amend tests to consider process block
1 parent a379e1f commit 06141fc

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

Tests/Rules/ReviewUnusedParameter.tests.ps1

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,26 @@ Describe "ReviewUnusedParameter" {
2020
$Violations.Count | Should -Be 2
2121
}
2222

23-
It "has 1 violation - function with 1 parameter with ValueFromPipeline set to false and `$_ usage" {
24-
$ScriptDefinition = 'function BadFunc1 { param ([Parameter(ValueFromPipeline = $false)] $Param1) $_}'
23+
It "has 1 violation - function with 1 parameter with ValueFromPipeline set to false and `$_ usage inside process block" {
24+
$ScriptDefinition = 'function BadFunc1 { param ([Parameter(ValueFromPipeline = $false)] $Param1) process {$_}}'
2525
$Violations = Invoke-ScriptAnalyzer -ScriptDefinition $ScriptDefinition -IncludeRule $RuleName
2626
$Violations.Count | Should -Be 1
2727
}
2828

29-
It "has 1 violation - function with 1 parameter with ValueFromPipeline set to false and `$PSItem usage" {
30-
$ScriptDefinition = 'function BadFunc1 { param ([Parameter(ValueFromPipeline = $false)] $Param1) $PSItem}'
29+
It "has 1 violation - function with 1 parameter with ValueFromPipeline set to false and `$PSItem usage inside process block" {
30+
$ScriptDefinition = 'function BadFunc1 { param ([Parameter(ValueFromPipeline = $false)] $Param1) process {$PSItem}}'
31+
$Violations = Invoke-ScriptAnalyzer -ScriptDefinition $ScriptDefinition -IncludeRule $RuleName
32+
$Violations.Count | Should -Be 1
33+
}
34+
35+
It "has 1 violation - function with 1 parameter with ValueFromPipeline set to true and `$_ usage outside process block" {
36+
$ScriptDefinition = 'function BadFunc1 { param ([Parameter(ValueFromPipeline = $true)] $Param1) $_}'
37+
$Violations = Invoke-ScriptAnalyzer -ScriptDefinition $ScriptDefinition -IncludeRule $RuleName
38+
$Violations.Count | Should -Be 1
39+
}
40+
41+
It "has 1 violation - function with 1 parameter with ValueFromPipeline set to true and `$PSItem usage outside process block" {
42+
$ScriptDefinition = 'function BadFunc1 { param ([Parameter(ValueFromPipeline = $true)] $Param1) $PSItem}'
3143
$Violations = Invoke-ScriptAnalyzer -ScriptDefinition $ScriptDefinition -IncludeRule $RuleName
3244
$Violations.Count | Should -Be 1
3345
}
@@ -71,26 +83,26 @@ Describe "ReviewUnusedParameter" {
7183
$Violations.Count | Should -Be 0
7284
}
7385

74-
It "has no violation - function with 1 parameter with ValueFromPipeline explictly set to true and `$_ usage" {
75-
$ScriptDefinition = 'function BadFunc1 { param ([Parameter(ValueFromPipeline = $true)] $Param1) $_}'
86+
It "has no violation - function with 1 parameter with ValueFromPipeline explictly set to true and `$_ usage inside process block" {
87+
$ScriptDefinition = 'function BadFunc1 { param ([Parameter(ValueFromPipeline = $true)] $Param1) process {$_}}'
7688
$Violations = Invoke-ScriptAnalyzer -ScriptDefinition $ScriptDefinition -IncludeRule $RuleName
7789
$Violations.Count | Should -Be 0
7890
}
7991

80-
It "has no violation - function with 1 parameter with ValueFromPipeline explictly set to true and `$PSItem usage" {
81-
$ScriptDefinition = 'function BadFunc1 { param ([Parameter(ValueFromPipeline = $true)] $Param1) $PSItem}'
92+
It "has no violation - function with 1 parameter with ValueFromPipeline explictly set to true and `$PSItem usage inside process block" {
93+
$ScriptDefinition = 'function BadFunc1 { param ([Parameter(ValueFromPipeline = $true)] $Param1) process {$PSItem}}'
8294
$Violations = Invoke-ScriptAnalyzer -ScriptDefinition $ScriptDefinition -IncludeRule $RuleName
8395
$Violations.Count | Should -Be 0
8496
}
8597

86-
It "has no violation - function with 1 parameter with ValueFromPipeline implicitly set to true and `$_ usage" {
87-
$ScriptDefinition = 'function BadFunc1 { param ([Parameter(ValueFromPipeline)] $Param1) $_}'
98+
It "has no violation - function with 1 parameter with ValueFromPipeline implicitly set to true and `$_ usage inside process block" {
99+
$ScriptDefinition = 'function BadFunc1 { param ([Parameter(ValueFromPipeline)] $Param1) process{$_}}'
88100
$Violations = Invoke-ScriptAnalyzer -ScriptDefinition $ScriptDefinition -IncludeRule $RuleName
89101
$Violations.Count | Should -Be 0
90102
}
91103

92-
It "has no violation - function with 1 parameter with ValueFromPipeline implicitly set to true and `$PSItem usage" {
93-
$ScriptDefinition = 'function BadFunc1 { param ([Parameter(ValueFromPipeline)] $Param1) $PSItem}'
104+
It "has no violation - function with 1 parameter with ValueFromPipeline implicitly set to true and `$PSItem usage inside process block" {
105+
$ScriptDefinition = 'function BadFunc1 { param ([Parameter(ValueFromPipeline)] $Param1) process{$PSItem}}'
94106
$Violations = Invoke-ScriptAnalyzer -ScriptDefinition $ScriptDefinition -IncludeRule $RuleName
95107
$Violations.Count | Should -Be 0
96108
}

0 commit comments

Comments
 (0)