Introduce FIR_IDENTICAL for FIR vs old frontend tests #KT-36879 Fixed

This commit is contained in:
Mikhail Glukhikh
2020-03-04 17:54:33 +03:00
parent 186e0b0cba
commit 8884cbe415
2268 changed files with 1175 additions and 19754 deletions
@@ -12,7 +12,7 @@ import java.io.File
abstract class AbstractFirOldFrontendDiagnosticsTest : AbstractFirDiagnosticsTest() {
override fun createTestFileFromPath(filePath: String): File {
val newPath = filePath.replace(".kt", ".fir.kt")
val newPath = if (File(filePath).readText().contains("// FIR_IDENTICAL")) filePath else filePath.replace(".kt", ".fir.kt")
return File(newPath).also {
prepareTestDataFile(filePath, it)
}
@@ -40,6 +40,11 @@ abstract class AbstractFirOldFrontendDiagnosticsTest : AbstractFirDiagnosticsTes
checkResultingFirFiles(allFirFiles, testDataFile)
assertFalse("Test is good but there is expected exception", failureFile.exists())
checkDiagnostics(testDataFile, testFiles, allFirFiles)
if (testDataFile.absolutePath.endsWith(".fir.kt")) {
val oldFrontendTestDataFile = File(testDataFile.absolutePath.replace(".fir.kt", ".kt"))
compareAndMergeFirFileAndOldFrontendFile(oldFrontendTestDataFile, testDataFile)
}
val needDump = testFiles.any { it.directives.containsKey("FIR_DUMP") }
if (needDump) {
checkFir(testDataFile, allFirFiles)
@@ -0,0 +1,31 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir
import junit.framework.TestCase
import java.io.File
fun compareAndMergeFirFileAndOldFrontendFile(oldFrontendTestDataFile: File, frontendIRTestDataFile: File) {
if (oldFrontendTestDataFile.exists() && frontendIRTestDataFile.exists()) {
val originalLines = oldFrontendTestDataFile.readLines()
val firLines = frontendIRTestDataFile.readLines()
val sameDumps = firLines.withIndex().all { (index, line) ->
val trimmed = line.trim()
val originalTrimmed = originalLines.getOrNull(index)?.trim()
trimmed.isEmpty() && originalTrimmed?.isEmpty() != false || trimmed == originalTrimmed
} && originalLines.withIndex().all { (index, line) ->
index < firLines.size || line.trim().isEmpty()
}
if (sameDumps) {
frontendIRTestDataFile.delete()
oldFrontendTestDataFile.writeText("// FIR_IDENTICAL\n" + oldFrontendTestDataFile.readText())
}
TestCase.assertFalse(
"Dumps via FIR & via old FE are the same. Deleted .fir.txt dump, added // FIR_IDENTICAL to test source",
sameDumps
)
}
}