LeoColman
04/02/2022, 5:48 PMshouldBeFailure
, the error message I get is
java.lang.AssertionError: Result should be a failure but was kotlin.UnitWhile I actually expected it to be more significant that it's a Success, like:
java.lang.AssertionError: Result should be a failure but was Success(kotlin.Unit)This is due to the fact that
BeFailure
uses getOrNull
in the Result
instead of toString
. I think it would be better to replace it, but I don't know. What do you think? I can open an issue to discuss this further in the Kotest repositoryLeoColman
04/02/2022, 5:50 PMclass BeFailure : Matcher<Result<Any?>> {
override fun test(value: Result<Any?>) = MatcherResult(
value.isFailure,
{ "Result should be a failure but was ${value.getOrNull()}" },
{ "Result should not be a failure" })
}
commonMain/io/kotest/matchers/result/matchers.ktmitch
04/04/2022, 11:42 AMResult<T>
is actually printing out Success(...)
maybe that success should just be a "Result should be a failure but was $value"
@SinceKotlin("1.3")
@JvmInline
public value class Result<out T> @PublishedApi internal constructor(
@PublishedApi
internal val value: Any?
) : Serializable {
// etc...
/**
* Returns a string `Success(v)` if this instance represents [success][Result.isSuccess]
* where `v` is a string representation of the value or a string `Failure(x)` if
* it is [failure][isFailure] where `x` is a string representation of the exception.
*/
public override fun toString(): String =
when (value) {
is Failure -> value.toString() // "Failure($exception)"
else -> "Success($value)"
}