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

View File

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