Pester
Pester copied to clipboard
Throw on unbound user-provided scriptblocks
PR Summary
Throws when user provides scriptblocks that are not bound to a session state. They would be executed in Pester's module state which could cause unexpected behaviour.
Examples:
Fix #2411
Checklist:
- [x]
Add-AssertionOperator -Test(type:ScriptBlock) - [x]
Add-ShouldOperator -Test(type:ScriptBlock) - [x]
AfterAll -Scriptblock(type:ScriptBlock) - [x]
AfterEach -Scriptblock(type:ScriptBlock) - [x]
BeforeAll -Scriptblock(type:ScriptBlock) - [x]
BeforeDiscovery -ScriptBlock(type:ScriptBlock) - [x]
BeforeEach -Scriptblock(type:ScriptBlock) - [x]
Context -Fixture(type:ScriptBlock) - [x]
Describe -Fixture(type:ScriptBlock) - [x]
InModuleScope -ScriptBlock(type:ScriptBlock)- Not applicable as it always overrides session state to specified module
- [x]
It -Test(type:ScriptBlock) - [x]
Mock -MockWith(type:ScriptBlock)- Already handles unbound scriptblocks. Test added
- [x]
Mock -ParameterFilter(type:ScriptBlock)- Already handles unbound scriptblocks. Test added
- [x]
New-PesterContainer -ScriptBlock(type:ScriptBlock[]) - [x]
Should-All -FilterScript(type:ScriptBlock) - [x]
Should-Any -FilterScript(type:ScriptBlock) - [x]
Should-Throw -ScriptBlock(type:ScriptBlock) - [x]
Run.Scriptblock - [x]
Run.Container
PR Checklist
- [x] PR has meaningful title
- [x] Summary describes changes
- [x] PR is ready to be merged
- If not, use the arrow next to
Create Pull Requestto mark it as a draft. PR can be markedReady for reviewwhen it's ready.
- If not, use the arrow next to
- [x] Tests are added/update (if required)
- [ ] Documentation is updated/added (if required)
Good or checking too many places? Can we improve the error somehow? Included a truncated scriptblock string to help identity the source.
Update link to https://pester.dev/docs/migrations/v5-to-v6 (when available) with workaround?
The PR looks great. There is some merge conflict