Add appropriate script extension to the source name, if not provided
#KT-31704 fixed
This commit is contained in:
+20
@@ -27,7 +27,9 @@ import kotlin.script.experimental.host.BasicScriptingHost
|
||||
import kotlin.script.experimental.host.FileBasedScriptSource
|
||||
import kotlin.script.experimental.host.toScriptSource
|
||||
import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
|
||||
import kotlin.script.experimental.jvm.dependenciesFromCurrentContext
|
||||
import kotlin.script.experimental.jvm.impl.KJvmCompiledScript
|
||||
import kotlin.script.experimental.jvm.jvm
|
||||
import kotlin.script.experimental.jvm.updateClasspath
|
||||
import kotlin.script.experimental.jvm.util.KotlinJars
|
||||
import kotlin.script.experimental.jvm.util.classpathFromClass
|
||||
@@ -54,6 +56,24 @@ class ScriptingHostTest : TestCase() {
|
||||
Assert.assertEquals(greeting, output2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSourceWithName() {
|
||||
val greeting = "Hello from script!"
|
||||
val output = captureOut {
|
||||
val basicJvmScriptingHost = BasicJvmScriptingHost()
|
||||
basicJvmScriptingHost.eval(
|
||||
"println(\"$greeting\")".toScriptSource("name"),
|
||||
createJvmCompilationConfigurationFromTemplate<SimpleScript>(basicJvmScriptingHost.hostConfiguration) {
|
||||
jvm {
|
||||
dependenciesFromCurrentContext(wholeClasspath = true)
|
||||
}
|
||||
},
|
||||
createJvmEvaluationConfigurationFromTemplate<SimpleScript>(basicJvmScriptingHost.hostConfiguration)
|
||||
).throwOnFailure()
|
||||
}
|
||||
Assert.assertEquals(greeting, output)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testValueResult() {
|
||||
val resVal = evalScriptWithResult("42") as ResultValue.Value
|
||||
|
||||
Reference in New Issue
Block a user