Add info about the end of range in scripting REPL compiler messages
This commit is contained in:
committed by
Ilya Chernikov
parent
a70a128d9e
commit
af251cafa4
+30
-3
@@ -10,7 +10,6 @@ import kotlinx.coroutines.runBlocking
|
||||
import org.jetbrains.kotlin.cli.common.repl.BasicReplStageHistory
|
||||
import org.jetbrains.kotlin.descriptors.ScriptDescriptor
|
||||
import org.jetbrains.kotlin.scripting.compiler.plugin.impl.KJvmReplCompilerImpl
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import kotlin.script.experimental.api.*
|
||||
@@ -96,6 +95,27 @@ class ReplTest : TestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEvalWithErrorWithLocation() {
|
||||
checkEvaluateInReplDiags(
|
||||
sequenceOf(
|
||||
"""
|
||||
val foobar = 78
|
||||
val foobaz = "dsdsda"
|
||||
val ddd = ppp
|
||||
val ooo = foobar
|
||||
""".trimIndent()
|
||||
),
|
||||
sequenceOf(
|
||||
makeFailureResult(
|
||||
"Unresolved reference: ppp", location = SourceCode.Location(
|
||||
SourceCode.Position(3, 11), SourceCode.Position(3, 14)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSyntaxErrors() {
|
||||
checkEvaluateInReplDiags(
|
||||
@@ -152,7 +172,8 @@ fun evaluateInRepl(
|
||||
var currentEvalConfig = evaluationConfiguration ?: ScriptEvaluationConfiguration()
|
||||
val snipetsLimited = if (limit == 0) snippets else snippets.take(limit)
|
||||
return snipetsLimited.mapIndexed { snippetNo, snippetText ->
|
||||
val snippetSource = snippetText.toScriptSource("Line_$snippetNo.${compilationConfiguration[ScriptCompilationConfiguration.fileExtension]}")
|
||||
val snippetSource =
|
||||
snippetText.toScriptSource("Line_$snippetNo.${compilationConfiguration[ScriptCompilationConfiguration.fileExtension]}")
|
||||
val snippetId = ReplSnippetIdImpl(snippetNo, 0, snippetSource)
|
||||
replCompilerProxy.compileReplSnippet(compilationState, snippetSource, snippetId, compilationHistory)
|
||||
.onSuccess {
|
||||
@@ -188,9 +209,15 @@ fun checkEvaluateInReplDiags(
|
||||
when {
|
||||
res is ResultWithDiagnostics.Failure && expectedRes is ResultWithDiagnostics.Failure -> {
|
||||
Assert.assertTrue(
|
||||
"#$index: Expected $expectedRes, got $res",
|
||||
"#$index: Expected $expectedRes, got $res. Messages are different",
|
||||
res.reports.map { it.message } == expectedRes.reports.map { it.message }
|
||||
)
|
||||
Assert.assertTrue(
|
||||
"#$index: Expected $expectedRes, got $res. Locations are different",
|
||||
res.reports.map { it.location }.zip(expectedRes.reports.map { it.location }).all {
|
||||
it.second == null || it.second == it.first
|
||||
}
|
||||
)
|
||||
}
|
||||
res is ResultWithDiagnostics.Success && expectedRes is ResultWithDiagnostics.Success -> {
|
||||
val expectedVal = expectedRes.value
|
||||
|
||||
Reference in New Issue
Block a user