Created
October 9, 2018 21:09
-
-
Save lburgazzoli/5818679786271f8ea86c5729c9f74ea2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NewScriptTest { | |
@Test | |
@Throws(Exception::class) | |
fun `load new script`() { | |
val script = """ | |
println("hello kts!") | |
""" | |
val cache = object: CompiledJvmScriptsCache { | |
val data = hashMapOf<Pair<SourceCode, ScriptCompilationConfiguration>, CompiledScript<*>>() | |
override fun get( | |
script: SourceCode, | |
scriptCompilationConfiguration: ScriptCompilationConfiguration): CompiledScript<*>? { | |
return data[script to scriptCompilationConfiguration] | |
} | |
override fun store( | |
compiledScript: CompiledScript<*>, | |
script: SourceCode, | |
scriptCompilationConfiguration: ScriptCompilationConfiguration) { | |
data[script to scriptCompilationConfiguration] = compiledScript | |
} | |
} | |
val compiler = JvmScriptCompiler(defaultJvmScriptingHostConfiguration, cache = cache) | |
val evaluator = BasicJvmScriptEvaluator() | |
val host = BasicJvmScriptingHost(compiler = compiler, evaluator = evaluator) | |
val compilationConfiguration = createJvmCompilationConfigurationFromTemplate<SimpleScriptTemplate>() | |
val res = host.eval(script.toScriptSource(), compilationConfiguration, null) | |
for (rep in res.reports) { | |
println("res: " + rep.exception) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment