K2 Scripting: enable K2 tests in some test projects

This commit is contained in:
Ilya Chernikov
2022-11-17 12:26:00 +01:00
committed by Space Team
parent 90a4f6002e
commit deb2d6d024
7 changed files with 72 additions and 5 deletions
+6
View File
@@ -671,6 +671,12 @@ tasks {
dependsOn(":kotlin-scripting-ide-services-test:embeddableTest")
}
register("scriptingK2Test") {
dependsOn(":kotlin-scripting-compiler:testWithK2")
dependsOn(":kotlin-scripting-jvm-host-test:testWithK2")
dependsOn(":kotlin-main-kts-test:testWithK2")
}
register("scriptingTest") {
dependsOn("scriptingJvmTest")
}
@@ -59,3 +59,9 @@ projectTest(taskName = "testWithIr", parallel = true) {
workingDir = rootDir
systemProperty("kotlin.script.base.compiler.arguments", "-Xuse-ir")
}
projectTest(taskName = "testWithK2", parallel = true) {
dependsOn(":dist")
workingDir = rootDir
systemProperty("kotlin.script.base.compiler.arguments", "-Xuse-k2")
}
@@ -255,7 +255,7 @@ class ScriptingHostTest : TestCase() {
}
assertTrue(comp0 is ResultWithDiagnostics.Failure)
val errors = comp0.reports.filter { it.severity == ScriptDiagnostic.Severity.ERROR }
assertTrue( errors.any { it.message == "Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type String?" })
assertTrue( errors.any { it.message.contains( "Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type ") })
// runtime
fun evalWith(evalConfig: ScriptEvaluationConfiguration) =
@@ -23,11 +23,17 @@ sourceSets {
projectTest(parallel = true) {
dependsOn(":dist")
workingDir = rootDir
systemProperty("kotlin.script.test.base.compiler.arguments", "-Xuse-old-backend")
systemProperty("kotlin.script.base.compiler.arguments", "-Xuse-old-backend")
}
projectTest(taskName = "testWithIr", parallel = true) {
dependsOn(":dist")
workingDir = rootDir
systemProperty("kotlin.script.test.base.compiler.arguments", "-Xuse-ir")
systemProperty("kotlin.script.base.compiler.arguments", "-Xuse-ir")
}
projectTest(taskName = "testWithK2", parallel = true) {
dependsOn(":dist")
workingDir = rootDir
systemProperty("kotlin.script.base.compiler.arguments", "-Xuse-k2")
}
@@ -73,3 +73,11 @@ projectTest(taskName = "testWithIr", parallel = true) {
systemProperty("kotlin.script.test.base.compiler.arguments", "-Xuse-ir")
}
projectTest(taskName = "testWithK2", parallel = true) {
dependsOn(":dist")
workingDir = rootDir
systemProperty("kotlin.test.script.classpath", testSourceSet.output.classesDirs.joinToString(File.pathSeparator))
systemProperty("kotlin.script.test.base.compiler.arguments", "-Xuse-k2")
systemProperty("kotlin.script.base.compiler.arguments", "-Xuse-k2")
}
@@ -22,7 +22,7 @@ import kotlin.concurrent.thread
const val SCRIPT_TEST_BASE_COMPILER_ARGUMENTS_PROPERTY = "kotlin.script.test.base.compiler.arguments"
private fun getBaseCompilerArgumentsFromProperty(): List<String>? =
internal fun getBaseCompilerArgumentsFromProperty(): List<String>? =
System.getProperty(SCRIPT_TEST_BASE_COMPILER_ARGUMENTS_PROPERTY)?.takeIf { it.isNotBlank() }?.split(' ')
// TODO: partially copypasted from LauncherReplTest, consider extracting common parts to some (new) test util module
@@ -7,7 +7,9 @@ package org.jetbrains.kotlin.scripting.compiler.test
import junit.framework.TestCase
import kotlinx.coroutines.runBlocking
import org.jetbrains.kotlin.scripting.compiler.plugin.getBaseCompilerArgumentsFromProperty
import org.jetbrains.kotlin.scripting.compiler.plugin.impl.ScriptJvmCompilerIsolated
import org.jetbrains.kotlin.utils.tryConstructClassFromStringArgs
import kotlin.reflect.KClass
import kotlin.reflect.KProperty
import kotlin.reflect.full.createInstance
@@ -32,6 +34,40 @@ class ScriptCompilerTest : TestCase() {
assertTrue(res.reports.none { it.message.contains("nonsense") })
}
fun testSimpleVarAccess() {
val res = compileToClass(
"""
val x = 2
val y = x
""".trimIndent().toScriptSource()
)
val kclass = res.valueOrThrow()
val scriptInstance = kclass.createInstance()
assertNotNull(scriptInstance)
}
fun testLambdaWithProperty() {
val versionProperties = java.util.Properties()
"".reader().use { propInput ->
versionProperties.load(propInput)
}
val res = compileToClass(
"""
val versionProperties = java.util.Properties()
"".reader().use { propInput ->
val x = 1
x.toString()
versionProperties.load(propInput)
}
""".trimIndent().toScriptSource()
)
val kclass = res.valueOrThrow()
val scriptInstance = kclass.createInstance()
assertNotNull(scriptInstance)
}
fun testTypeAliases() {
val res = compileToClass(
"""
@@ -78,7 +114,12 @@ class ScriptCompilerTest : TestCase() {
script: SourceCode,
cfgBody: ScriptCompilationConfiguration.Builder.() -> Unit
): ResultWithDiagnostics<CompiledScript> {
val compilationConfiguration = ScriptCompilationConfiguration(cfgBody)
val compilationConfiguration = ScriptCompilationConfiguration {
cfgBody()
getBaseCompilerArgumentsFromProperty()?.let {
compilerOptions.append(it)
}
}
val compiler = ScriptJvmCompilerIsolated(defaultJvmScriptingHostConfiguration)
return compiler.compile(script, compilationConfiguration)
}