[FIR] Fix TEST SPEC tests

Ensure the test data contents for both the frontends
are identical. This is needed for proper analysis of
K2-differences.
This commit is contained in:
Nikolay Lunyak
2023-06-12 15:20:46 +03:00
committed by Space Team
parent e6633d3d92
commit 7541732752
583 changed files with 4053 additions and 5418 deletions
@@ -16,6 +16,8 @@ import org.jetbrains.kotlin.test.runners.AbstractFirPsiDiagnosticTest
import org.jetbrains.kotlin.test.runners.AbstractKotlinCompilerTest
import org.jetbrains.kotlin.test.services.*
import org.jetbrains.kotlin.test.utils.firTestDataFile
import org.jetbrains.kotlin.test.utils.isFirTestData
import org.jetbrains.kotlin.test.utils.originalTestDataFile
import java.io.File
open class FirTestDataConsistencyHandler(testServices: TestServices) : AfterAnalysisChecker(testServices) {
@@ -27,16 +29,19 @@ open class FirTestDataConsistencyHandler(testServices: TestServices) : AfterAnal
val testData = moduleStructure.originalTestDataFiles.first()
if (testData.extension == "kts") return
if (FirDiagnosticsDirectives.FIR_IDENTICAL in moduleStructure.allDirectives) return
val firTestData = testData.firTestDataFile
val (firTestData, originalTestData) = when {
testData.isFirTestData -> testData to testData.originalTestDataFile
else -> testData.firTestDataFile to testData
}
if (!firTestData.exists()) {
runFirTestAndGeneratedTestData(testData, firTestData)
return
}
val firPreprocessedTextData = firTestData.preprocessSource()
val originalPreprocessedTextData = testData.preprocessSource()
val originalPreprocessedTextData = originalTestData.preprocessSource()
testServices.assertions.assertEquals(firPreprocessedTextData, originalPreprocessedTextData) {
"Original and FIR test data aren't identical. " +
"Please, add changes from ${testData.name} to ${firTestData.name}"
"Please, add changes from ${originalTestData.name} to ${firTestData.name}"
}
}
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.test.bind
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
import org.jetbrains.kotlin.test.directives.AdditionalFilesDirectives.SPEC_HELPERS
import org.jetbrains.kotlin.test.directives.ConfigurationDirectives.WITH_STDLIB
import org.jetbrains.kotlin.test.frontend.classic.handlers.FirTestDataConsistencyHandler
import org.jetbrains.kotlin.test.frontend.fir.FirFailingTestSuppressor
import org.jetbrains.kotlin.test.frontend.fir.handlers.FirIdenticalChecker
import org.jetbrains.kotlin.test.services.fir.FirOldFrontendMetaConfigurator
@@ -36,6 +37,7 @@ fun TestConfigurationBuilder.baseFirSpecDiagnosticTestConfiguration(baseDir: Str
useAfterAnalysisCheckers(
::FirIdenticalChecker,
::FirTestDataConsistencyHandler,
::FirFailingTestSuppressor,
)