Pass provided script configuration to refining code
when script compilation configuration refinement happening during parsing, the updated configuration passed to the script compiler/REPL compile function is now used. #KT-44580 fixed
This commit is contained in:
+43
@@ -14,6 +14,8 @@ import kotlin.script.experimental.api.*
|
||||
import kotlin.script.experimental.host.toScriptSource
|
||||
import kotlin.script.experimental.jvm.BasicJvmReplEvaluator
|
||||
import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
|
||||
import kotlin.script.experimental.jvm.updateClasspath
|
||||
import kotlin.script.experimental.jvm.util.classpathFromClass
|
||||
|
||||
class ReplTest : TestCase() {
|
||||
|
||||
@@ -191,6 +193,44 @@ class ReplTest : TestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAddNewAnnotationHandler() {
|
||||
val replCompiler = KJvmReplCompilerBase.create(defaultJvmScriptingHostConfiguration)
|
||||
val replEvaluator = BasicJvmReplEvaluator()
|
||||
val compilationConfiguration = ScriptCompilationConfiguration().with {
|
||||
updateClasspath(classpathFromClass<NewAnn>())
|
||||
}
|
||||
val evaluationConfiguration = ScriptEvaluationConfiguration()
|
||||
|
||||
val res0 = runBlocking {
|
||||
replCompiler.compile("1".toScriptSource("Line_0.kts"), compilationConfiguration).onSuccess {
|
||||
replEvaluator.eval(it, evaluationConfiguration)
|
||||
}
|
||||
}
|
||||
assertTrue("Expecting 1 got $res0", res0 is ResultWithDiagnostics.Success && (res0.value.get().result as ResultValue.Value).value == 1)
|
||||
|
||||
var handlerInvoked = false
|
||||
|
||||
val compilationConfiguration2 = compilationConfiguration.with {
|
||||
refineConfiguration {
|
||||
// defaultImports(NewAnn::class) // TODO: fix support for default imports
|
||||
onAnnotations<NewAnn> {
|
||||
handlerInvoked = true
|
||||
it.compilationConfiguration.asSuccess()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val res1 = runBlocking {
|
||||
replCompiler.compile("@file:kotlin.script.experimental.jvmhost.test.NewAnn()\n2".toScriptSource("Line_1.kts"), compilationConfiguration2).onSuccess {
|
||||
replEvaluator.eval(it, evaluationConfiguration)
|
||||
}
|
||||
}
|
||||
assertTrue("Expecting 2 got $res1", res1 is ResultWithDiagnostics.Success && (res1.value.get().result as ResultValue.Value).value == 2)
|
||||
|
||||
assertTrue("Refinement handler on annotation is not invoked", handlerInvoked)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private fun evaluateInRepl(
|
||||
snippets: Sequence<String>,
|
||||
@@ -300,3 +340,6 @@ class ReplTest : TestCase() {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Target(AnnotationTarget.FILE)
|
||||
annotation class NewAnn
|
||||
|
||||
Reference in New Issue
Block a user