fix: succeed for empty expected collection in Contains#648
Conversation
When checking that a collection contains an empty expected collection, it should succeed.
There was a problem hiding this comment.
Pull Request Overview
This PR ensures that calling Contains with an empty expected collection always succeeds by updating the matching logic and adding corresponding tests.
- Added tests (
WhenExpectedIsEmpty_ShouldSucceed) for empty expected collections across allContainsvariants, plus null-expected failure tests. - Updated
CollectionMatchOptions.MissingItemsErrorto early-exit when the expected collection is empty. - Adjusted the build pipeline scope to
CoreOnly.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionTests.cs | Added empty-expected and null-expected tests for all Contains overloads |
| Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.Contains.CollectionTests.cs | Added empty-expected and null-expected tests for async enumerable Contains |
| Source/aweXpect.Core/Options/CollectionMatchOptions.cs | Early return in MissingItemsError when expected total is zero |
| Pipeline/Build.cs | Changed BuildScope from Default to CoreOnly in build script |
Comments suppressed due to low confidence (2)
Source/aweXpect.Core/Options/CollectionMatchOptions.cs:187
- [nitpick] Add a brief comment explaining that this guard handles the empty expected collection case and prevents an erroneous "all missing" error.
if (total == 0)
Pipeline/Build.cs:22
- [nitpick] This build-scope change appears unrelated to the
Containsfix. Consider moving pipeline configuration updates into a separate PR to keep concerns isolated.
readonly BuildScope BuildScope = BuildScope.CoreOnly;
|
Test Results 4 files - 34 4 suites - 34 19s ⏱️ - 2m 26s Results for commit 3937ab1. ± Comparison against base commit e50b985. This pull request removes 12796 and adds 54 tests. Note that renamed tests count towards both. |
|
This is addressed in release v2.17.0. |



When checking that a collection contains an empty expected collection, it should succeed.