Skip to content
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

Improve error when -HaveParameter is used with mock or alias for local function #2233

Merged
merged 3 commits into from Mar 31, 2023

Conversation

fflaten
Copy link
Collaborator

@fflaten fflaten commented Aug 8, 2022

PR Summary

PowerShell doesn't resolve local functions properly for AliasInfo when function is defined in local scope in different session state. This affects use of -HaveParameter on a mocked command, ex. Get-Command Should -HaveParameter mockedCommand

Replace generic NRE with exception that suggests a workaround as this problem is unlikely to be fixed soon in PowerShell and probably not at all in Windows PowerShell.

Fix #1431

PR Checklist

  • PR has meaningful title
  • Summary describes changes
  • PR is ready to be merged
    • If not, use the arrow next to Create Pull Request to mark it as a draft. PR can be marked Ready for review when it's ready.
  • Tests are added/update (if required)
  • Documentation is updated/added (if required)

@fflaten
Copy link
Collaborator Author

fflaten commented Aug 8, 2022

Looking for feedback:

  • Throw vs failure message?
  • Should we stick with Where-Object Parameters workaround for both scenarios to keep it simple?

@fflaten fflaten changed the title Improve exception when -HaveParameter is used with mock or alias for local function Improve error when -HaveParameter is used with mock or alias for local function Aug 8, 2022
@nohwnd
Copy link
Member

nohwnd commented Oct 3, 2022

Looks good, I would start from throwing, it is better to make the user correct their test, than us having to support yet another scenario where we "guess" for the user.

@fflaten fflaten marked this pull request as ready for review October 8, 2022 12:11
@nohwnd
Copy link
Member

nohwnd commented Oct 31, 2022

Again pending comments. :/

fflaten and others added 2 commits October 31, 2022 11:40
Co-authored-by: Jakub Jareš <me@jakubjares.com>
@fflaten
Copy link
Collaborator Author

fflaten commented Nov 16, 2022

Pending #2267 to fix CI

@fflaten
Copy link
Collaborator Author

fflaten commented Dec 4, 2022

/azp run

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

@fflaten fflaten added the Bug label Mar 30, 2023
@nohwnd nohwnd merged commit 7ee7139 into pester:main Mar 31, 2023
@fflaten fflaten deleted the haveparameter-mock branch March 31, 2023 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should -HaveParameter yields a RunTime exception when used on a mocked function
2 participants