Fix dependencies for Olive, add tests for basic scripting

This commit is contained in:
Edwin Jakobs
2020-04-11 11:03:20 +02:00
parent 8c591c4830
commit a0fd51c3c2
4 changed files with 54 additions and 10 deletions

View File

@@ -2,13 +2,8 @@ dependencies {
implementation project(":orx-file-watcher")
// -- JSR 223, old style script loader
api "org.jetbrains.kotlin:kotlin-scripting-jsr223:$kotlinVersion"
api "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
api "org.jetbrains.kotlin:kotlin-scripting-jvm-host-embeddable:$kotlinVersion"
api "org.jetbrains.kotlin:kotlin-scripting-common:$kotlinVersion"
api "org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:$kotlinVersion"
api "org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion"
api "org.jetbrains.kotlin:kotlin-compiler:$kotlinVersion"
api "org.jetbrains.kotlin:kotlin-script-runtime:$kotlinVersion"
implementation "org.jetbrains.kotlin:kotlin-scripting-jvm:$kotlinVersion"
implementation "org.jetbrains.kotlin:kotlin-scripting-jvm-host:$kotlinVersion"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
implementation "org.jetbrains.kotlin:kotlin-scripting-jsr223:$kotlinVersion"
}

View File

@@ -30,6 +30,20 @@ fun <T> loadFromScriptKSH(
}
}
): T = (evalScriptWithConfiguration(script.readText(), host, body).valueOrThrow().returnValue as ResultValue.Value).value as T
): T = loadFromScriptKSH(script.readText(), host, body)
@Suppress("UNCHECKED_CAST")
fun <T> loadFromScriptKSH(
script: String,
host: BasicScriptingHost = BasicJvmScriptingHost(),
body: ScriptCompilationConfiguration.Builder.() -> Unit = {
jvm {
dependenciesFromCurrentContext(wholeClasspath = true)
}
}
): T = (evalScriptWithConfiguration(script, host, body).valueOrThrow().returnValue as ResultValue.Value).value as T

View File

@@ -0,0 +1,18 @@
import org.amshove.kluent.`should be equal to`
import org.openrndr.extra.olive.ScriptObjectLoader
import org.openrndr.extra.olive.loadFromScript
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
object TestLoadScript : Spek({
describe("some script") {
val loader = ScriptObjectLoader()
val number = loader.load<Int>("5")
it("should evaluate properly") {
number `should be equal to` 5
}
}
})

View File

@@ -0,0 +1,17 @@
import org.amshove.kluent.`should be equal to`
import org.openrndr.extra.olive.ScriptObjectLoader
import org.openrndr.extra.olive.loadFromScript
import org.openrndr.extra.olive.loadFromScriptKSH
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
object TestLoadScriptKSH : Spek({
describe("some script") {
val number = loadFromScriptKSH<Int>("5")
it("should evaluate properly") {
number `should be equal to` 5
}
}
})