Tests to check the existence of kotlin-stdlib in runtime
This commit is contained in:
parent
9282313552
commit
6581c14072
@ -68,6 +68,7 @@ xomrk {
|
||||
}
|
||||
}
|
||||
val jvmMain by getting {
|
||||
dependsOn(commonMain)
|
||||
dependencies {
|
||||
compileOnly(kotlinStdlibDependency)
|
||||
}
|
||||
|
@ -1 +1,5 @@
|
||||
kotlin.code.style=official
|
||||
kotlin.stdlib.default.dependency=false
|
||||
kotlin.mpp.applyDefaultHierarchyTemplate=false
|
||||
kotlin.native.enableKlibsCrossCompilation=true
|
||||
# compileOnly dependencies from commonMain still throw warning
|
||||
kotlin.suppressGradlePluginWarnings=IncorrectCompileOnlyDependencyWarning
|
@ -0,0 +1,130 @@
|
||||
package ru.landrafhomyak.utility.reference_counter.tests
|
||||
|
||||
import java.lang.AssertionError
|
||||
import org.testng.annotations.Test
|
||||
import org.testng.asserts.Assertion
|
||||
import ru.landgrafhomyak.utility.highlevel_try_finally.safeAutoClose1
|
||||
import ru.landrafhomyak.utility.reference_counter.CloseableReferenceCounter
|
||||
import ru.landrafhomyak.utility.reference_counter.CloseableReferenceCounter_Debug
|
||||
|
||||
@Test
|
||||
class KotlinStdlibDependencyTest {
|
||||
@Test
|
||||
fun testNoKotlinStdlib() {
|
||||
try {
|
||||
if (KotlinVersion.CURRENT.major != -1)
|
||||
throw AssertionError("Kotlin stdlib still in runtime classpath")
|
||||
} catch (_: LinkageError) {
|
||||
}
|
||||
}
|
||||
|
||||
private class CustomTestException : RuntimeException()
|
||||
|
||||
private object CustomUnit
|
||||
|
||||
private fun throw7throwFn() {
|
||||
safeAutoClose1(finally = { throw CustomTestException() }, action = { throw CustomTestException() })
|
||||
}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
private inline fun throw7throwIn() {
|
||||
safeAutoClose1(finally = { throw CustomTestException() }, action = { throw CustomTestException() })
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ["testNoKotlinStdlib"])
|
||||
fun testIncrefDecrefClose() {
|
||||
try {
|
||||
val refcnt = CloseableReferenceCounter("")
|
||||
refcnt.incref()
|
||||
refcnt.decref()
|
||||
refcnt.incref()
|
||||
refcnt.incref()
|
||||
refcnt.decref()
|
||||
refcnt.decref()
|
||||
refcnt.close("")
|
||||
} catch (le: LinkageError) {
|
||||
throw AssertionError("CloseableReferenceCounter still has dependency on kotlin stdlib", le)
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(CloseableReferenceCounter_Debug.RequiresExplicitDebug::class)
|
||||
@Test(dependsOnMethods = ["testNoKotlinStdlib"])
|
||||
fun testIncrefDecrefClose_Debug() {
|
||||
try {
|
||||
val refcnt = CloseableReferenceCounter_Debug("", "")
|
||||
refcnt.incref()
|
||||
refcnt.decref()
|
||||
refcnt.incref()
|
||||
refcnt.incref()
|
||||
refcnt.decref()
|
||||
refcnt.decref()
|
||||
refcnt.close("")
|
||||
} catch (le: LinkageError) {
|
||||
throw AssertionError("CloseableReferenceCounter_Debug still has dependency on kotlin stdlib", le)
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ["testNoKotlinStdlib", "testIncrefDecrefClose"])
|
||||
fun testWithRef() {
|
||||
try {
|
||||
val refcnt = CloseableReferenceCounter("")
|
||||
refcnt.withRef {
|
||||
return@withRef CustomUnit
|
||||
}
|
||||
refcnt.withRef w1@{
|
||||
return@w1 refcnt.withRef w2@{
|
||||
return@w2 CustomUnit
|
||||
}
|
||||
}
|
||||
refcnt.close("")
|
||||
} catch (le: LinkageError) {
|
||||
throw AssertionError("CloseableReferenceCounter still has dependency on kotlin stdlib", le)
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(CloseableReferenceCounter_Debug.RequiresExplicitDebug::class)
|
||||
@Test(dependsOnMethods = ["testNoKotlinStdlib", "testIncrefDecrefClose_Debug"])
|
||||
fun testWithRef_Debug() {
|
||||
try {
|
||||
val refcnt = CloseableReferenceCounter_Debug("", "")
|
||||
refcnt.withRef {
|
||||
return@withRef CustomUnit
|
||||
}
|
||||
refcnt.withRef w1@{
|
||||
return@w1 refcnt.withRef w2@{
|
||||
return@w2 CustomUnit
|
||||
}
|
||||
}
|
||||
refcnt.close("")
|
||||
} catch (le: LinkageError) {
|
||||
throw AssertionError("CloseableReferenceCounter_Debug still has dependency on kotlin stdlib", le)
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ["testNoKotlinStdlib", "testIncrefDecrefClose", "testWithRef"])
|
||||
fun testWithRef_Err() {
|
||||
try {
|
||||
val refcnt = CloseableReferenceCounter("")
|
||||
refcnt.withRef {
|
||||
throw CustomTestException()
|
||||
}
|
||||
} catch (_: CustomTestException) {
|
||||
} catch (le: LinkageError) {
|
||||
throw AssertionError("CloseableReferenceCounter still has dependency on kotlin stdlib", le)
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(CloseableReferenceCounter_Debug.RequiresExplicitDebug::class)
|
||||
@Test(dependsOnMethods = ["testNoKotlinStdlib", "testIncrefDecrefClose_Debug", "testWithRef_Debug"])
|
||||
fun testWithRef_ErrDebug() {
|
||||
try {
|
||||
val refcnt = CloseableReferenceCounter_Debug("", "")
|
||||
refcnt.withRef {
|
||||
throw CustomTestException()
|
||||
}
|
||||
} catch (_: CustomTestException) {
|
||||
} catch (le: LinkageError) {
|
||||
throw AssertionError("CloseableReferenceCounter_Debug still has dependency on kotlin stdlib", le)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user