K2 Scripting: add support for script implicit receivers

This commit is contained in:
Ilya Chernikov
2023-05-03 15:54:13 +02:00
committed by Space Team
parent 480ea80fc4
commit 6c7751b0af
4 changed files with 44 additions and 13 deletions
@@ -110,7 +110,7 @@ class CachingTest : TestCase() {
}
@Test
fun testImplicitReceiversWithJarCache() = expectTestToFailOnK2 {
fun testImplicitReceiversWithJarCache() {
withTempDir("scriptingTestJarCache") { cacheDir ->
val cache = TestCompiledScriptJarsCache(cacheDir)
Assert.assertTrue(cache.baseDir.listFiles()!!.isEmpty())
@@ -24,7 +24,7 @@ class ConstructorArgumentsOrderTest {
}
@Test
fun testScriptWithImplicitReceiver() = expectTestToFailOnK2 {
fun testScriptWithImplicitReceiver() {
val res = evalString<ScriptWithImplicitReceiver>("""println(receiverString)""") {
implicitReceivers(ImplicitReceiverClass("Hello Receiver!"))
}
@@ -223,6 +223,27 @@ class ScriptingHostTest : TestCase() {
Assert.assertEquals(greeting, output)
}
@Test
fun testSimpleScriptWithImplicitReceiver() {
val greeting = listOf("3")
val script = "println(length)"
val definition = createJvmScriptDefinitionFromTemplate<SimpleScriptTemplate>(
compilation = {
implicitReceivers(String::class)
},
evaluation = {
implicitReceivers("abc")
}
)
val output = captureOut {
val retVal = BasicJvmScriptingHost().eval(
script.toScriptSource(), definition.compilationConfiguration, definition.evaluationConfiguration
).valueOrThrow().returnValue
if (retVal is ResultValue.Error) throw retVal.error
}.lines()
Assert.assertEquals(greeting, output)
}
@Test
fun testProvidedPropertiesNullability() = expectTestToFailOnK2 {
val stringType = KotlinType(String::class)