Skip to content

Throw on unbound user-provided scriptblocks#2551

Merged
nohwnd merged 2 commits into
pester:mainfrom
fflaten:assert-boundinput
Oct 30, 2024
Merged

Throw on unbound user-provided scriptblocks#2551
nohwnd merged 2 commits into
pester:mainfrom
fflaten:assert-boundinput

Conversation

@fflaten

@fflaten fflaten commented Jul 30, 2024

Copy link
Copy Markdown
Collaborator

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:

image

image

Fix #2411

Checklist:

  • Add-AssertionOperator -Test (type: ScriptBlock)
  • Add-ShouldOperator -Test (type: ScriptBlock)
  • AfterAll -Scriptblock (type: ScriptBlock)
  • AfterEach -Scriptblock (type: ScriptBlock)
  • BeforeAll -Scriptblock (type: ScriptBlock)
  • BeforeDiscovery -ScriptBlock (type: ScriptBlock)
  • BeforeEach -Scriptblock (type: ScriptBlock)
  • Context -Fixture (type: ScriptBlock)
  • Describe -Fixture (type: ScriptBlock)
  • InModuleScope -ScriptBlock (type: ScriptBlock)
    • Not applicable as it always overrides session state to specified module
  • It -Test (type: ScriptBlock)
  • Mock -MockWith (type: ScriptBlock)
    • Already handles unbound scriptblocks. Test added
  • Mock -ParameterFilter (type: ScriptBlock)
    • Already handles unbound scriptblocks. Test added
  • New-PesterContainer -ScriptBlock (type: ScriptBlock[])
  • Should-All -FilterScript (type: ScriptBlock)
  • Should-Any -FilterScript (type: ScriptBlock)
  • Should-Throw -ScriptBlock (type: ScriptBlock)
  • Run.Scriptblock
  • Run.Container

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

fflaten commented Jul 30, 2024

Copy link
Copy Markdown
Collaborator Author

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?

@fflaten fflaten changed the title Block unbound scriptblocks as input Throw on unbound user-provided scriptblocks Jul 30, 2024
Comment thread src/Pester.Runtime.ps1 Outdated
Comment thread src/Pester.Runtime.ps1
@nohwnd

nohwnd commented Oct 1, 2024

Copy link
Copy Markdown
Member

The PR looks great. There is some merge conflict

…ial issues

Co-authored-by: Jakub Jareš <me@jakubjares.com>
@nohwnd nohwnd merged commit e4f9092 into pester:main Oct 30, 2024
@fflaten fflaten deleted the assert-boundinput branch October 30, 2024 22:31
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.

Unbound container scriptblock unexpectedly runs in Pester scope

2 participants