Scripting: switch legacy CLI REPL to the new infrastructure
This commit is contained in:
@@ -98,6 +98,10 @@ data class ScriptDiagnostic(
|
||||
}
|
||||
}
|
||||
|
||||
fun ScriptDiagnostic.isError() =
|
||||
(severity == ScriptDiagnostic.Severity.ERROR || severity == ScriptDiagnostic.Severity.FATAL) &&
|
||||
(code == ScriptDiagnostic.unspecifiedException || code == ScriptDiagnostic.unspecifiedError)
|
||||
|
||||
/**
|
||||
* The result wrapper with diagnostics container
|
||||
*/
|
||||
|
||||
+4
-2
@@ -456,8 +456,10 @@ class ReplTest : TestCase() {
|
||||
is ResultValue.Unit -> Assert.assertNull("#$index: Expected $expectedVal, got Unit", expectedVal)
|
||||
is ResultValue.Error -> Assert.assertTrue(
|
||||
"#$index: Expected $expectedVal, got Error: ${actualVal.error}",
|
||||
expectedVal is Throwable && expectedVal.message == actualVal.error.message
|
||||
&& expectedVal.cause?.message == actualVal.error.cause?.message
|
||||
((expectedVal as? Throwable) ?: (expectedVal as? ResultValue.Error)?.error).let {
|
||||
it != null && it.message == actualVal.error.message
|
||||
&& it.cause?.message == actualVal.error.cause?.message
|
||||
}
|
||||
)
|
||||
is ResultValue.NotEvaluated -> Assert.assertEquals(
|
||||
"#$index: Expected $expectedVal, got NotEvaluated",
|
||||
|
||||
+1
-1
@@ -298,7 +298,7 @@ class ScriptingHostTest : TestCase() {
|
||||
"println(\"$greeting\")".toScriptSource(),
|
||||
{},
|
||||
{
|
||||
scriptExecutionWrapper {
|
||||
scriptExecutionWrapper<Any?> {
|
||||
val outStream = ByteArrayOutputStream()
|
||||
val prevOut = System.out
|
||||
System.setOut(PrintStream(outStream))
|
||||
|
||||
@@ -57,8 +57,13 @@ class BasicJvmReplEvaluator(val scriptEvaluator: ScriptEvaluator = BasicJvmScrip
|
||||
}
|
||||
KJvmEvaluatedSnippet(snippetVal, currentConfiguration, retVal)
|
||||
}
|
||||
else ->
|
||||
KJvmEvaluatedSnippet(snippetVal, currentConfiguration, ResultValue.NotEvaluated)
|
||||
else -> {
|
||||
val firstError = evalRes.reports.find { it.isError() }
|
||||
KJvmEvaluatedSnippet(
|
||||
snippetVal, currentConfiguration,
|
||||
firstError?.exception?.let { ResultValue.Error(it) } ?: ResultValue.NotEvaluated
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val newNode = lastEvaluatedSnippet.add(newEvalRes)
|
||||
|
||||
+9
@@ -5,6 +5,7 @@
|
||||
|
||||
package kotlin.script.experimental.jvm.util
|
||||
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.PrintStream
|
||||
import kotlin.script.experimental.api.ResultValue
|
||||
|
||||
@@ -42,3 +43,11 @@ fun ResultValue.Error.renderError(stream: PrintStream) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun ResultValue.Error.renderError(): String =
|
||||
ByteArrayOutputStream().use { os ->
|
||||
val ps = PrintStream(os)
|
||||
renderError(ps)
|
||||
ps.flush()
|
||||
os.toString()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user