Visitar URL original
BeEmpty() materializes IEnumerable<T> only once, even on failure by louis-z · Pull Request #2530 · fluentassertions/fluentassertions · GitHub
Skip to content

BeEmpty() materializes IEnumerable<T> only once, even on failure - #2530

Merged
dennisdoomen merged 4 commits into
fluentassertions:developfrom
louis-z:issue-2490
Jan 5, 2024
Merged

dennisdoomen merged 4 commits into
fluentassertions:developfrom
louis-z:issue-2490

Conversation

@louis-z

@louis-z louis-z commented Dec 31, 2023 •

Copy link
Copy Markdown
Contributor
  • Make BeEmpty() materialize only the first item, as no further processing is needed for validation
  • The error message now mentions "but found at least one item" and outputs the said item

Fixes #2490

IMPORTANT

  • If the PR touches the public API, the changes have been approved in a separate issue with the "api-approved" label.
  • The code complies with the Coding Guidelines for C#.
  • The changes are covered by unit tests which follow the Arrange-Act-Assert syntax and the naming conventions such as is used in these tests.
  • If the PR adds a feature or fixes a bug, please update the release notes with a functional description that explains what the change means to consumers of this library, which are published on the website.
  • If the PR changes the public API the changes needs to be included by running AcceptApiChanges.ps1 or AcceptApiChanges.sh.
  • If the PR affects the documentation, please include your changes in this pull request so the documentation will appear on the website.
    • Please also run ./build.sh --target spellcheck or .\build.ps1 --target spellcheck before pushing and check the good outcome

@github-actions

github-actions Bot commented Dec 31, 2023 •

Copy link
Copy Markdown

Qodana for .NET

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Contact Qodana team

Contact us at qodana-support@jetbrains.com

@dennisdoomen
dennisdoomen requested a review from jnyrup January 1, 2024 14:55
@louis-z
louis-z marked this pull request as ready for review January 2, 2024 16:35
@coveralls

coveralls commented Jan 3, 2024 •

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 7416242537

Warning: This coverage report may be inaccurate.

We've detected an issue with your CI configuration that might affect the accuracy of this pull request's coverage report.
To ensure accuracy in future PRs, please see these guidelines.
A quick fix for this PR: rebase it; your next report should be accurate.

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.001%) to 97.466%

Totals Coverage Status
Change from base Build 7414260681: 0.001%
Covered Lines: 11748
Relevant Lines: 11932

💛 - Coveralls

@jnyrup

jnyrup commented Jan 4, 2024

Copy link
Copy Markdown
Member

A note: This partly reverts #227, but I'm fine with the change here.
A similar change should be applied to BeNullOrEmpty to keep them aligned.

@louis-z

louis-z commented Jan 4, 2024 •

Copy link
Copy Markdown
Contributor Author

[...] A similar change should be applied to BeNullOrEmpty to keep them aligned.

Done

- Make BeEmpty() materialize only the first item, as no further processing is needed for validation
- The error message now mentions "but found at least 1 item" and outputs the said item
@jnyrup

jnyrup commented Jan 4, 2024

Copy link
Copy Markdown
Member

Aren't we missing a test for BeNullOrEmpty identical to the added When_asserting_non_empty_collection_is_empty_it_should_enumerate_only_once test to verify the change?

@dennisdoomen
dennisdoomen enabled auto-merge (squash) January 5, 2024 07:10
@dennisdoomen
dennisdoomen merged commit d2dbf77 into fluentassertions:develop Jan 5, 2024
@IT-VBFK

IT-VBFK commented Jan 5, 2024 •

Copy link
Copy Markdown
Contributor

@louis-z Did you intentionally left this out from the release notes? IMHO this is worth to be added there? 🤔

@dennisdoomen

Copy link
Copy Markdown
Member

Fair point.

@louis-z
louis-z deleted the issue-2490 branch January 5, 2024 12:11
jnyrup pushed a commit to jnyrup/fluentassertions that referenced this pull request Jul 14, 2024
…entassertions#2530)

* BeEmpty() materializes IEnumerable<T> only once, even on failure

- Make BeEmpty() materialize only the first item, as no further processing is needed for validation
- The error message now mentions "but found at least 1 item" and outputs the said item

* Tweak error message & fix tests

* Make similar changes for BeNullOrEmpty

* Add test, as per request
jnyrup pushed a commit to jnyrup/fluentassertions that referenced this pull request Jul 14, 2024
…entassertions#2530)

* BeEmpty() materializes IEnumerable<T> only once, even on failure

- Make BeEmpty() materialize only the first item, as no further processing is needed for validation
- The error message now mentions "but found at least 1 item" and outputs the said item

* Tweak error message & fix tests

* Make similar changes for BeNullOrEmpty

* Add test, as per request
jnyrup pushed a commit to jnyrup/fluentassertions that referenced this pull request Jul 14, 2024
…entassertions#2530)

* BeEmpty() materializes IEnumerable<T> only once, even on failure

- Make BeEmpty() materialize only the first item, as no further processing is needed for validation
- The error message now mentions "but found at least 1 item" and outputs the said item

* Tweak error message & fix tests

* Make similar changes for BeNullOrEmpty

* Add test, as per request
jnyrup pushed a commit to jnyrup/fluentassertions that referenced this pull request Aug 18, 2024
…entassertions#2530)

* BeEmpty() materializes IEnumerable<T> only once, even on failure

- Make BeEmpty() materialize only the first item, as no further processing is needed for validation
- The error message now mentions "but found at least 1 item" and outputs the said item

* Tweak error message & fix tests

* Make similar changes for BeNullOrEmpty

* Add test, as per request
jnyrup pushed a commit to jnyrup/fluentassertions that referenced this pull request Aug 18, 2024
…entassertions#2530)

* BeEmpty() materializes IEnumerable<T> only once, even on failure

- Make BeEmpty() materialize only the first item, as no further processing is needed for validation
- The error message now mentions "but found at least 1 item" and outputs the said item

* Tweak error message & fix tests

* Make similar changes for BeNullOrEmpty

* Add test, as per request
jnyrup pushed a commit to jnyrup/fluentassertions that referenced this pull request Aug 24, 2024
…entassertions#2530)

* BeEmpty() materializes IEnumerable<T> only once, even on failure

- Make BeEmpty() materialize only the first item, as no further processing is needed for validation
- The error message now mentions "but found at least 1 item" and outputs the said item

* Tweak error message & fix tests

* Make similar changes for BeNullOrEmpty

* Add test, as per request
jnyrup pushed a commit that referenced this pull request Sep 9, 2024
* BeEmpty() materializes IEnumerable<T> only once, even on failure

- Make BeEmpty() materialize only the first item, as no further processing is needed for validation
- The error message now mentions "but found at least 1 item" and outputs the said item

* Tweak error message & fix tests

* Make similar changes for BeNullOrEmpty

* Add test, as per request
@bogataj

bogataj commented Sep 12, 2024 •

Copy link
Copy Markdown

@dennisdoomen did this change also unintentionally affect WithMessage on ExceptionAssertions? Release notes only mentions BeEmpty() and BeNullOrEmpty(), but I have tests failing now after upgrading 6.12.0 -> 6.12.1 where the iterator seem to stop after the first item at that method also.

Specifically my use case is a generic convention test that finds and prints all missing subscription registrations on a service bus, stopping the iteration on the first item while evaluating WithMessage would be a somewhat unfortunate feature, while I appreciate the efforts for performance gains 👍

@jnyrup

jnyrup commented Sep 12, 2024

Copy link
Copy Markdown
Member

@bogataj Please share a code example of what no longer works for you.

In the meantime I would suggest that if your test requires complete enumeration, that you enforce it on your side instead of relying on that we (or any other library) does that.

This was referenced Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IEnumerable gets evaluated multiple times when using BeEmpty()

6 participants