[JVM] Port line number tests to stepping framework.

Allow specifying JVM and JVM_IR as well as shared expectations.

Add the method name to the step.

Discard steps in synthetic methods.
This commit is contained in:
Mads Ager
2020-05-19 16:34:59 +02:00
committed by max-kammerer
parent 4dbd4a56d5
commit 9fa1614903
59 changed files with 896 additions and 540 deletions
@@ -9,6 +9,7 @@ import com.sun.jdi.VirtualMachine
import com.sun.jdi.event.Event
import com.sun.jdi.event.LocatableEvent
import junit.framework.TestCase
import org.jetbrains.kotlin.test.TargetBackend
import org.junit.AfterClass
import org.junit.BeforeClass
import java.io.File
@@ -19,7 +20,10 @@ abstract class AbstractSteppingTest : AbstractDebugTest() {
override val proxyPort: Int = Companion.proxyPort
companion object {
const val LINENUMBER_PREFIX = "// LINENUMBERS"
const val LINENUMBERS_MARKER = "// LINENUMBERS"
const val FORCE_STEP_INTO_MARKER = "// FORCE_STEP_INTO"
const val JVM_LINENUMBER_MARKER = "$LINENUMBERS_MARKER JVM"
const val JVM_IR_LINENUMBER_MARKER = "$LINENUMBERS_MARKER JVM_IR"
var proxyPort = 0
lateinit var process: Process
lateinit var virtualMachine: VirtualMachine
@@ -47,17 +51,49 @@ abstract class AbstractSteppingTest : AbstractDebugTest() {
loggedItems.add(event)
}
data class SteppingExpectations(val forceStepInto: Boolean, val lineNumbers: String)
private fun readExpectations(wholeFile: File): SteppingExpectations {
val expected = mutableListOf<String>()
val lines = wholeFile.readLines().dropWhile {
!it.startsWith(LINENUMBERS_MARKER) && !it.startsWith(FORCE_STEP_INTO_MARKER)
}
var forceStepInto = false
var currentBackend = TargetBackend.ANY
for (line in lines) {
if (line.trim() == FORCE_STEP_INTO_MARKER) {
forceStepInto = true
continue
}
if (line.startsWith(LINENUMBERS_MARKER)) {
currentBackend = when (line) {
LINENUMBERS_MARKER -> TargetBackend.ANY
JVM_LINENUMBER_MARKER -> TargetBackend.JVM
JVM_IR_LINENUMBER_MARKER -> TargetBackend.JVM_IR
else -> error("Expected JVM backend")
}
continue
}
if (currentBackend == TargetBackend.ANY || currentBackend == backend) {
expected.add(line.drop(3).trim())
}
}
return SteppingExpectations(forceStepInto, expected.joinToString("\n"))
}
override fun checkResult(wholeFile: File, loggedItems: List<Any>) {
val expectedLineNumbers = wholeFile
.readLines()
.dropWhile { !it.startsWith(LINENUMBER_PREFIX) }
.drop(1)
.map { it.drop(3).trim() }
.joinToString("\n")
val (forceStepInto, expectedLineNumbers) = readExpectations(wholeFile)
val actualLineNumbers = loggedItems
.filter {
val location = (it as LocatableEvent).location()
// Ignore synthetic code with no line number information
// unless force step into behavior is requested.
forceStepInto || !location.method().isSynthetic
}
.map { event ->
val location = (event as LocatableEvent).location()
"${location.sourceName()}:${location.lineNumber()}"
val synthetic = if (location.method().isSynthetic) " (synthetic)" else ""
"${location.sourceName()}:${location.lineNumber()} ${location.method().name()}$synthetic"
}
TestCase.assertEquals(expectedLineNumbers, actualLineNumbers.joinToString("\n"))
}