K2 Scripting: add support for result field

This commit is contained in:
Ilya Chernikov
2023-04-28 17:11:56 +02:00
committed by Space Team
parent 6c7751b0af
commit d24fc3b581
20 changed files with 87 additions and 25 deletions
@@ -20,7 +20,6 @@ import kotlin.script.experimental.host.toScriptSource
import kotlin.script.experimental.host.with
import kotlin.script.experimental.jvm.*
import kotlin.script.experimental.jvm.impl.KJvmCompiledScript
import kotlin.script.experimental.jvm.loadDependencies
import kotlin.script.experimental.jvm.util.KotlinJars
import kotlin.script.experimental.jvm.util.classpathFromClass
import kotlin.script.experimental.jvmhost.BasicJvmScriptingHost
@@ -181,7 +180,7 @@ class CachingTest : TestCase() {
}
@Test
fun testLocalDependencyWithExternalLoadAndCache() = expectTestToFailOnK2 {
fun testLocalDependencyWithExternalLoadAndCache() {
withTempDir("scriptingTestDepDir") { depDir ->
val standardJars = KotlinJars.kotlinScriptStandardJars
val outJar = makeDependenciesJar(depDir, standardJars)
@@ -13,7 +13,7 @@ import kotlin.test.assertTrue
class CapturingTest {
@Test
fun testScriptWithImplicitReceiverAndSimpleCapturing() = expectTestToFailOnK2 {
fun testScriptWithImplicitReceiverAndSimpleCapturing() {
// Reproducing (a bit extended) scenario from KT-53947: without the fix, in the presence of the implicit receiver
// of the same type as the receiver in the `apply` function body, the lowering was incorrectly substituting
// the correct receiver with the accessor to the implicit one
@@ -36,7 +36,7 @@ class CapturingTest {
}
@Test
fun testScriptWithImplicitReceiverAndNoCapturing() = expectTestToFailOnK2 {
fun testScriptWithImplicitReceiverAndNoCapturing() {
// Reproducing (a bit extended) scenario from KT-53947: without the fix, in the presence of the implicit receiver
// of the same type as the receiver in the `C2.apply` function body, the lowering was incorrectly substituting
// the correct receiver with the accessor to the implicit one
@@ -49,7 +49,7 @@ class ResolveDependenciesTest : TestCase() {
}
@Test
fun testResolveClassFromClasspath() = expectTestToFailOnK2 {
fun testResolveClassFromClasspath() {
runScriptAndCheckResult(classAccessScript, configurationWithDependenciesFromClasspath, null, 42)
runScriptAndCheckResult(classImportScript, configurationWithDependenciesFromClasspath, null, 42)
}
@@ -76,7 +76,7 @@ class ResolveDependenciesTest : TestCase() {
}
@Test
fun testResolveFunAndValFromClasspath() = expectTestToFailOnK2 {
fun testResolveFunAndValFromClasspath() {
runScriptAndCheckResult(funAndValAccessScript, configurationWithDependenciesFromClasspath, null, 42)
runScriptAndCheckResult(funAndValImportScript, configurationWithDependenciesFromClasspath, null, 42)
}
@@ -65,13 +65,14 @@ class ScriptingHostTest : TestCase() {
}
@Test
fun testValueResult() = expectTestToFailOnK2 {
fun testValueResult() {
val evalScriptWithResult = evalScriptWithResult("42")
val resVal = evalScriptWithResult as ResultValue.Value
Assert.assertEquals(42, resVal.value)
Assert.assertEquals("\$\$result", resVal.name)
Assert.assertEquals("kotlin.Int", resVal.type)
val resField = resVal.scriptInstance!!::class.java.getDeclaredField("\$\$result")
resField.setAccessible(true)
Assert.assertEquals(42, resField.get(resVal.scriptInstance!!))
}
@@ -91,7 +92,7 @@ class ScriptingHostTest : TestCase() {
}
@Test
fun testCustomResultField() = expectTestToFailOnK2 {
fun testCustomResultField() {
val resVal = evalScriptWithResult("42") {
resultField("outcome")
} as ResultValue.Value
@@ -245,7 +246,7 @@ class ScriptingHostTest : TestCase() {
}
@Test
fun testProvidedPropertiesNullability() = expectTestToFailOnK2 {
fun testProvidedPropertiesNullability() {
val stringType = KotlinType(String::class)
val definition = createJvmScriptDefinitionFromTemplate<SimpleScriptTemplate>(
compilation = {