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

Throw on unbound user-provided scriptblocks #2551

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fflaten
Copy link
Collaborator

@fflaten fflaten commented Jul 30, 2024

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
Copy link
Collaborator Author

fflaten commented Jul 30, 2024

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
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
1 participant