Tests to check kotlin stdlib dependencies and some improvements in gradle

This commit is contained in:
Andrew Golovashevich 2025-03-25 22:20:45 +03:00
parent 758bc31a85
commit 529508bf74
3 changed files with 82 additions and 4 deletions

View File

@ -41,10 +41,14 @@ xomrk {
compileTaskProvider.configure {
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
freeCompilerArgs.addAll("-Xallow-kotlin-package")
}
}
}
tasks.named { t -> t == "${this@jvm.name}Test" }.configureEach {
this as Test
useTestNG()
}
}
sourceSets {
@ -66,7 +70,13 @@ xomrk {
}
}
sourceSets.configureEach {
jvmTest {
dependencies {
implementation("org.testng:testng:7.5.1")
}
}
configureEach {
when {
// commonMain !in dependsOn -> return@configureEach
!name.endsWith("Main") -> return@configureEach

View File

@ -1,3 +1,5 @@
kotlin.code.style=official
kotlin.stdlib.default.dependency=false
kotlin.mpp.applyDefaultHierarchyTemplate=false
kotlin.mpp.applyDefaultHierarchyTemplate=false
kotlin.native.enableKlibsCrossCompilation=true
# compileOnly dependencies from commonMain still throw warning
kotlin.suppressGradlePluginWarnings=IncorrectCompileOnlyDependencyWarning

View File

@ -0,0 +1,66 @@
package ru.landgrafhomyak.utility.highlevel_try_finally.tests
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
@Test
class KotlinStdlibDependencyTest {
@Test
fun testNoKotlinStdlib() {
try {
KotlinVersion.CURRENT
Assertion().assertTrue(false, "Kotlin stdlib still in runtime classpath")
} catch (_: LinkageError) {
}
}
private class CustomTestException : RuntimeException()
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 testAutoCloseFn() {
try {
throw7throwFn()
} catch (_: CustomTestException) {
} catch (_: LinkageError) {
Assertion().assertTrue(false, "safeAutoClose still has dependency on kotlin stdlib")
}
}
@Test(dependsOnMethods = ["testNoKotlinStdlib"])
fun testAutoCloseIn() {
try {
throw7throwIn()
} catch (_: CustomTestException) {
} catch (_: LinkageError) {
Assertion().assertTrue(false, "safeAutoClose still has dependency on kotlin stdlib")
}
}
@Test(dependsOnMethods = ["testNoKotlinStdlib"])
fun testTryFinallyChain() {
try {
@Suppress("KotlinUnreachableCode")
tryFinallyChain { chain ->
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")
}
}
}