Testing tryFinallyChain seems untrivial so it still require kotlin stdlib

This commit is contained in:
Andrew Golovashevich 2025-03-25 22:34:55 +03:00
parent 529508bf74
commit 28ab658dd2
2 changed files with 6 additions and 4 deletions

View File

@ -12,7 +12,7 @@ class TryFinallyChainScope @PublishedApi internal constructor() {
this._actualException?.let { e -> throw e }
}
inline fun action(fn: () -> Unit) {
inline fun action(fn: () -> Unit): TryFinallyChainScope {
contract {
callsInPlace(fn, InvocationKind.EXACTLY_ONCE)
}
@ -21,5 +21,6 @@ class TryFinallyChainScope @PublishedApi internal constructor() {
onError = { err -> this._actualException?.addSuppressed(err) ?: run { this._actualException = err } },
action = fn
)
return this
}
}

View File

@ -4,6 +4,7 @@ import org.testng.annotations.Test
import org.testng.asserts.Assertion
import ru.landgrafhomyak.utility.highlevel_try_finally.safeAutoClose1
import ru.landgrafhomyak.utility.highlevel_try_finally.tryFinallyChain
import java.lang.AssertionError
@Test
class KotlinStdlibDependencyTest {
@ -52,15 +53,15 @@ class KotlinStdlibDependencyTest {
try {
@Suppress("KotlinUnreachableCode")
tryFinallyChain { chain ->
chain.action { }
// chain.action { }
chain.action { throw CustomTestException() }
chain.action { throw CustomTestException() }
chain.action { }
chain.action { }
}
} catch (_: CustomTestException) {
} catch (_: LinkageError) {
Assertion().assertTrue(false, "safeAutoClose still has dependency on kotlin stdlib")
} catch (e: LinkageError) {
throw AssertionError("safeAutoClose still has dependency on kotlin stdlib", e)
}
}
}