Fix dependencies for Olive, add tests for basic scripting
This commit is contained in:
@@ -2,13 +2,8 @@ dependencies {
|
|||||||
implementation project(":orx-file-watcher")
|
implementation project(":orx-file-watcher")
|
||||||
|
|
||||||
// -- JSR 223, old style script loader
|
// -- JSR 223, old style script loader
|
||||||
api "org.jetbrains.kotlin:kotlin-scripting-jsr223:$kotlinVersion"
|
implementation "org.jetbrains.kotlin:kotlin-scripting-jvm:$kotlinVersion"
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-scripting-jvm-host:$kotlinVersion"
|
||||||
api "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
|
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
|
||||||
api "org.jetbrains.kotlin:kotlin-scripting-jvm-host-embeddable:$kotlinVersion"
|
implementation "org.jetbrains.kotlin:kotlin-scripting-jsr223:$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"
|
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
18
orx-olive/src/test/kotlin/TestLoadScript.kt
Normal file
18
orx-olive/src/test/kotlin/TestLoadScript.kt
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
17
orx-olive/src/test/kotlin/TestLoadScriptKSH.kt
Normal file
17
orx-olive/src/test/kotlin/TestLoadScriptKSH.kt
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user