Skip to content

feat: add seed via exception context - #113

Draft
pbrisbin wants to merge 1 commit into
mainfrom
pb/annotate2
Draft

feat: add seed via exception context#113
pbrisbin wants to merge 1 commit into
mainfrom
pb/annotate2

Conversation

@pbrisbin

Copy link
Copy Markdown
Member

When supported (base-4.20), use addExceptionContext to add the seed to
the failure. This ensures it happens, not just with expectation failures
(HUnitFailure), but also with other thrown-exception failures, and
does so without altering the exception type (as annotated-exception
would).

In base lower than 4.20, behavior is unchanged.

Closes #44.

CAVEAT: this doesn't work :(

HUnit-based testing libraries (e.g hspec) have not updated themselves to
use or display exception context in their output. They would need to
incorporate it into formatFailureMessage for expectation failures.

Even if/when they do, this also doesn't even work for its intended
purpose (non-expectation-failure exceptions) because hspec (for
example) uses show or (optionally) displayException, neither of
which include context (which is wild, IMHO).

So, while it would be nice if we could use exception context for this
information, users would still need to update their test runners somehow
to ensure its displayed.

I know the hspec project is not amenable to displaying more
information like this in its output by default, but I think they do
plan to add some sort of --verbose flag. If/when that existed, I
think we could get them to include any exception context in such output,
and we could instruct our uses to use it if they want to see seed.

But is that how we want it to work? Or should we keep this behavior of
stuffing it into strings that we know are always displayed (and just
give up on #44)? I'm leaning this way.

When supported (base-4.20), use `addExceptionContext` to add the seed to
the failure. This ensures it happens, not just with expectation failures
(`HUnitFailure`), but also with other thrown-exception failures, and
does so without altering the exception type (as `annotated-exception`
would).

In base lower than 4.20, behavior is unchanged.

Closes #44.

**CAVEAT**: this doesn't work :(

HUnit-based testing libraries (e.g hspec) have not updated themselves to
use or display exception context in their output. They would need to
incorporate it into `formatFailureMessage` for expectation failures.

Even if/when they do, this also doesn't even work for its intended
purpose (non-expectation-failure exceptions) because `hspec` (for
example) uses `show` or (optionally) `displayException`, neither of
which include context (which is wild, IMHO).

So, while it would be nice if we could use exception context for this
information, users would still need to update their test runners somehow
to ensure its displayed.

I know the `hspec` project is not amenable to displaying more
information like this in its output _by default_, but I think they do
plan to add some sort of `--verbose` flag. If/when that existed, I
think we could get them to include any exception context in such output,
and we could instruct our uses to use it if they want to see seed.

But is that how we want it to work? Or should we keep this behavior of
stuffing it into strings that we know are always displayed (and just
give up on #44)? I'm leaning this way.
@pbrisbin
pbrisbin requested a review from cdmren July 31, 2026 13:27
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.

Catch SomeException and decorate with seed

1 participant