robfletcher
03/04/2021, 12:31 AMkotlin.Result
when I enable IR. No other changes. [This line of code](https://github.com/robfletcher/strikt/blob/main/strikt-core/src/main/kotlin/strikt/assertions/Result.kt#L17) starts throwing
java.lang.ClassCastException: class kotlin.Result$Failure cannot be cast to class kotlin.Result (kotlin.Result$Failure and kotlin.Result are in unnamed module of loader 'app')
robfletcher
03/04/2021, 12:36 AMIvan Kubyshkin [JetBrains]
03/04/2021, 12:31 PMimport kotlinx.coroutines.runBlocking
fun <R> Builder<Result<R>>.isFailure(): Builder<Throwable> =
this.get { exceptionOrNull()!! }
interface Builder<T> {
fun <R> get(
function: T.() -> R
): Builder<R>
}
inline fun <reified E : Throwable> expectThrows(
noinline action: () -> Any?
): Builder<E> =
AssertionBuilder(
AssertionSubject(
try {
runBlocking { action() }.let(Result.Companion::success)
} catch (e: Throwable) {
Result.failure(e)
}
)
).failedWith()
@Suppress("UNCHECKED_CAST")
inline fun <reified E : Throwable> Builder<Result<*>>.failedWith() =
isFailure() as Builder<E>
fun main() {
expectThrows<IllegalStateException> { error("o noes") }
}
class AssertionSubject<S>(
val subject: S
)
class AssertionBuilder<T>(
private val context: AssertionSubject<T>
) : Builder<T> {
override fun <R> get(
function: (T) -> R
): Builder<R> = runCatching {
function(context.subject)
}
.getOrElse { ex -> throw RuntimeException("", ex) }
.let {
TODO()
}
}
Ivan Kubyshkin [JetBrains]
03/04/2021, 12:32 PMrobfletcher
03/04/2021, 2:58 PM