Skip to content

Commit

Permalink
It still does not work for false, true, or , but I feel better about …
Browse files Browse the repository at this point in the history
…it :D
  • Loading branch information
nohwnd committed Oct 16, 2023
1 parent 65342c4 commit 3affeb7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/functions/assertions/HaveParameter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,14 @@
# That is: param($param1 = $false) will set this to true for $param1
# but param($param1) will have this set to false, because there was no default value.
$paramInfo.HasDefaultValue = $true
# $null does not have a Value
$paramInfo.DefaultValue = if ($null -ne $parameter.DefaultValue.Value) { $parameter.DefaultValue.Value } else { $parameter.DefaulValue.Extent }
# When the value has a known fully realized value (indicated by .Value being on the DefaultValue object)
# we take that and use it, otherwise we take the extent (how it was written in code). This will make
# 1, 2, or "abc", appear as 1, 2, abc to the assertion, but (Get-Date) will be (Get-Date).
$paramInfo.DefaultValue = if ($parameter.DefaultValue.PSObject.Properties["Value"]) { $parameter.DefaultValue.Value } else { $parameter.DefaultValue.Extent.Text }
}

$paramInfo
break
}
}

Expand Down
4 changes: 2 additions & 2 deletions tst/functions/assertions/HaveParameter.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ InPesterModuleScope {
param(
[Parameter(Mandatory = $true, ParameterSetName = 'PrimarySet')]
[Alias('First', 'Another')]
$MandatoryParam,
$MandatoryParam = "",

[Parameter(ParameterSetName = 'PrimarySet')]
[ValidateNotNullOrEmpty()]
Expand Down Expand Up @@ -65,7 +65,7 @@ InPesterModuleScope {
param(
[Parameter(Mandatory = $true, ParameterSetName = 'PrimarySet')]
[Alias('First', 'Another')]
$MandatoryParam,
$MandatoryParam = "",

[Parameter(ParameterSetName = 'PrimarySet')]
[ValidateNotNullOrEmpty()]
Expand Down

0 comments on commit 3affeb7

Please sign in to comment.