Skip to content

Commit 5f1e045

Browse files
author
Kapil Borle
committed
Fix tests for latest PS build
1 parent 57ddda7 commit 5f1e045

18 files changed

+77
-73
lines changed

Tests/Engine/CommunityAnalyzerRules/CommunityAnalyzerRules.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ function Measure-RequiresModules
227227

228228
# The two rules in the following if block use StaticParameterBinder class.
229229
# StaticParameterBinder class was introduced in PSv4.
230-
if ($PSVersionTable.PSVersion -ge [Version]'4.0')
230+
if ($PSVersionTable.PSVersion -ge [Version]'4.0.0')
231231
{
232232
<#
233233
.SYNOPSIS

Tests/Engine/CustomizedRule.tests.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Check if PSScriptAnalyzer is already loaded so we don't
1+
2+
# Check if PSScriptAnalyzer is already loaded so we don't
23
# overwrite a test version of Invoke-ScriptAnalyzer by
34
# accident
45
if (!(Get-Module PSScriptAnalyzer) -and !$testingLibraryUsage)
@@ -195,7 +196,7 @@ Describe "Test importing correct customized rules" {
195196
$customizedRulePath.Count | Should Be 1
196197
}
197198

198-
if ($PSVersionTable.PSVersion -ge [Version]'5.0')
199+
if ($PSVersionTable.PSVersion -lt [Version]'5.0.0')
199200
{
200201
It "loads custom rules that contain version in their path" {
201202
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -CustomRulePath $directory\VersionedSampleRule\SampleRuleWithVersion

Tests/Engine/GetScriptAnalyzerRule.tests.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
1+
2+
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
23
Import-Module -Verbose PSScriptAnalyzer
34
$testRootDirectory = Split-Path -Parent $directory
45
Import-Module (Join-Path $testRootDirectory 'PSScriptAnalyzerTestHelper.psm1')
@@ -94,7 +95,7 @@ Describe "Test RuleExtension" {
9495
Context "When used correctly" {
9596

9697
$expectedNumCommunityRules = 10
97-
if ($PSVersionTable.PSVersion -ge [Version]'4.0')
98+
if ($PSVersionTable.PSVersion -ge [Version]'4.0.0')
9899
{
99100
$expectedNumCommunityRules = 12
100101
}

Tests/Engine/InvokeScriptAnalyzer.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Describe "Test available parameters" {
7373
}
7474
}
7575

76-
if (!$testingLibraryUsage -and ($PSVersionTable.PSVersion -ge [Version]'5.0'))
76+
if (!$testingLibraryUsage -and ($PSVersionTable.PSVersion -ge [Version]'5.0.0'))
7777
{
7878
Context "SaveDscDependency parameter" {
7979
It "has the parameter" {

Tests/Engine/ModuleDependencyHandler.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if ((Test-PSEditionCoreCLRLinux))
2020
}
2121

2222
# DSC Module saving is not supported in versions less than PSv5
23-
if (($PSVersionTable.PSVersion -lt [Version]'5.0'))
23+
if (($PSVersionTable.PSVersion -lt [Version]'5.0.0'))
2424
{
2525
return
2626
}

Tests/Engine/ModuleHelp.Tests.ps1

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<#
1+
<#
22
.SYNOPSIS
3-
Tests the PowerShell help for the commands in a module.
3+
Tests the PowerShell help for the commands in a module.
44
55
.DESCRIPTION
6-
This Pester test verifies that the commands in a module have basic help content.
6+
This Pester test verifies that the commands in a module have basic help content.
77
It works on all command types and both comment-based and XML help.
88
99
This test verifies that Get-Help is not autogenerating help because it cannot
@@ -21,15 +21,15 @@ When testing attributes of parameters that appear in multiple parameter sets,
2121
this test uses the parameter that appears in the default parameter set, if one
2222
is defined.
2323
24-
You can run this Tests file from any location. For a help test that is located in a module
24+
You can run this Tests file from any location. For a help test that is located in a module
2525
directory, use https://github.com/juneb/PesterTDD/InModule.Help.Tests.ps1
2626
2727
.PARAMETER ModuleName
2828
Enter the name of the module to test. You can enter only one name at a time. This
2929
parameter is mandatory.
3030
3131
.PARAMETER RequiredVersion
32-
Enter the version of the module to test. This parameter is optional. If you
32+
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
@@ -57,13 +57,13 @@ Param
5757
[ValidateScript({ Get-Module -ListAvailable -Name $_ })]
5858
[string]
5959
$ModuleName = 'PSScriptAnalyzer',
60-
60+
6161
[Parameter(Mandatory = $false)]
6262
[System.Version]
6363
$RequiredVersion
6464
)
6565

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

6868
<#
6969
.SYNOPSIS
@@ -87,16 +87,16 @@ Enter a CommandInfo object, such as the object that Get-Command returns. You
8787
can also pipe a CommandInfo object to the function.
8888
8989
This parameter takes a CommandInfo object, instead of a command name, so
90-
you can use the parameters of Get-Command to specify the module and version
90+
you can use the parameters of Get-Command to specify the module and version
9191
of the command.
9292
9393
.EXAMPLE
9494
PS C:\> Get-ParametersDefaultFirst -Command (Get-Command New-Guid)
95-
This command uses the Command parameter to specify the command to
95+
This command uses the Command parameter to specify the command to
9696
Get-ParametersDefaultFirst
9797
9898
.EXAMPLE
99-
PS C:\> Get-Command New-Guid | Get-ParametersDefaultFirst
99+
PS C:\> Get-Command New-Guid | Get-ParametersDefaultFirst
100100
You can also pipe a CommandInfo object to Get-ParametersDefaultFirst
101101
102102
.EXAMPLE
@@ -107,7 +107,7 @@ command runs Get-Command module-qualified name value.
107107
.EXAMPLE
108108
PS C:\> $ModuleSpec = @{ModuleName='BetterCredentials';RequiredVersion=4.3}
109109
PS C:\> Get-Command -FullyQualifiedName $ModuleSpec | Get-ParametersDefaultFirst
110-
This command uses a Microsoft.PowerShell.Commands.ModuleSpecification object to
110+
This command uses a Microsoft.PowerShell.Commands.ModuleSpecification object to
111111
specify the module and version. You can also use it to specify the module GUID.
112112
Then, it pipes the CommandInfo object to Get-ParametersDefaultFirst.
113113
#>
@@ -119,7 +119,7 @@ function Get-ParametersDefaultFirst {
119119
[System.Management.Automation.CommandInfo]
120120
$Command
121121
)
122-
122+
123123
BEGIN {
124124
$Common = 'Debug', 'ErrorAction', 'ErrorVariable', 'InformationAction', 'InformationVariable', 'OutBuffer', 'OutVariable', 'PipelineVariable', 'Verbose', 'WarningAction', 'WarningVariable'
125125
$parameters = @()
@@ -128,7 +128,7 @@ function Get-ParametersDefaultFirst {
128128
if ($defaultPSetName = $Command.DefaultParameterSet) {
129129
$defaultParameters = ($Command.ParameterSets | Where-Object Name -eq $defaultPSetName).parameters | Where-Object Name -NotIn $common
130130
$otherParameters = ($Command.ParameterSets | Where-Object Name -ne $defaultPSetName).parameters | Where-Object Name -NotIn $common
131-
131+
132132
$parameters = $defaultParameters
133133
if ($parameters -and $otherParameters) {
134134
$otherParameters | ForEach-Object {
@@ -142,8 +142,8 @@ function Get-ParametersDefaultFirst {
142142
else {
143143
$parameters = $Command.ParameterSets.Parameters | Where-Object Name -NotIn $common | Sort-Object Name -Unique
144144
}
145-
146-
145+
146+
147147
return $parameters
148148
}
149149
END { }
@@ -161,7 +161,7 @@ following properties:
161161
-- [string] $CommandName
162162
-- [string] $ModuleName (or PSSnapin name)
163163
-- [string] $ModuleVersion (or PowerShell Version)
164-
164+
165165
.PARAMETER CommandInfo
166166
Specifies a Commandinfo object, e.g. (Get-Command Get-Item).
167167
@@ -191,7 +191,7 @@ function Get-CommandVersion {
191191
[System.Management.Automation.CommandInfo]
192192
$CommandInfo
193193
)
194-
194+
195195
if ((-not ((($commandModuleName = $CommandInfo.Module.Name) -and ($commandVersion = $CommandInfo.Module.Version)) -or
196196
(($commandModuleName = $CommandInfo.PSSnapin) -and ($commandVersion = $CommandInfo.PSSnapin.Version))))) {
197197
Write-Error "For $($CommandInfo.Name) : Can't find PSSnapin/module name and version"
@@ -215,7 +215,7 @@ Import-Module $ModuleName -RequiredVersion $RequiredVersion -ErrorAction Stop
215215
$ms = $null
216216
$commands =$null
217217
$paramBlackList = @()
218-
if ($PSVersionTable.PSVersion -lt [Version]'5.0') {
218+
if ($PSVersionTable.PSVersion -lt [Version]'5.0.0') {
219219
$ms = New-Object -TypeName 'Microsoft.PowerShell.Commands.ModuleSpecification' -ArgumentList $ModuleName
220220
$commands = Get-Command -Module $ms.Name
221221
$paramBlackList += 'SaveDscDependency'
@@ -230,79 +230,80 @@ else {
230230

231231
foreach ($command in $commands) {
232232
$commandName = $command.Name
233-
233+
234234
# Get the module name and version of the command. Used in the Describe name.
235235
$commandModuleVersion = Get-CommandVersion -CommandInfo $command
236-
236+
237237
# The module-qualified command fails on Microsoft.PowerShell.Archive cmdlets
238238
$Help = Get-Help $ModuleName\$commandName -ErrorAction SilentlyContinue
239239
if ($Help.Synopsis -like '*`[`<CommonParameters`>`]*') {
240240
$Help = Get-Help $commandName -ErrorAction SilentlyContinue
241241
}
242-
242+
243243
Describe "Test help for $commandName in $($commandModuleVersion.ModuleName) ($($commandModuleVersion.Version))" {
244-
244+
245245
# If help is not found, synopsis in auto-generated help is the syntax diagram
246246
It "should not be auto-generated" {
247-
$Help.Synopsis | Should Not BeLike '*`[`<CommonParameters`>`]*'
247+
# Replace pester BeLike with powershell -like as pester 3.3.9 does not support BeLike
248+
$Help.Synopsis -like '*`[`<CommonParameters`>`]*' | Should Be $false
248249
}
249-
250+
250251
# Should be a description for every function
251252
It "gets description for $commandName" {
252253
$Help.Description | Should Not BeNullOrEmpty
253254
}
254-
255+
255256
# Should be at least one example
256257
It "gets example code from $commandName" {
257258
($Help.Examples.Example | Select-Object -First 1).Code | Should Not BeNullOrEmpty
258259
}
259-
260+
260261
# Should be at least one example description
261262
It "gets example help from $commandName" {
262263
($Help.Examples.Example.Remarks | Select-Object -First 1).Text | Should Not BeNullOrEmpty
263264
}
264-
265+
265266
Context "Test parameter help for $commandName" {
266-
267+
267268
$Common = 'Debug', 'ErrorAction', 'ErrorVariable', 'InformationAction', 'InformationVariable', 'OutBuffer', 'OutVariable',
268269
'PipelineVariable', 'Verbose', 'WarningAction', 'WarningVariable'
269-
270-
# Get parameters. When >1 parameter with same name,
270+
271+
# Get parameters. When >1 parameter with same name,
271272
# get parameter from the default parameter set, if any.
272273
$parameters = Get-ParametersDefaultFirst -Command $command
273-
274+
274275
$parameterNames = $parameters.Name
275276
$HelpParameterNames = $Help.Parameters.Parameter.Name | Sort-Object -Unique
276-
277+
277278
foreach ($parameter in $parameters) {
278279
if ($parameter -in $paramBlackList) {
279280
continue
280281
}
281282
$parameterName = $parameter.Name
282283
$parameterHelp = $Help.parameters.parameter | Where-Object Name -EQ $parameterName
283-
284+
284285
# Should be a description for every parameter
285286
It "gets help for parameter: $parameterName : in $commandName" {
286-
# `$parameterHelp.Description.Text | Should Not BeNullOrEmpty` fails for -Settings paramter
287+
# `$parameterHelp.Description.Text | Should Not BeNullOrEmpty` fails for -Settings paramter
287288
# without explicit [string] casting on the Text property
288289
[string]::IsNullOrEmpty($parameterHelp.Description.Text) | Should Be $false
289290
}
290-
291+
291292
# Required value in Help should match IsMandatory property of parameter
292293
It "help for $parameterName parameter in $commandName has correct Mandatory value" {
293294
$codeMandatory = $parameter.IsMandatory.toString()
294295
$parameterHelp.Required | Should Be $codeMandatory
295296
}
296-
297+
297298
# Parameter type in Help should match code
298299
It "help for $commandName has correct parameter type for $parameterName" {
299300
$codeType = $parameter.ParameterType.Name
300301
# To avoid calling Trim method on a null object.
301302
$helpType = if ($parameterHelp.parameterValue) { $parameterHelp.parameterValue.Trim() }
302-
$helpType | Should be $codeType
303+
$helpType | Should be $codeType
303304
}
304305
}
305-
306+
306307
foreach ($helpParm in $HelpParameterNames) {
307308
if ($helpParm -in $paramBlackList) {
308309
continue

Tests/Engine/RuleSuppression.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function SuppressPwdParam()
103103
}
104104

105105
Context "Rule suppression within DSC Configuration definition" {
106-
It "Suppresses rule" -skip:((Test-PSEditionCoreCLRLinux) -or ($PSVersionTable.PSVersion -ge [Version]'5.0')) {
106+
It "Suppresses rule" -skip:((Test-PSEditionCoreCLRLinux) -or ($PSVersionTable.PSVersion -ge [Version]'5.0.0')) {
107107
$suppressedRule = Invoke-ScriptAnalyzer -ScriptDefinition $ruleSuppressionInConfiguration -SuppressedOnly
108108
$suppressedRule.Count | Should Be 1
109109
}

Tests/Engine/RuleSuppressionClass.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if ($PSVersionTable.PSVersion -ge [Version]'5.0') {
1+
if ($PSVersionTable.PSVersion -ge [Version]'5.0.0') {
22

33
# Check if PSScriptAnalyzer is already loaded so we don't
44
# overwrite a test version of Invoke-ScriptAnalyzer by

Tests/PSScriptAnalyzerTestHelper.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ Function Test-CorrectionExtent
3030

3131
Function Test-PSEditionCoreCLR
3232
{
33-
($PSVersionTable.Keys -contains "PSEdition") -and ($PSVersionTable.PSEdition -ne 'Desktop')
33+
[bool]$IsCoreCLR
3434
}
3535

3636
Function Test-PSEditionCoreCLRLinux
3737
{
38-
(Test-PSEditionCoreCLR) -and ($env:OS -eq "Linux")
38+
(Test-PSEditionCoreCLR) -and $IsLinux
3939
}
4040

4141
Export-ModuleMember -Function Get-ExtentText

Tests/Rules/AvoidUnloadableModuleOrMissingRequiredFieldInManifest.tests.ps1

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,32 +59,32 @@ ModuleVersion = '1.0.0.0'
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") | Should Be $true
62+
[Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper]::IsModuleManifest($filepath, [version]"5.0.0") | Should Be $true
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") | Should Be $false
67+
[Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper]::IsModuleManifest($filepath, [version]"5.0.0") | Should Be $false
6868
}
6969

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

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

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

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

0 commit comments

Comments
 (0)