Should-BeAfter/BeBefore: make positional DateTime work#2709
Merged
Conversation
The doc example `(Get-Date).AddDays(1) | Should-BeAfter (Get-Date)` errored with "Cannot bind positional parameters because no names were given." The `Fluent` and `Expected` parameter sets both declared a position-0 parameter (`$Time` and `$Expected`), so a `DateTime` at position 0 matched both sets and PowerShell could not pick one. Split the `Fluent` parameter set into `FluentAgo` and `FluentFromNow`, each requiring its mandatory switch. With `-Ago`/`-FromNow` no longer optional within their set, neither fluent set is satisfiable from just a positional `[DateTime]`, so the `Expected` set wins unambiguously. Side effects: - `Should-BeAfter 10minutes -Ago -FromNow` now fails at binding (no parameter set can be resolved) instead of the runtime check. - The runtime "you must provide -Ago or -FromNow" check is gone, since binding enforces it. Added doc-style positional tests on both `Should-BeAfter` and `Should-BeBefore`. Verified the full Pester suite: 2171 passed, 0 failed. Follow-up to pester#2707. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The doc example
errors today with
Cannot bind positional parameters because no names were given.TheFluentandExpectedparameter sets both declared a position-0 parameter ($Timeand$Expected), so aDateTimeat position 0 matched both sets and PowerShell could not pick one.Split the
Fluentparameter set intoFluentAgoandFluentFromNow, each requiring its mandatory switch. With-Ago/-FromNowno longer optional within their set, neither fluent set is satisfiable from just a positional[DateTime], so theExpectedset wins unambiguously.Side effects:
Should-BeAfter 10minutes -Ago -FromNownow fails at binding ("parameter set cannot be resolved") instead of the runtime check.Added doc-style positional tests on both
Should-BeAfterandShould-BeBefore. Verified the full Pester suite: 2171 passed, 0 failed.Follow-up to #2707.