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

Take callbacks for actual and which #1901

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

natebosch
Copy link
Member

This aligns these arguments with all the other failure formatting
arguments like clause and label. There may be some performance
benefit in some cases where a rejection from softCheck is ignored and
expensive String operations are avoid, but in the typical case this just
introduces closures which will be invoked shortly.

Replace the default empty list for actual with a default function.
This is a slight behavior change where passing () => [] will not get
overwritten with the default, but passing [] would have. Only
defaulting for when the argument was not passed at all is slightly
better behavior.

Replace a bunch of Iterable<String> with Iterable<String> Function()
and invoke them at the moment the strings are needed.

The main benefit this brings is it brings more alignment with the
`clause` arguments for `expect` calls. The docs will be able to focus on
the difference in how the value is use (preceding "that" in the case of
labels, standing on its own in a list in the case of clauses) and can
use a consistent description for how it is passed.

A secondary benefit is that it allows multiline labels and avoid
workaround like joining with `r'\n'`.

A final benefit is that it saves some unnecessary String formatting
since the callback isn't called if no expectations fail on the Subject,
or when used as a soft check where the failure details are ignored.

- Make the `label` arguments to `nest` and `nestAsync`, and the _label
  field in `_TestContext` an `Iterable<String> Function()`.
- Wrap strings that had been passed to `String` arguments with callbacks
  that return the string in a list.
- When writing the label in a failure, write all lines, and use a
  postfix " that:".
- Update some `Map` expectations which had manually joined with literal
  slash-n to keep the label or clause to a single line to take advantage
  of the multiline allowance. Split tests for the changed
  implementations and add tests for the descriptions with multiline
  examples. Some of these could have used multiline clauses before.
@natebosch natebosch force-pushed the label-callback--lazy-rejection-strings branch from 1079df0 to 16ebb0b Compare February 3, 2023 03:19
This aligns these arguments with all the other failure formatting
arguments like `clause` and `label`. There may be some performance
benefit in some cases where a rejection from `softCheck` is ignored and
expensive String operations are avoid, but in the typical case this just
introduces closures which will be invoked shortly.

Replace the default empty list for `actual` with a default function.
This is a slight behavior change where passing `() => []` will not get
overwritten with the default, but passing `[]` would have. Only
defaulting for when the argument was not passed at all is slightly
better behavior.

Replace a bunch of `Iterable<String>` with `Iterable<String> Function()`
and invoke them at the moment the strings are needed.
@natebosch natebosch force-pushed the label-callback--lazy-rejection-strings branch from 16ebb0b to b95c060 Compare February 3, 2023 03:21
'was accepted by the condition checking:',
...await describeAsync(condition)
]);
final description = await describeAsync(condition);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is one place where we are not getting value from the callback potentially not getting invoked.

I can't make the which callback async, so we are forced to do this async work outside of the callback.

Base automatically changed from label-callback to master February 4, 2023 01:56
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.

1 participant