K2 Scripting: enable K2 tests in some test projects
This commit is contained in:
committed by
Space Team
parent
90a4f6002e
commit
deb2d6d024
@@ -671,6 +671,12 @@ tasks {
|
|||||||
dependsOn(":kotlin-scripting-ide-services-test:embeddableTest")
|
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") {
|
register("scriptingTest") {
|
||||||
dependsOn("scriptingJvmTest")
|
dependsOn("scriptingJvmTest")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,3 +59,9 @@ projectTest(taskName = "testWithIr", parallel = true) {
|
|||||||
workingDir = rootDir
|
workingDir = rootDir
|
||||||
systemProperty("kotlin.script.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")
|
||||||
|
}
|
||||||
|
|||||||
+1
-1
@@ -255,7 +255,7 @@ class ScriptingHostTest : TestCase() {
|
|||||||
}
|
}
|
||||||
assertTrue(comp0 is ResultWithDiagnostics.Failure)
|
assertTrue(comp0 is ResultWithDiagnostics.Failure)
|
||||||
val errors = comp0.reports.filter { it.severity == ScriptDiagnostic.Severity.ERROR }
|
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
|
// runtime
|
||||||
fun evalWith(evalConfig: ScriptEvaluationConfiguration) =
|
fun evalWith(evalConfig: ScriptEvaluationConfiguration) =
|
||||||
|
|||||||
@@ -23,11 +23,17 @@ sourceSets {
|
|||||||
projectTest(parallel = true) {
|
projectTest(parallel = true) {
|
||||||
dependsOn(":dist")
|
dependsOn(":dist")
|
||||||
workingDir = rootDir
|
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) {
|
projectTest(taskName = "testWithIr", parallel = true) {
|
||||||
dependsOn(":dist")
|
dependsOn(":dist")
|
||||||
workingDir = rootDir
|
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")
|
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")
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ import kotlin.concurrent.thread
|
|||||||
|
|
||||||
const val SCRIPT_TEST_BASE_COMPILER_ARGUMENTS_PROPERTY = "kotlin.script.test.base.compiler.arguments"
|
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(' ')
|
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
|
// TODO: partially copypasted from LauncherReplTest, consider extracting common parts to some (new) test util module
|
||||||
|
|||||||
+42
-1
@@ -7,7 +7,9 @@ package org.jetbrains.kotlin.scripting.compiler.test
|
|||||||
|
|
||||||
import junit.framework.TestCase
|
import junit.framework.TestCase
|
||||||
import kotlinx.coroutines.runBlocking
|
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.scripting.compiler.plugin.impl.ScriptJvmCompilerIsolated
|
||||||
|
import org.jetbrains.kotlin.utils.tryConstructClassFromStringArgs
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
import kotlin.reflect.full.createInstance
|
import kotlin.reflect.full.createInstance
|
||||||
@@ -32,6 +34,40 @@ class ScriptCompilerTest : TestCase() {
|
|||||||
assertTrue(res.reports.none { it.message.contains("nonsense") })
|
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() {
|
fun testTypeAliases() {
|
||||||
val res = compileToClass(
|
val res = compileToClass(
|
||||||
"""
|
"""
|
||||||
@@ -78,7 +114,12 @@ class ScriptCompilerTest : TestCase() {
|
|||||||
script: SourceCode,
|
script: SourceCode,
|
||||||
cfgBody: ScriptCompilationConfiguration.Builder.() -> Unit
|
cfgBody: ScriptCompilationConfiguration.Builder.() -> Unit
|
||||||
): ResultWithDiagnostics<CompiledScript> {
|
): ResultWithDiagnostics<CompiledScript> {
|
||||||
val compilationConfiguration = ScriptCompilationConfiguration(cfgBody)
|
val compilationConfiguration = ScriptCompilationConfiguration {
|
||||||
|
cfgBody()
|
||||||
|
getBaseCompilerArgumentsFromProperty()?.let {
|
||||||
|
compilerOptions.append(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
val compiler = ScriptJvmCompilerIsolated(defaultJvmScriptingHostConfiguration)
|
val compiler = ScriptJvmCompilerIsolated(defaultJvmScriptingHostConfiguration)
|
||||||
return compiler.compile(script, compilationConfiguration)
|
return compiler.compile(script, compilationConfiguration)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user