Oliver.O
08/29/2021, 8:53 PMsuspend
version of shouldThrow
missing for a reason or should I file an issue?sam
08/29/2021, 10:43 PMLeoColman
08/30/2021, 1:18 AMx = y
couldn't be inlined by our function, and then we added shouldThrowUnit
. I believe all of this is inlinesam
08/30/2021, 4:27 AMOliver.O
08/30/2021, 10:45 AMsam
08/31/2021, 2:36 PMJim
08/31/2021, 4:17 PMTestExecutionFilter
that installs the necessary stuff for withClue. Then deprecate the old ones and make withClue a suspending extension function on TestContextOliver.O
08/31/2021, 4:30 PMwithClue
would no longer be usable with the standalone assertions-package, (i.e. without the Kotest framework), right?Jim
08/31/2021, 4:31 PMOliver.O
08/31/2021, 5:47 PMprivate val _errorCollector = ThreadLocal<ThreadLocalErrorCollector>()
val errorCollector: ErrorCollector get() = _errorCollector.get()
suspend fun withErrorCollector(thunk: suspend () -> R) = withContext(_errorCollector.asContextElement()) { thunk() }
suspend fun <R> withClue(clue: Any?, thunk: suspend () -> R): R {
try {
errorCollector.pushClue { clue.toString() }
return withErrorCollector { thunk() }
} finally {
errorCollector.popClue()
}
}
Jim
08/31/2021, 5:48 PMwithClue
, any
, all
, and one
Oliver.O
08/31/2021, 5:51 PMJim
08/31/2021, 5:57 PMOliver.O
08/31/2021, 7:25 PMsuspend
differences alone:
suspend fun <R> withClue(clue: Any?, thunk: suspend () -> R): R
fun <R> withClue(clue: Any?, thunk: () -> R): R
In this case, it would complain on the non-suspending call site:
Overload resolution ambiguityThis is https://youtrack.jetbrains.com/issue/KT-23610. Another point: You start in non-coroutine land, invoke
withClue
(or assertSoftly
) there, then start coroutines which might switch threads. You'd probably have to make the ThreadLocalErrorCollector from non-coroutine land available to coroutines.