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 when providing null or empty array to -ForEach #2537

Merged
merged 6 commits into from
Jul 10, 2024

Conversation

fflaten
Copy link
Collaborator

@fflaten fflaten commented Jul 9, 2024

PR Summary

Throw during Discovery when Describe/Context/It is provided $null or @() to -ForEach/TestCases to avoid silent failure.

The previous behavior, ignoring the test/block, can be achieved by setting the configuration option Run.FailOnNullOrEmptyForEach to $false.

When enabled, individual blocks or tests can be overriden to allow empty array or null by adding a new -AllowNullOrEmptyForEach parameter to Describe/Context/It, e.g. if a test is generated using external data which might be empty.

Fix #2151

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 changed the title Throw when no Data passed to -ForEach Throw when providing null or empty array to -ForEach Jul 9, 2024
@fflaten
Copy link
Collaborator Author

fflaten commented Jul 9, 2024

/azp run

Copy link
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

@fflaten
Copy link
Collaborator Author

fflaten commented Jul 9, 2024

/azp run

Copy link
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

@fflaten
Copy link
Collaborator Author

fflaten commented Jul 9, 2024

@nohwnd It already paid off 😄 a365340

@fflaten fflaten marked this pull request as ready for review July 9, 2024 17:03
@fflaten
Copy link
Collaborator Author

fflaten commented Jul 9, 2024

/azp run

Copy link
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

@nohwnd nohwnd merged commit 5f5251d into pester:main Jul 10, 2024
11 checks passed
@nohwnd
Copy link
Member

nohwnd commented Jul 10, 2024

Amazing work!

@fflaten fflaten deleted the FailOnNullOrEmptyForEach branch July 31, 2024 11:10
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.

Throw when no test cases passed to -ForEach
2 participants