Skip to content

Conversation

habara-k
Copy link
Contributor

Changes

  • Add dependency of libs.kotlinx.coroutines.test to :kotest-assertions:kotest-assertions-core

Motivation

It is necessary to add this dependency to run :kotest-assertions:kotest-assertions-core locally.

Related PRs

@habara-k habara-k requested a review from a team as a code owner April 23, 2025 05:01
github-merge-queue bot pushed a commit that referenced this pull request Apr 24, 2025
…t]BeOneOf` and `should[Not]BeIn` (#4849)

<!-- 
If this PR updates documentation, please update all relevant versions of
the docs, see:
https://github.com/kotest/kotest/tree/master/documentation/versioned_docs
The documentation at
https://github.com/kotest/kotest/tree/master/documentation/docs is the
documentation for the next minor or major version _TO BE RELEASED_
-->

This PR resolves #4847.

## Changes

Allow emptyList to be passed as an argument to
- `should[Not]ContainAnyOf`
- `should[Not]BeOneOf`
- `should[Not]BeIn`

### Minor changes
- ~Add dependency of libs.kotlinx.coroutines.test for local testing of
:kotest-assertions:kotest-assertions-core.~ Moved to #4856


## Motivation

Mathematically, the following assertions should each fail or pass as
described:

```kt
// Example assertions with empty lists
listOf(...).shouldContainAnyOf(emptyList())    // Expected to fail
listOf(...).shouldNotContainAnyOf(emptyList()) // Expected to pass
listOf(...).shouldBeOneOf(emptyList())         // Expected to fail
listOf(...).shouldNotBeOneOf(emptyList())      // Expected to pass
listOf(...).shouldBeIn(emptyList())            // Expected to fail
listOf(...).shouldNotBeIn(emptyList())         // Expected to pass
```

However, when these assertions are passed an empty collection, an error
occurs stating: "Asserting content on empty collection. Use
Collection.shouldBeEmpty() instead."

These assertions lack consistency with the existing specifications of
the following assertions:

```kt
listOf(...).shouldContainAll(emptyList())     // Passes
listOf(...).shouldNotContainAll(emptyList())  // Fails
mapOf(...).shouldContainAll(emptyMap())       // Passes
mapOf(...).shouldNotContainAll(emptyMap())    // Fails
mapOf(...).shouldContainKeys()                // Passes
mapOf(...).shouldNotContainKeys()             // Fails
mapOf(...).shouldContainAnyKeysOf()           // Fails
mapOf(...).shouldNotContainAnyKeysOf()        // Passes
mapOf(...).shouldContainValues()              // Passes
mapOf(...).shouldNotContainValues()           // Fails
mapOf(...).shouldContainAnyValuesOf()         // Fails
mapOf(...).shouldNotContainAnyValuesOf()      // Passes
```

This PR aims to correct the inconsistent behavior and make the Kotest
assertions mathematically accurate and more general.

---------

Co-authored-by: Felix Wiemuth <533601+felixwiemuth@users.noreply.github.com>
Co-authored-by: Alex Kuznetsov <Alex.Cue.987@gmail.com>
Co-authored-by: ej-castillo <eugene.j.castillo@gmail.com>
@sksamuel sksamuel enabled auto-merge May 5, 2025 14:37
@sksamuel sksamuel added this pull request to the merge queue May 5, 2025
Merged via the queue into kotest:master with commit e229a8c May 5, 2025
7 checks passed
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.

2 participants