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:
Ilya Chernikov
2019-07-25 15:23:58 +02:00
parent 288fdc0952
commit ec3ccf1ba8
6 changed files with 52 additions and 26 deletions
@@ -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" +