-
-
Notifications
You must be signed in to change notification settings - Fork 467
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
Should -HaveParameter should check DefaultParameterType #1888
Comments
@lipkau ^^^ would you consider PRing it? 🙂 |
I'll pick this up. |
To clarify, do we want to require Describe 'd' {
It 'i' {
function myDefault { 'my\default' }
function myFunc {
param(
[string]$MyParam = '(myDefault)'
)
}
# This should work
Get-Command myFunc | Should -HaveParameter MyParam -DefaultValue {(myDefault)}
# This shouldn't
Get-Command myFunc | Should -HaveParameter MyParam -DefaultValue '(myDefault)'
}
} We still end up comparing them as strings, so it would mostly be for the optics right? If so, is it worth the breaking change? Am I missing something? Would likely have to trim the scriptblock-text since formatter in VSCode likes to add whitespace between curly-braces and content in |
I think I just meant that we will always compare them as strings, but we will have additional -DefaultValueType parameter which can would be the actual type of the default value: $Path = (Get-DefaultPath) == -DefaultValue "(Get-DefaultPath)" and -DefaultValueType ScriptBlock (or whatever is the name of the type on the default value, is that Expression?) |
Default parameter type is figured out in the code, but parameter for it is not surfaced to Should which is unfortunate when you check
$Path = (Get-DefaultPath)
because our assertion will pass for both$Path = (Get-DefaultPath)
and$Path = "(Get-DefaultPath)"
.But if the DefaultValueType was surfaced then we could say the the value should be Expression, not a string, and we would be able to distinguish those two.
The text was updated successfully, but these errors were encountered: