Properly handle REPL snippets with exceptions ...
so the REPL remain operational after exception in one of the snippets: - separately return script class and script instance on evaluation ( because in case of an exception the class is valid, while the instance is not). - store both the class and the instance in the history - handle this data accordingly
This commit is contained in:
+17
@@ -85,6 +85,23 @@ class KotlinJsr223ScriptEngineIT {
|
||||
Assert.assertEquals(5, res3)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEvalWithException() {
|
||||
val engine = ScriptEngineManager().getEngineByExtension("kts")!!
|
||||
try {
|
||||
engine.eval("throw Exception(\"!!\")")
|
||||
Assert.fail("Expecting exception to propagate")
|
||||
} catch (e: ScriptException) {
|
||||
Assert.assertEquals("!!", e.cause?.message)
|
||||
}
|
||||
// engine should remain operational
|
||||
val res1 = engine.eval("val x = 3")
|
||||
Assert.assertNull(res1)
|
||||
val res2 = engine.eval("x + 4")
|
||||
Assert.assertEquals(7, res2)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun testEngineRepeatWithReset() {
|
||||
val code = "open class A {}\n" +
|
||||
|
||||
Reference in New Issue
Block a user