Scripting: switch legacy CLI REPL to the new infrastructure

This commit is contained in:
Ilya Chernikov
2022-05-13 20:44:44 +02:00
committed by teamcity
parent 6784cb63aa
commit b36d1be5f8
16 changed files with 185 additions and 62 deletions
@@ -98,7 +98,7 @@ abstract class KotlinJsr223JvmScriptEngineBase(protected val myFactory: ScriptEn
is ReplEvalResult.Error ->
when {
result is ReplEvalResult.Error.Runtime && result.cause != null ->
throw ScriptException(result.cause)
throw ScriptException((result.cause as? java.lang.Exception) ?: RuntimeException(result.cause))
result is ReplEvalResult.Error.CompileTime && result.location != null ->
throw ScriptException(result.message, result.location.path, result.location.line, result.location.column)
else -> throw ScriptException(result.message)
@@ -148,7 +148,7 @@ sealed class ReplEvalResult : Serializable {
}
sealed class Error(val message: String) : ReplEvalResult() {
class Runtime(message: String, val cause: Exception? = null) : Error(message) {
class Runtime(message: String, val cause: Throwable? = null) : Error(message) {
companion object { private val serialVersionUID: Long = 1L }
}
+2
View File
@@ -1,5 +1,6 @@
>>> throw Exception("hi there")
java.lang.Exception: hi there
at Line_0.<init>(Line_0.kts:1)
>>> fun foo() = 2
>>> foo()
2
@@ -7,3 +8,4 @@ java.lang.Exception: hi there
>>> bar()
java.lang.AssertionError
at Line_3.bar(Line_3.kts:1)
at Line_4.<init>(Line_4.kts:1)
+1
View File
@@ -3,3 +3,4 @@
java.lang.IllegalStateException: message
at Line_0$B.foo(Line_0.kts:1)
at Line_0$B.toString(Line_0.kts:1)
at Line_1.<init>(Line_1.kts:1)
+3 -3
View File
@@ -2,7 +2,7 @@
java.lang.RuntimeException
at Line_0$x$1.invoke(Line_0.kts:1)
at Line_0$x$1.invoke(Line_0.kts:1)
at Line_0.<init>(Line_0.kts:1)
>>> x
error: unresolved reference: x
x
^
java.lang.NullPointerException
at Line_1.<init>(Line_1.kts:1)
-3
View File
@@ -2,9 +2,6 @@
error: expecting an element
)(
^
error: expecting an expression
)(
^
>>> fun foo() = 98
>>> foo()
98
@@ -17,7 +17,10 @@
package org.jetbrains.kotlin.repl
import com.intellij.openapi.util.text.StringUtil
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
import org.jetbrains.kotlin.cli.common.repl.ReplEvalResult
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.script.loadScriptingPlugin
import org.jetbrains.kotlin.scripting.compiler.plugin.repl.ReplInterpreter
import org.jetbrains.kotlin.scripting.compiler.plugin.repl.configuration.ConsoleReplConfiguration
@@ -86,8 +89,14 @@ abstract class AbstractReplInterpreterTest : KtUsefulTestCase() {
protected fun doTest(path: String) {
val configuration = KotlinTestUtils.newConfiguration(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK)
loadScriptingPlugin(configuration)
val projectEnvironment =
KotlinCoreEnvironment.ProjectEnvironment(
testRootDisposable,
KotlinCoreEnvironment.getOrCreateApplicationEnvironmentForTests(testRootDisposable, configuration),
configuration
)
val repl = ReplInterpreter(
testRootDisposable, configuration,
projectEnvironment, configuration,
ConsoleReplConfiguration()
)
@@ -100,6 +109,7 @@ abstract class AbstractReplInterpreterTest : KtUsefulTestCase() {
val actual = when (lineResult) {
is ReplEvalResult.ValueResult -> lineResult.value.toString()
is ReplEvalResult.Error.CompileTime -> MessageRenderer.WITHOUT_PATHS.render(CompilerMessageSeverity.ERROR, lineResult.message, lineResult.location)
is ReplEvalResult.Error -> lineResult.message
is ReplEvalResult.Incomplete -> INCOMPLETE_LINE_MESSAGE
is ReplEvalResult.UnitResult -> ""