Skip to content

Fix function definition in parameter filter#1293

Merged
nohwnd merged 7 commits intopester:masterfrom
clcaldwell:FixFunctionDefinitionInParameterFilter
May 1, 2019
Merged

Fix function definition in parameter filter#1293
nohwnd merged 7 commits intopester:masterfrom
clcaldwell:FixFunctionDefinitionInParameterFilter

Conversation

@clcaldwell
Copy link
Copy Markdown
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
Comment thread Functions/Mock.ps1 Outdated
Copy link
Copy Markdown
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

Comment thread Functions/Mock.ps1 Outdated
Comment thread Functions/Mock.Tests.ps1
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
Copy Markdown
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