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

Fix function definition in parameter filter #1293

Merged
merged 7 commits into from
May 1, 2019
Merged

Fix function definition in parameter filter #1293

merged 7 commits into from
May 1, 2019

Conversation

clcaldwell
Copy link
Contributor

1. Fix bug where function definition ( ${function:} ) pass to -ParameterFilter breaks upon AST.

Fix #1291

This is a small fix to to the 'New-BlockWithoutParameterAliases' function. When a function definition was passed to -ParameterFilter and internally passed to 'New-BlockWithoutParameterAliases', the AST would fail because it was expecting a true scriptblock, so the AST was in a different location than expected.

It now checks to see if the passed scriptblock is a FunctionDefinitionAst or ScriptBlockAst and handles the AST appropriately.

Tests included.

@nohwnd nohwnd requested a review from renehernandez April 23, 2019 08:17
Functions/Mock.ps1 Outdated Show resolved Hide resolved
Copy link
Contributor

@renehernandez renehernandez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clcaldwell Thanks for adding the implementation. As @nohwnd mentioned before just change the block variable case

Functions/Mock.ps1 Outdated Show resolved Hide resolved
Describe 'Mocking using ParameterFilter with scriptblock' {
$filter = [scriptblock]::Create( ('$Path -eq ''C:\Windows''') )
Mock -CommandName 'Test-Path' -ParameterFilter $filter
Describe 'Mocking using ParameterFilter' {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clcaldwell Some of these tests seem to be very similar. They could be candidate to be refactored using the TestCases option

@nohwnd nohwnd merged commit ea65cc6 into pester:master May 1, 2019
@clcaldwell clcaldwell deleted the FixFunctionDefinitionInParameterFilter branch May 2, 2019 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot use ${function:}s for ParameterFilters anymore
3 participants