Skip to content

Update from Pester 4.1.1 to 4.3.1 and use new -BeTrue and -BeFalse operators #906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ For adding/removing resource strings in the `*.resx` files, it is recommended to
#### Tests
Pester-based ScriptAnalyzer Tests are located in `path/to/PSScriptAnalyzer/Tests` folder.

* Ensure Pester 4.1.1 is installed on the machine
* Ensure [Pester 4.3.1](https://www.powershellgallery.com/packages/Pester/4.3.1) is installed
* Copy `path/to/PSScriptAnalyzer/out/PSScriptAnalyzer` to a folder in `PSModulePath`
* Go the Tests folder in your local repository
* Run Engine Tests:
Expand Down
8 changes: 4 additions & 4 deletions Tests/Engine/Extensions.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Describe "AttributeAst extension methods" {
param($param1, $param2)
}}.Ast.EndBlock.Statements[0]
$extNamespace::IsCmdletBindingAttributeAst($funcDefnAst.Body.ParamBlock.Attributes[0]) |
Should -Be $true
Should -BeTrue
}
}

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

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

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

}
Expand Down
6 changes: 3 additions & 3 deletions Tests/Engine/GetScriptAnalyzerRule.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Describe "Test available parameters" {
$params = $sa.Parameters
Context "Name parameter" {
It "has a RuleName parameter" {
$params.ContainsKey("Name") | Should -Be $true
$params.ContainsKey("Name") | Should -BeTrue
}

It "accepts string" {
Expand All @@ -24,15 +24,15 @@ Describe "Test available parameters" {

Context "RuleExtension parameters" {
It "has a RuleExtension parameter" {
$params.ContainsKey("CustomRulePath") | Should -Be $true
$params.ContainsKey("CustomRulePath") | Should -BeTrue
}

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

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

Expand Down
6 changes: 3 additions & 3 deletions Tests/Engine/Helper.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ Describe "Test Directed Graph" {
It "correctly adds the edges" {
$digraph.GetOutDegree('v1') | Should -Be 2
$neighbors = $digraph.GetNeighbors('v1')
$neighbors -contains 'v2' | Should -Be $true
$neighbors -contains 'v5' | Should -Be $true
$neighbors -contains 'v2' | Should -BeTrue
$neighbors -contains 'v5' | Should -BeTrue
}

It "finds the connection" {
$digraph.IsConnected('v1', 'v4') | Should -Be $true
$digraph.IsConnected('v1', 'v4') | Should -BeTrue
}
}
}
26 changes: 13 additions & 13 deletions Tests/Engine/InvokeScriptAnalyzer.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Describe "Test available parameters" {
$params = $sa.Parameters
Context "Path parameter" {
It "has a Path parameter" {
$params.ContainsKey("Path") | Should -Be $true
$params.ContainsKey("Path") | Should -BeTrue
}

It "accepts string" {
Expand All @@ -31,7 +31,7 @@ Describe "Test available parameters" {

Context "Path parameter" {
It "has a ScriptDefinition parameter" {
$params.ContainsKey("ScriptDefinition") | Should -Be $true
$params.ContainsKey("ScriptDefinition") | Should -BeTrue
}

It "accepts string" {
Expand All @@ -41,21 +41,21 @@ Describe "Test available parameters" {

Context "CustomRulePath parameters" {
It "has a CustomRulePath parameter" {
$params.ContainsKey("CustomRulePath") | Should -Be $true
$params.ContainsKey("CustomRulePath") | Should -BeTrue
}

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

It "has a CustomizedRulePath alias"{
$params.CustomRulePath.Aliases.Contains("CustomizedRulePath") | Should -Be $true
$params.CustomRulePath.Aliases.Contains("CustomizedRulePath") | Should -BeTrue
}
}

Context "IncludeRule parameters" {
It "has an IncludeRule parameter" {
$params.ContainsKey("IncludeRule") | Should -Be $true
$params.ContainsKey("IncludeRule") | Should -BeTrue
}

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

Context "Severity parameters" {
It "has a severity parameters" {
$params.ContainsKey("Severity") | Should -Be $true
$params.ContainsKey("Severity") | Should -BeTrue
}

It "accepts string array" {
Expand All @@ -77,7 +77,7 @@ Describe "Test available parameters" {
{
Context "SaveDscDependency parameter" {
It "has the parameter" {
$params.ContainsKey("SaveDscDependency") | Should -Be $true
$params.ContainsKey("SaveDscDependency") | Should -BeTrue
}

It "is a switch parameter" {
Expand All @@ -100,7 +100,7 @@ Describe "Test available parameters" {
}
}

$hasFile | Should -Be $true
$hasFile | Should -BeTrue
}

It "Has ScriptDefinition parameter set" {
Expand All @@ -112,7 +112,7 @@ Describe "Test available parameters" {
}
}

$hasFile | Should -Be $true
$hasFile | Should -BeTrue
}

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

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

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

It "Analyzes all the files" {
Expand All @@ -209,7 +209,7 @@ Describe "Test Path" {
Write-Output $globalVarsViolation.Count
Write-Output $clearHostViolation.Count
Write-Output $writeHostViolation.Count
$globalVarsViolation.Count -eq 1 -and $writeHostViolation.Count -eq 1 | Should -Be $true
$globalVarsViolation.Count -eq 1 -and $writeHostViolation.Count -eq 1 | Should -BeTrue
}
}
}
Expand All @@ -231,7 +231,7 @@ Describe "Test ExcludeRule" {
It "does not exclude any rules" {
$noExclude = Invoke-ScriptAnalyzer $directory\..\Rules\BadCmdlet.ps1
$withExclude = Invoke-ScriptAnalyzer $directory\..\Rules\BadCmdlet.ps1 -ExcludeRule "This is a wrong rule"
$withExclude.Count -eq $noExclude.Count | Should -Be $true
$withExclude.Count -eq $noExclude.Count | Should -BeTrue
}
}

Expand Down
8 changes: 4 additions & 4 deletions Tests/Engine/ModuleHelp.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ Enter the version of the module to test. This parameter is optional. If you
omit it, the test runs on the latest version of the module in $env:PSModulePath.

.EXAMPLE
.\Module.Help.Tests.ps1 -ModuleName Pester -RequiredVersion 4.1.1
This command runs the tests on the commands in Pester 4.1.1.
.\Module.Help.Tests.ps1 -ModuleName Pester -RequiredVersion 4.3.1
This command runs the tests on the commands in Pester 4.3.1.

.EXAMPLE
.\Module.Help.Tests.ps1 -ModuleName Pester
Expand Down Expand Up @@ -63,7 +63,7 @@ Param
$RequiredVersion
)

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

<#
.SYNOPSIS
Expand Down Expand Up @@ -310,7 +310,7 @@ foreach ($command in $commands) {
}
# Shouldn't find extra parameters in help.
It "finds help parameter in code: $helpParm" {
$helpParm -in $parameterNames | Should -Be $true
$helpParm -in $parameterNames | Should -BeTrue
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/Engine/Settings.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Describe "Settings Class" {
}

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

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

$settings = New-Object -TypeName $settingsTypeName -ArgumentList $settingsHashtable
$settings."$paramName" | Should -Be $true
$settings."$paramName" | Should -BeTrue
}

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

$settings = New-Object -TypeName $settingsTypeName -ArgumentList $settingsHashtable
$settings."$paramName" | Should -Be $false
$settings."$paramName" | Should -BeFalse
}

It "Should throw if a non-boolean value is given" {
Expand All @@ -183,7 +183,7 @@ Describe "Settings Class" {
It "Should detect the parameter in a settings file" {
$settings = New-Object -TypeName $settingsTypeName `
-ArgumentList ([System.IO.Path]::Combine($project1Root, "CustomRulePathSettings.psd1"))
$settings."$paramName" | Should -Be $true
$settings."$paramName" | Should -BeTrue
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Engine/SettingsTest/Issue828/Issue828.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ Describe "Issue 828: No NullReferenceExceptionin AlignAssignmentStatement rule w
Set-Location $initialLocation
}

$cmdletThrewError | Should -Be $false
$cmdletThrewError | Should -BeFalse
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,39 +52,39 @@ ModuleVersion = '1.0.0.0'

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

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

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

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

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ cache:
install:
- ps: nuget install platyPS -Version 0.9.0 -source https://www.powershellgallery.com/api/v2 -outputDirectory "$Env:ProgramFiles\WindowsPowerShell\Modules\." -ExcludeVersion
- ps: |
$requiredPesterVersion = '4.1.1'
$requiredPesterVersion = '4.3.1'
$pester = Get-Module Pester -ListAvailable | Where-Object { $_.Version -eq $requiredPesterVersion }
$pester
if ($null -eq $pester)
Expand Down
2 changes: 1 addition & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ if ($Install)

if ($Test)
{
Import-Module -Name Pester -MinimumVersion 4.1.1 -ErrorAction Stop
Import-Module -Name Pester -MinimumVersion 4.3.1 -ErrorAction Stop
Function GetTestRunnerScriptContent($testPath)
{
$x = @"
Expand Down