Make expectations in stepping tests more flexible
We can now write expectations in the following form: // EXPECTATIONS [backends...] [frontends...] Backends are specified as in the TargetBackend enum. Frontends are specified as in the FrontendKinds object. This will make it more suitable for supporting Kotlin/JS in stepping tests. For example, for expectations that match only JVM backends with the classic frontend, we use: // EXPECTATIONS JVM JVM_IR ClassicFrontend
This commit is contained in:
+21
-26
@@ -9,16 +9,13 @@ import org.jetbrains.kotlin.test.TargetBackend
|
|||||||
import org.jetbrains.kotlin.test.model.FrontendKind
|
import org.jetbrains.kotlin.test.model.FrontendKind
|
||||||
import org.jetbrains.kotlin.test.model.FrontendKinds
|
import org.jetbrains.kotlin.test.model.FrontendKinds
|
||||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertEqualsToFile
|
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertEqualsToFile
|
||||||
|
import org.jetbrains.kotlin.test.services.impl.valueOfOrNull
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
data class SteppingTestLoggedData(val line: Int, val isSynthetic: Boolean, val expectation: String)
|
data class SteppingTestLoggedData(val line: Int, val isSynthetic: Boolean, val expectation: String)
|
||||||
|
|
||||||
private const val EXPECTATIONS_MARKER = "// EXPECTATIONS"
|
private const val EXPECTATIONS_MARKER = "// EXPECTATIONS"
|
||||||
private const val FORCE_STEP_INTO_MARKER = "// FORCE_STEP_INTO"
|
private const val FORCE_STEP_INTO_MARKER = "// FORCE_STEP_INTO"
|
||||||
private const val JVM_EXPECTATIONS_MARKER = "$EXPECTATIONS_MARKER JVM"
|
|
||||||
private const val JVM_IR_EXPECTATIONS_MARKER = "$EXPECTATIONS_MARKER JVM_IR"
|
|
||||||
private const val CLASSIC_FRONTEND_EXPECTATIONS_MARKER = "$EXPECTATIONS_MARKER CLASSIC_FRONTEND"
|
|
||||||
private const val FIR_EXPECTATIONS_MARKER = "$EXPECTATIONS_MARKER FIR"
|
|
||||||
|
|
||||||
fun checkSteppingTestResult(
|
fun checkSteppingTestResult(
|
||||||
frontendKind: FrontendKind<*>,
|
frontendKind: FrontendKind<*>,
|
||||||
@@ -38,14 +35,19 @@ fun checkSteppingTestResult(
|
|||||||
.map { "// ${it.expectation}" }
|
.map { "// ${it.expectation}" }
|
||||||
val actualLineNumbersIterator = actualLineNumbers.iterator()
|
val actualLineNumbersIterator = actualLineNumbers.iterator()
|
||||||
|
|
||||||
val lineIterator = lines.iterator()
|
val lineIterator = lines.listIterator()
|
||||||
for (line in lineIterator) {
|
for (line in lineIterator) {
|
||||||
|
if (line.startsWith(EXPECTATIONS_MARKER)) {
|
||||||
|
// Rewind the iterator to the first '// EXPECTATIONS' line
|
||||||
|
if (lineIterator.hasPrevious()) lineIterator.previous()
|
||||||
|
break
|
||||||
|
}
|
||||||
actual.add(line)
|
actual.add(line)
|
||||||
if (line.startsWith(EXPECTATIONS_MARKER) || line.startsWith(FORCE_STEP_INTO_MARKER)) break
|
if (line.startsWith(FORCE_STEP_INTO_MARKER)) break
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentBackend = TargetBackend.ANY
|
var currentBackends = setOf(TargetBackend.ANY)
|
||||||
var currentFrontend = frontendKind
|
var currentFrontends = setOf(frontendKind)
|
||||||
for (line in lineIterator) {
|
for (line in lineIterator) {
|
||||||
if (line.isEmpty()) {
|
if (line.isEmpty()) {
|
||||||
actual.add(line)
|
actual.add(line)
|
||||||
@@ -53,26 +55,19 @@ fun checkSteppingTestResult(
|
|||||||
}
|
}
|
||||||
if (line.startsWith(EXPECTATIONS_MARKER)) {
|
if (line.startsWith(EXPECTATIONS_MARKER)) {
|
||||||
actual.add(line)
|
actual.add(line)
|
||||||
currentBackend = when (line) {
|
val backendsAndFrontends = line.removePrefix(EXPECTATIONS_MARKER).splitToSequence(Regex("\\s+")).filter { it.isNotEmpty() }
|
||||||
EXPECTATIONS_MARKER -> TargetBackend.ANY
|
currentBackends = backendsAndFrontends
|
||||||
JVM_EXPECTATIONS_MARKER -> TargetBackend.JVM
|
.mapNotNullTo(mutableSetOf()) { valueOfOrNull<TargetBackend>(it) }
|
||||||
JVM_IR_EXPECTATIONS_MARKER -> TargetBackend.JVM_IR
|
.takeIf { it.isNotEmpty() }
|
||||||
CLASSIC_FRONTEND_EXPECTATIONS_MARKER -> currentBackend
|
?: setOf(TargetBackend.ANY)
|
||||||
FIR_EXPECTATIONS_MARKER -> currentBackend
|
currentFrontends = backendsAndFrontends
|
||||||
else -> error("Expected JVM backend: $line")
|
.mapNotNullTo(mutableSetOf(), FrontendKinds::fromString)
|
||||||
}
|
.takeIf { it.isNotEmpty() }
|
||||||
currentFrontend = when (line) {
|
?: setOf(frontendKind)
|
||||||
EXPECTATIONS_MARKER -> frontendKind
|
|
||||||
JVM_EXPECTATIONS_MARKER -> currentFrontend
|
|
||||||
JVM_IR_EXPECTATIONS_MARKER -> currentFrontend
|
|
||||||
CLASSIC_FRONTEND_EXPECTATIONS_MARKER -> FrontendKinds.ClassicFrontend
|
|
||||||
FIR_EXPECTATIONS_MARKER -> FrontendKinds.FIR
|
|
||||||
else -> error("Expected JVM backend: $line")
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if ((currentBackend == TargetBackend.ANY || currentBackend == targetBackend) &&
|
if ((currentBackends.contains(TargetBackend.ANY) || currentBackends.contains(targetBackend)) &&
|
||||||
currentFrontend == frontendKind
|
currentFrontends.contains(frontendKind)
|
||||||
) {
|
) {
|
||||||
if (actualLineNumbersIterator.hasNext()) {
|
if (actualLineNumbersIterator.hasNext()) {
|
||||||
actual.add(actualLineNumbersIterator.next())
|
actual.add(actualLineNumbersIterator.next())
|
||||||
|
|||||||
Reference in New Issue
Block a user