withClue

inline fun AssertionScope.withClue(clue: String, block: context(AssertionScope) () -> Unit)(source)

Executes the given assertion block with a descriptive clue that is prefixed to any assertion failure messages.

The clue provides additional context for assertion failures. When an assertion within the block fails, the failure message will include the clue on the first line, followed by the original failure message (indented). This makes it easier to understand which assertion failed and why.

Receiver

The assertion scope that will receive the prefixed failure messages.

Parameters

clue

A descriptive string that will be prefixed to any assertion failure messages originating from within the block.

block

The assertion block to execute with the clue as context. Called exactly once.


@JvmName(name = "withClueContextual")
context(assertionScope: AssertionScope)
inline fun withClue(clue: String, block: context(AssertionScope) () -> Unit)(source)

Executes the given assertion block with a descriptive clue that is prefixed to any assertion failure messages within the current assertion scope.

This contextual version uses the assertionScope from the surrounding context. The clue provides additional context for assertion failures. When an assertion within the block fails, the failure message will include the clue on the first line, followed by the original failure message (indented).

Context Parameters

assertionScope

The assertion scope that will receive the prefixed failure messages.

Parameters

clue

A descriptive string that will be prefixed to any assertion failure messages originating from within the block.

block

The assertion block to execute with the clue as context. Called exactly once.

See also


inline fun AssertionScope.withClue(crossinline clue: () -> String, block: context(AssertionScope) () -> Unit)(source)

Executes the given assertion block with a lazily-evaluated clue that is prefixed to any assertion failure messages.

The clue is obtained by calling the clue function only when an assertion within the block fails. This allows for expensive clue computation to be deferred until needed. When an assertion within the block fails, the failure message will include the result of the clue function on the first line, followed by the original failure message (indented).

Receiver

The assertion scope that will receive the prefixed failure messages.

Parameters

clue

A function that provides a descriptive string. Called only if an assertion within the block fails.

block

The assertion block to execute with the lazily-evaluated clue as context. Called exactly once.


@JvmName(name = "withClueContextual")
context(assertionScope: AssertionScope)
inline fun withClue(crossinline clue: () -> String, block: context(AssertionScope) () -> Unit)(source)

Executes the given assertion block with a lazily-evaluated clue that is prefixed to any assertion failure messages within the current assertion scope.

This contextual version uses the assertionScope from the surrounding context. The clue is obtained by calling the clue function only when an assertion within the block fails. This allows for expensive clue computation to be deferred until needed. When an assertion within the block fails, the failure message will include the result of the clue function on the first line, followed by the original failure message (indented).

Context Parameters

assertionScope

The assertion scope that will receive the prefixed failure messages.

Parameters

clue

A function that provides a descriptive string. Called only if an assertion within the block fails.

block

The assertion block to execute with the lazily-evaluated clue as context. Called exactly once.

See also