Set thread context classloader in the kotlin runner

#KT-26624 fixed
This commit is contained in:
Ilya Chernikov
2019-08-26 19:43:55 +02:00
parent d3f32c0d8a
commit 08720a3dc6
3 changed files with 31 additions and 0 deletions
@@ -57,6 +57,8 @@ abstract class AbstractRunner : Runner {
)
}
Thread.currentThread().contextClassLoader = classLoader
try {
main.invoke(null, arguments.toTypedArray())
}
+11
View File
@@ -0,0 +1,11 @@
object ContextClassLoaderTester {
@JvmStatic
fun main(args: Array<String>) {
kotlin.test.DefaultAsserter.assertTrue("", true) // this tests that kotlin-test is in the compilation and runtime classpaths
val contextClassLoader = Thread.currentThread().getContextClassLoader()
contextClassLoader.loadClass("kotlin.test.DefaultAsserter") // this tests that thread context classloader is set correctly
println("ok")
}
}
@@ -88,6 +88,24 @@ class LauncherScriptTest : TestCaseWithTmpdir() {
)
}
fun testKotlinJvmContextClassLoader() {
val kotlinTestJar = File(PathUtil.kotlinPathsForDistDirectory.homePath, "lib/kotlin-test.jar")
assertTrue("kotlin-main-kts.jar not found, run dist task: ${kotlinTestJar.absolutePath}", kotlinTestJar.exists())
runProcess(
"kotlinc",
"-cp", kotlinTestJar.path,
"$testDataDirectory/contextClassLoaderTester.kt",
"-d", tmpdir.path
)
runProcess(
"kotlin",
"-cp", listOf(tmpdir.path, kotlinTestJar.path).joinToString(File.pathSeparator),
"ContextClassLoaderTester",
expectedStdout = "ok\n"
)
}
fun testKotlincJsSimple() {
runProcess(
"kotlinc-js",