From f6c5622dd4e05cf6233f7529e733bf3eca378708 Mon Sep 17 00:00:00 2001 From: Dmitry Kandalov Date: Fri, 22 Sep 2023 10:33:33 +0100 Subject: [PATCH] kotest shouldBeSuccess() returning value --- .../kotlin/dev/forkhandles/result4k/kotest/matchers.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/result4k/kotest/src/main/kotlin/dev/forkhandles/result4k/kotest/matchers.kt b/result4k/kotest/src/main/kotlin/dev/forkhandles/result4k/kotest/matchers.kt index 92cd69f..63fe16a 100644 --- a/result4k/kotest/src/main/kotlin/dev/forkhandles/result4k/kotest/matchers.kt +++ b/result4k/kotest/src/main/kotlin/dev/forkhandles/result4k/kotest/matchers.kt @@ -19,16 +19,16 @@ fun beSuccess(): Matcher> = object : Matcher> { } @OptIn(ExperimentalContracts::class) -fun Result.shouldBeSuccess() { +fun Result.shouldBeSuccess(): T { contract { - returns() implies (this@shouldBeSuccess is Success<*>) + returns() implies (this@shouldBeSuccess is Success) } this should beSuccess() + return (this as Success).value } infix fun Result.shouldBeSuccess(block: (T) -> Unit) { - this.shouldBeSuccess() - block((this as Success).value) + block(this.shouldBeSuccess()) } infix fun Result.shouldBeSuccess(value: T) = this should beSuccess(value)