Skip to content

Commit bdb8707

Browse files
bergmeisterJamesWTruher
authored andcommitted
Update from Pester 4.1.1 to 4.3.1 and use new -BeTrue and -BeFalse operators (#906)
* upgrade from pester v 4.1.1 to 4.3.1 and use new -BeTrue and -BeFalse assertions and remove deprecated Should -Not -Throw calls * update pester version in other files as well * Use dash for -BeTrue and -BeFalse operators.
1 parent 6aeb4f6 commit bdb8707

11 files changed

+42
-42
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ For adding/removing resource strings in the `*.resx` files, it is recommended to
129129
#### Tests
130130
Pester-based ScriptAnalyzer Tests are located in `path/to/PSScriptAnalyzer/Tests` folder.
131131

132-
* Ensure Pester 4.1.1 is installed on the machine
132+
* Ensure [Pester 4.3.1](https://www.powershellgallery.com/packages/Pester/4.3.1) is installed
133133
* Copy `path/to/PSScriptAnalyzer/out/PSScriptAnalyzer` to a folder in `PSModulePath`
134134
* Go the Tests folder in your local repository
135135
* Run Engine Tests:

Tests/Engine/Extensions.tests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Describe "AttributeAst extension methods" {
118118
param($param1, $param2)
119119
}}.Ast.EndBlock.Statements[0]
120120
$extNamespace::IsCmdletBindingAttributeAst($funcDefnAst.Body.ParamBlock.Attributes[0]) |
121-
Should -Be $true
121+
Should -BeTrue
122122
}
123123
}
124124

@@ -145,7 +145,7 @@ Describe "NamedAttributeArgumentAst" {
145145
param($param1, $param2)
146146
}}.Ast.EndBlock.Statements[0].Body.ParamBlock.Attributes[0].NamedArguments[0]
147147
$expressionAst = $null
148-
$extNamespace::GetValue($attrAst, [ref]$expressionAst) | Should -Be $true
148+
$extNamespace::GetValue($attrAst, [ref]$expressionAst) | Should -BeTrue
149149
$expressionAst | Should -Be $null
150150
}
151151

@@ -156,7 +156,7 @@ Describe "NamedAttributeArgumentAst" {
156156
param($param1, $param2)
157157
}}.Ast.EndBlock.Statements[0].Body.ParamBlock.Attributes[0].NamedArguments[0]
158158
$expressionAst = $null
159-
$extNamespace::GetValue($attrAst, [ref]$expressionAst) | Should -Be $true
159+
$extNamespace::GetValue($attrAst, [ref]$expressionAst) | Should -BeTrue
160160
$expressionAst | Should -Not -Be $null
161161
}
162162

@@ -167,7 +167,7 @@ Describe "NamedAttributeArgumentAst" {
167167
param($param1, $param2)
168168
}}.Ast.EndBlock.Statements[0].Body.ParamBlock.Attributes[0].NamedArguments[0]
169169
$expressionAst = $null
170-
$extNamespace::GetValue($attrAst, [ref]$expressionAst) | Should -Be $false
170+
$extNamespace::GetValue($attrAst, [ref]$expressionAst) | Should -BeFalse
171171
$expressionAst | Should -Not -Be $null
172172

173173
}

Tests/Engine/GetScriptAnalyzerRule.tests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Describe "Test available parameters" {
1414
$params = $sa.Parameters
1515
Context "Name parameter" {
1616
It "has a RuleName parameter" {
17-
$params.ContainsKey("Name") | Should -Be $true
17+
$params.ContainsKey("Name") | Should -BeTrue
1818
}
1919

2020
It "accepts string" {
@@ -24,15 +24,15 @@ Describe "Test available parameters" {
2424

2525
Context "RuleExtension parameters" {
2626
It "has a RuleExtension parameter" {
27-
$params.ContainsKey("CustomRulePath") | Should -Be $true
27+
$params.ContainsKey("CustomRulePath") | Should -BeTrue
2828
}
2929

3030
It "accepts string array" {
3131
$params["CustomRulePath"].ParameterType.FullName | Should -Be "System.String[]"
3232
}
3333

3434
It "takes CustomizedRulePath parameter as an alias of CustomRulePath parameter" {
35-
$params.CustomRulePath.Aliases.Contains("CustomizedRulePath") | Should -Be $true
35+
$params.CustomRulePath.Aliases.Contains("CustomizedRulePath") | Should -BeTrue
3636
}
3737
}
3838

Tests/Engine/Helper.tests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ Describe "Test Directed Graph" {
2020
It "correctly adds the edges" {
2121
$digraph.GetOutDegree('v1') | Should -Be 2
2222
$neighbors = $digraph.GetNeighbors('v1')
23-
$neighbors -contains 'v2' | Should -Be $true
24-
$neighbors -contains 'v5' | Should -Be $true
23+
$neighbors -contains 'v2' | Should -BeTrue
24+
$neighbors -contains 'v5' | Should -BeTrue
2525
}
2626

2727
It "finds the connection" {
28-
$digraph.IsConnected('v1', 'v4') | Should -Be $true
28+
$digraph.IsConnected('v1', 'v4') | Should -BeTrue
2929
}
3030
}
3131
}

Tests/Engine/InvokeScriptAnalyzer.tests.ps1

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Describe "Test available parameters" {
2121
$params = $sa.Parameters
2222
Context "Path parameter" {
2323
It "has a Path parameter" {
24-
$params.ContainsKey("Path") | Should -Be $true
24+
$params.ContainsKey("Path") | Should -BeTrue
2525
}
2626

2727
It "accepts string" {
@@ -31,7 +31,7 @@ Describe "Test available parameters" {
3131

3232
Context "Path parameter" {
3333
It "has a ScriptDefinition parameter" {
34-
$params.ContainsKey("ScriptDefinition") | Should -Be $true
34+
$params.ContainsKey("ScriptDefinition") | Should -BeTrue
3535
}
3636

3737
It "accepts string" {
@@ -41,21 +41,21 @@ Describe "Test available parameters" {
4141

4242
Context "CustomRulePath parameters" {
4343
It "has a CustomRulePath parameter" {
44-
$params.ContainsKey("CustomRulePath") | Should -Be $true
44+
$params.ContainsKey("CustomRulePath") | Should -BeTrue
4545
}
4646

4747
It "accepts a string array" {
4848
$params["CustomRulePath"].ParameterType.FullName | Should -Be "System.String[]"
4949
}
5050

5151
It "has a CustomizedRulePath alias"{
52-
$params.CustomRulePath.Aliases.Contains("CustomizedRulePath") | Should -Be $true
52+
$params.CustomRulePath.Aliases.Contains("CustomizedRulePath") | Should -BeTrue
5353
}
5454
}
5555

5656
Context "IncludeRule parameters" {
5757
It "has an IncludeRule parameter" {
58-
$params.ContainsKey("IncludeRule") | Should -Be $true
58+
$params.ContainsKey("IncludeRule") | Should -BeTrue
5959
}
6060

6161
It "accepts string array" {
@@ -65,7 +65,7 @@ Describe "Test available parameters" {
6565

6666
Context "Severity parameters" {
6767
It "has a severity parameters" {
68-
$params.ContainsKey("Severity") | Should -Be $true
68+
$params.ContainsKey("Severity") | Should -BeTrue
6969
}
7070

7171
It "accepts string array" {
@@ -77,7 +77,7 @@ Describe "Test available parameters" {
7777
{
7878
Context "SaveDscDependency parameter" {
7979
It "has the parameter" {
80-
$params.ContainsKey("SaveDscDependency") | Should -Be $true
80+
$params.ContainsKey("SaveDscDependency") | Should -BeTrue
8181
}
8282

8383
It "is a switch parameter" {
@@ -100,7 +100,7 @@ Describe "Test available parameters" {
100100
}
101101
}
102102

103-
$hasFile | Should -Be $true
103+
$hasFile | Should -BeTrue
104104
}
105105

106106
It "Has ScriptDefinition parameter set" {
@@ -112,7 +112,7 @@ Describe "Test available parameters" {
112112
}
113113
}
114114

115-
$hasFile | Should -Be $true
115+
$hasFile | Should -BeTrue
116116
}
117117

118118
}
@@ -132,7 +132,7 @@ Describe "Test Path" {
132132
It "Has the same effect as without Path parameter" {
133133
$withPath = Invoke-ScriptAnalyzer $directory\TestScript.ps1
134134
$withoutPath = Invoke-ScriptAnalyzer -Path $directory\TestScript.ps1
135-
$withPath.Count -eq $withoutPath.Count | Should -Be $true
135+
$withPath.Count -eq $withoutPath.Count | Should -BeTrue
136136
}
137137

138138
It "Does not run rules on script with more than 10 parser errors" {
@@ -199,7 +199,7 @@ Describe "Test Path" {
199199
$withPathWithDirectory = Invoke-ScriptAnalyzer -Recurse -Path $directory\RecursionDirectoryTest
200200

201201
It "Has the same count as without Path parameter"{
202-
$withoutPathWithDirectory.Count -eq $withPathWithDirectory.Count | Should -Be $true
202+
$withoutPathWithDirectory.Count -eq $withPathWithDirectory.Count | Should -BeTrue
203203
}
204204

205205
It "Analyzes all the files" {
@@ -209,7 +209,7 @@ Describe "Test Path" {
209209
Write-Output $globalVarsViolation.Count
210210
Write-Output $clearHostViolation.Count
211211
Write-Output $writeHostViolation.Count
212-
$globalVarsViolation.Count -eq 1 -and $writeHostViolation.Count -eq 1 | Should -Be $true
212+
$globalVarsViolation.Count -eq 1 -and $writeHostViolation.Count -eq 1 | Should -BeTrue
213213
}
214214
}
215215
}
@@ -231,7 +231,7 @@ Describe "Test ExcludeRule" {
231231
It "does not exclude any rules" {
232232
$noExclude = Invoke-ScriptAnalyzer $directory\..\Rules\BadCmdlet.ps1
233233
$withExclude = Invoke-ScriptAnalyzer $directory\..\Rules\BadCmdlet.ps1 -ExcludeRule "This is a wrong rule"
234-
$withExclude.Count -eq $noExclude.Count | Should -Be $true
234+
$withExclude.Count -eq $noExclude.Count | Should -BeTrue
235235
}
236236
}
237237

Tests/Engine/ModuleHelp.Tests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ Enter the version of the module to test. This parameter is optional. If you
3333
omit it, the test runs on the latest version of the module in $env:PSModulePath.
3434
3535
.EXAMPLE
36-
.\Module.Help.Tests.ps1 -ModuleName Pester -RequiredVersion 4.1.1
37-
This command runs the tests on the commands in Pester 4.1.1.
36+
.\Module.Help.Tests.ps1 -ModuleName Pester -RequiredVersion 4.3.1
37+
This command runs the tests on the commands in Pester 4.3.1.
3838
3939
.EXAMPLE
4040
.\Module.Help.Tests.ps1 -ModuleName Pester
@@ -63,7 +63,7 @@ Param
6363
$RequiredVersion
6464
)
6565

66-
# #Requires -Module @{ModuleName = 'Pester'; ModuleVersion = '4.1.1'}
66+
# #Requires -Module @{ModuleName = 'Pester'; ModuleVersion = '4.3.1'}
6767

6868
<#
6969
.SYNOPSIS
@@ -310,7 +310,7 @@ foreach ($command in $commands) {
310310
}
311311
# Shouldn't find extra parameters in help.
312312
It "finds help parameter in code: $helpParm" {
313-
$helpParm -in $parameterNames | Should -Be $true
313+
$helpParm -in $parameterNames | Should -BeTrue
314314
}
315315
}
316316
}

Tests/Engine/Settings.tests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Describe "Settings Class" {
111111
}
112112

113113
It "Should parse boolean type argument" {
114-
$settings.RuleArguments["PSUseConsistentIndentation"]["Enable"] | Should -Be $true
114+
$settings.RuleArguments["PSUseConsistentIndentation"]["Enable"] | Should -BeTrue
115115
}
116116

117117
It "Should parse int type argument" {
@@ -162,15 +162,15 @@ Describe "Settings Class" {
162162
$settingsHashtable.Add($paramName, $true)
163163

164164
$settings = New-Object -TypeName $settingsTypeName -ArgumentList $settingsHashtable
165-
$settings."$paramName" | Should -Be $true
165+
$settings."$paramName" | Should -BeTrue
166166
}
167167

168168
It "Should correctly set the value if a boolean is given - false" {
169169
$settingsHashtable = @{}
170170
$settingsHashtable.Add($paramName, $false)
171171

172172
$settings = New-Object -TypeName $settingsTypeName -ArgumentList $settingsHashtable
173-
$settings."$paramName" | Should -Be $false
173+
$settings."$paramName" | Should -BeFalse
174174
}
175175

176176
It "Should throw if a non-boolean value is given" {
@@ -183,7 +183,7 @@ Describe "Settings Class" {
183183
It "Should detect the parameter in a settings file" {
184184
$settings = New-Object -TypeName $settingsTypeName `
185185
-ArgumentList ([System.IO.Path]::Combine($project1Root, "CustomRulePathSettings.psd1"))
186-
$settings."$paramName" | Should -Be $true
186+
$settings."$paramName" | Should -BeTrue
187187
}
188188
}
189189
}

Tests/Engine/SettingsTest/Issue828/Issue828.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ Describe "Issue 828: No NullReferenceExceptionin AlignAssignmentStatement rule w
2222
Set-Location $initialLocation
2323
}
2424

25-
$cmdletThrewError | Should -Be $false
25+
$cmdletThrewError | Should -BeFalse
2626
}
2727
}

Tests/Rules/AvoidUnloadableModuleOrMissingRequiredFieldInManifest.tests.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,39 +52,39 @@ ModuleVersion = '1.0.0.0'
5252

5353
Context "When an .psd1 file doesn't contain a hashtable" {
5454
It "does not throw exception" {
55-
{Invoke-ScriptAnalyzer -Path $noHashtableFilepath -IncludeRule $missingMemberRuleName} | Should -Not -Throw
55+
Invoke-ScriptAnalyzer -Path $noHashtableFilepath -IncludeRule $missingMemberRuleName
5656
}
5757
}
5858

5959
Context "Validate the contents of a .psd1 file" {
6060
It "detects a valid module manifest file" {
6161
$filepath = Join-Path $directory "TestManifest/ManifestGood.psd1"
62-
[Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper]::IsModuleManifest($filepath, [version]"5.0.0") | Should -Be $true
62+
[Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper]::IsModuleManifest($filepath, [version]"5.0.0") | Should -BeTrue
6363
}
6464

6565
It "detects a .psd1 file which is not module manifest" {
6666
$filepath = Join-Path $directory "TestManifest/PowerShellDataFile.psd1"
67-
[Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper]::IsModuleManifest($filepath, [version]"5.0.0") | Should -Be $false
67+
[Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper]::IsModuleManifest($filepath, [version]"5.0.0") | Should -BeFalse
6868
}
6969

7070
It "detects valid module manifest file for PSv5" {
7171
$filepath = Join-Path $directory "TestManifest/ManifestGoodPsv5.psd1"
72-
[Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper]::IsModuleManifest($filepath, [version]"5.0.0") | Should -Be $true
72+
[Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper]::IsModuleManifest($filepath, [version]"5.0.0") | Should -BeTrue
7373
}
7474

7575
It "does not validate PSv5 module manifest file for PSv3 check" {
7676
$filepath = Join-Path $directory "TestManifest/ManifestGoodPsv5.psd1"
77-
[Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper]::IsModuleManifest($filepath, [version]"3.0.0") | Should -Be $false
77+
[Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper]::IsModuleManifest($filepath, [version]"3.0.0") | Should -BeFalse
7878
}
7979

8080
It "detects valid module manifest file for PSv4" {
8181
$filepath = Join-Path $directory "TestManifest/ManifestGoodPsv4.psd1"
82-
[Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper]::IsModuleManifest($filepath, [version]"4.0.0") | Should -Be $true
82+
[Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper]::IsModuleManifest($filepath, [version]"4.0.0") | Should -BeTrue
8383
}
8484

8585
It "detects valid module manifest file for PSv3" {
8686
$filepath = Join-Path $directory "TestManifest/ManifestGoodPsv3.psd1"
87-
[Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper]::IsModuleManifest($filepath, [version]"3.0.0") | Should -Be $true
87+
[Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper]::IsModuleManifest($filepath, [version]"3.0.0") | Should -BeTrue
8888
}
8989
}
9090

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ cache:
1919
install:
2020
- ps: nuget install platyPS -Version 0.9.0 -source https://www.powershellgallery.com/api/v2 -outputDirectory "$Env:ProgramFiles\WindowsPowerShell\Modules\." -ExcludeVersion
2121
- ps: |
22-
$requiredPesterVersion = '4.1.1'
22+
$requiredPesterVersion = '4.3.1'
2323
$pester = Get-Module Pester -ListAvailable | Where-Object { $_.Version -eq $requiredPesterVersion }
2424
$pester
2525
if ($null -eq $pester)

build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ if ($Install)
132132

133133
if ($Test)
134134
{
135-
Import-Module -Name Pester -MinimumVersion 4.1.1 -ErrorAction Stop
135+
Import-Module -Name Pester -MinimumVersion 4.3.1 -ErrorAction Stop
136136
Function GetTestRunnerScriptContent($testPath)
137137
{
138138
$x = @"

0 commit comments

Comments
 (0)