[Tests] Add handler to regenerate irText testData
It is disabled by default, can be enabled by code change. It's useful when changes in dumper is done with significant amount of tests changed. ^KT-65460
This commit is contained in:
committed by
Space Team
parent
1f257e98a0
commit
5ddc31e932
+2
-4
@@ -27,10 +27,7 @@ import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.EXTERNAL_FILE
|
||||
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives
|
||||
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives.FIR_IDENTICAL
|
||||
import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
|
||||
import org.jetbrains.kotlin.test.model.BackendKind
|
||||
import org.jetbrains.kotlin.test.model.FrontendKinds
|
||||
import org.jetbrains.kotlin.test.model.TestFile
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.model.*
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
import org.jetbrains.kotlin.test.services.moduleStructure
|
||||
import org.jetbrains.kotlin.test.utils.MultiModuleInfoDumper
|
||||
@@ -154,3 +151,4 @@ class IrTextDumpHandler(
|
||||
return computeDumpExtension(this, DUMP_EXTENSION, ignoreFirIdentical)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2010-2024 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.test.backend.handlers
|
||||
|
||||
import com.intellij.rt.execution.junit.FileComparisonFailure
|
||||
import org.jetbrains.kotlin.test.WrappedException
|
||||
import org.jetbrains.kotlin.test.model.AfterAnalysisChecker
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
import java.io.File
|
||||
import kotlin.collections.mapNotNull
|
||||
import kotlin.io.writeText
|
||||
import kotlin.text.endsWith
|
||||
|
||||
/**
|
||||
* Does nothing normally.
|
||||
*
|
||||
* If change [enabled] to true or set system property `kotlin.test.update.test.data` to true,
|
||||
* then all text dump related files would be rewritten on test failures.
|
||||
*
|
||||
* This is useful to update test data after change of dump format.
|
||||
*
|
||||
* No rewrite happens on muted tests.
|
||||
*
|
||||
* For example, if you want to update IR text test data by K2 with the JVM backend, you need to run:
|
||||
*
|
||||
* ./gradlew :compiler:fir:fir2ir:test --tests "org.jetbrains.kotlin.test.runners.ir.FirPsiJvmIrTextTestGenerated" --continue -Pkotlin.test.update.test.data=true
|
||||
*
|
||||
*/
|
||||
class UpdateTestDataHandler(
|
||||
testServices: TestServices
|
||||
) : AfterAnalysisChecker(testServices) {
|
||||
private val enabled = false
|
||||
|
||||
override fun suppressIfNeeded(failedAssertions: List<WrappedException>): List<WrappedException> {
|
||||
if (enabled || System.getProperty("kotlin.test.update.test.data") == "true") {
|
||||
for (failure in failedAssertions.mapNotNull { it.cause as? FileComparisonFailure }) {
|
||||
File(failure.filePath).writeText(failure.actual)
|
||||
}
|
||||
}
|
||||
return failedAssertions
|
||||
}
|
||||
}
|
||||
+3
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.test.runners
|
||||
import com.intellij.testFramework.TestDataFile
|
||||
import org.jetbrains.kotlin.test.Constructor
|
||||
import org.jetbrains.kotlin.test.ExecutionListenerBasedDisposableProvider
|
||||
import org.jetbrains.kotlin.test.backend.handlers.UpdateTestDataHandler
|
||||
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
|
||||
import org.jetbrains.kotlin.test.builders.testRunner
|
||||
import org.jetbrains.kotlin.test.directives.ConfigurationDirectives
|
||||
@@ -55,6 +56,8 @@ abstract class AbstractKotlinCompilerTest {
|
||||
useAdditionalService { createApplicationDisposableProvider() }
|
||||
useAdditionalService { createKotlinStandardLibrariesPathProvider() }
|
||||
configure(this)
|
||||
// UpdateTestDataHandler should be the last handler, so it's added after the configure call.
|
||||
useAfterAnalysisCheckers(::UpdateTestDataHandler)
|
||||
}
|
||||
|
||||
abstract fun TestConfigurationBuilder.configuration()
|
||||
|
||||
Reference in New Issue
Block a user