You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pester version 5.4.1 has a regression from 5.4.0 where Should -HaveParameter -DefaultValue no longer works for the following kinds of tests that previously passed:
Function parameter of type [int] with a default value of 0
Function parameter of type [bool] with any default value set (both $true and $false)
Sample test
Describe 'Parameter default value tests' {
BeforeAll {
functionTest-Parameter {
param (
[Parameter()]
[int]$intParam=0,
[Parameter()]
[bool]$boolTrueParam=$true,
[Parameter()]
[bool]$boolFalseParam=$false
)
}
}
It 'Default value when integer is zero' {
Get-CommandTest-Parameter| Should -HaveParameter 'intParam'-Type 'int'-DefaultValue 0
}
It 'Default value for true boolean' {
Get-CommandTest-Parameter| Should -HaveParameter 'boolTrueParam'-Type 'bool'-DefaultValue $true
}
It 'Default value for false boolean' {
Get-CommandTest-Parameter| Should -HaveParameter 'boolFalseParam'-Type 'bool'-DefaultValue $false
}
}
In Pester 5.4.0, these worked as expected:
Running tests from'C:\source\PesterBug\Test-Parameter.Tests.ps1'
Describing Parameter default value tests
[+] Default value when integer is zero 36ms (6ms|30ms)
[+] Default value for true boolean 6ms (5ms|2ms)
[+] Default value for false boolean 14ms (6ms|9ms)
Tests completed in 217ms
Tests Passed: 3, Failed: 0, Skipped: 0 NotRun: 0
In Pester 5.4.1, these fail with:
[-] Parameter default value tests.Default value for integer 8ms (7ms|1ms)
Expected command Test-Parameter to have a parameter intParam, of type [System.Int32] and the default value to be '0', but the default value was <empty>.
at Get-CommandTest-Parameter| Should -HaveParameter 'intParam'-Type 'int'-DefaultValue 0,C:\source\PesterBug\Test-Parameter.Tests.ps1:21
at <ScriptBlock>,C:\source\PesterBug\Test-Parameter.Tests.ps1:21
[-] Parameter default value tests.Default value for true boolean 17ms (16ms|1ms)
Expected command Test-Parameter to have a parameter boolTrueParam, of type [System.Boolean] and the default value to be 'True', but the default value was '$true'.
at Get-CommandTest-Parameter| Should -HaveParameter 'boolTrueParam'-Type 'bool'-DefaultValue $true,C:\source\PesterBug\Test-Parameter.Tests.ps1:25
at <ScriptBlock>,C:\source\PesterBug\Test-Parameter.Tests.ps1:25
[-] Parameter default value tests.Default value for false boolean 19ms (18ms|1ms)
Expected command Test-Parameter to have a parameter boolFalseParam, of type [System.Boolean] and the default value to be 'False', but the default value was '$false'.
at Get-CommandTest-Parameter| Should -HaveParameter 'boolFalseParam'-Type 'bool'-DefaultValue $false,C:\source\PesterBug\Test-Parameter.Tests.ps1:29
at <ScriptBlock>,C:\source\PesterBug\Test-Parameter.Tests.ps1:29
Regression
This appears to have been caused by ea70451. I used a debugger to check the value of $paramInfo in Get-ParameterInfo and it looks different when the function was changed to use the AST.
Boolean before and after
# Pester 5.4.0
Name Type DefaultValue DefaultValueType
------------------------------------
boolParam [bool] true Variable
# Pester 5.4.1
Name Type DefaultValue DefaultValueType
------------------------------------
boolParam [boolean] $true Boolean
Integer before and after
# Pester 5.4.0
Name Type DefaultValue DefaultValueType
------------------------------------
intParam [int] 0 Number
# Pester 5.4.1
Name Type DefaultValue DefaultValueType
------------------------------------
intParam [int32] 0 Int32
Expected Behavior
These kind of tests with -DefaultValue should pass.
Steps To Reproduce
See working sample test above in issue description
Describe your environment
Pester version : 5.4.1 C:\Users\phoerr\Documents\PowerShell\Modules\Pester\5.4.1\Pester.psm1
PowerShell version : 7.3.6
OS version : Microsoft Windows NT 10.0.19045.0
Possible Solution?
No response
The text was updated successfully, but these errors were encountered:
Checklist
What is the issue?
Pester version
5.4.1
has a regression from5.4.0
whereShould -HaveParameter -DefaultValue
no longer works for the following kinds of tests that previously passed:[int]
with a default value of0
[bool]
with any default value set (both$true
and$false
)Sample test
In Pester
5.4.0
, these worked as expected:In Pester
5.4.1
, these fail with:Regression
This appears to have been caused by ea70451. I used a debugger to check the value of
$paramInfo
inGet-ParameterInfo
and it looks different when the function was changed to use the AST.Boolean before and after
Integer before and after
Expected Behavior
These kind of tests with
-DefaultValue
should pass.Steps To Reproduce
See working sample test above in issue description
Describe your environment
Possible Solution?
No response
The text was updated successfully, but these errors were encountered: