Kotlin/kotlin-script-examples

Using ScriptEngineManager to eval a class script file returns null

jpicklyk opened this issue · 0 comments

Kotlin version 1.8.20

Simple class defined in a file called simple.kts
class Test {
val x = 5
}

Testing the Script Engine Manager using the following:
@test
fun testClassCompile() {
val scriptReader = this::class.java.classLoader.getResource("simple.kts").openStream().reader()
val engine = ScriptEngineManager().getEngineByExtension("kts")
try {
val result = engine.eval(scriptReader)
assertNotNull(result)
}catch (se: ScriptException) {
fail()
}
}

If I am not mistaken this test should be returning an Object of type Class and not null. Please correct me if I am incorrect or have misunderstood how to get the Class object back.