[Tests] Introduce reversible source file preprocessor

This commit is contained in:
Evgeniy.Zhelenskiy
2021-12-08 22:52:03 +03:00
parent cb4ec932d7
commit b1d1f87318
12 changed files with 28 additions and 35 deletions
@@ -19292,13 +19292,13 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
@Test
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
public void testBoxResultInlineClassOfConstructorCall() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::replaceOptionalJvmInlineAnnotationWithReal);
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal());
}
@Test
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
public void testBoxResultInlineClassOfConstructorCall_valueClasses() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::removeOptionalJvmInlineAnnotation);
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@Test
@@ -24,13 +24,9 @@ class TestRunner(private val testConfiguration: TestConfiguration) {
private val allFailedExceptions = mutableListOf<WrappedException>()
private val allRanHandlers = mutableSetOf<AnalysisHandler<*>>()
fun runTest(
@TestDataFile testDataFileName: String,
expectedFileTransformer: ((String) -> String)? = null,
beforeDispose: (TestConfiguration) -> Unit = {},
) {
fun runTest(@TestDataFile testDataFileName: String, beforeDispose: (TestConfiguration) -> Unit = {}) {
try {
runTestImpl(testDataFileName, expectedFileTransformer)
runTestImpl(testDataFileName)
} finally {
try {
testConfiguration.testServices.temporaryDirectoryManager.cleanupTemporaryDirectories()
@@ -42,7 +38,7 @@ class TestRunner(private val testConfiguration: TestConfiguration) {
}
}
private fun runTestImpl(@TestDataFile testDataFileName: String, expectedFileTransformer: ((String) -> String)?) {
private fun runTestImpl(@TestDataFile testDataFileName: String) {
val services = testConfiguration.testServices
@Suppress("NAME_SHADOWING")
@@ -70,14 +66,10 @@ class TestRunner(private val testConfiguration: TestConfiguration) {
if (it.shouldSkipTest()) return
}
runTestPipeline(moduleStructure, services, expectedFileTransformer)
runTestPipeline(moduleStructure, services)
}
fun runTestPipeline(
moduleStructure: TestModuleStructure,
services: TestServices,
expectedFileTransformer: ((String) -> String)?,
) {
fun runTestPipeline(moduleStructure: TestModuleStructure, services: TestServices) {
val globalMetadataInfoHandler = testConfiguration.testServices.globalMetadataInfoHandler
globalMetadataInfoHandler.parseExistingMetadataInfosFromAllSources()
@@ -105,7 +97,7 @@ class TestRunner(private val testConfiguration: TestConfiguration) {
}
if (testConfiguration.metaInfoHandlerEnabled) {
withAssertionCatching(WrappedException::FromMetaInfoHandler) {
globalMetadataInfoHandler.compareAllMetaDataInfos(expectedFileTransformer)
globalMetadataInfoHandler.compareAllMetaDataInfos()
}
}
@@ -15,6 +15,10 @@ abstract class SourceFilePreprocessor(val testServices: TestServices) {
abstract fun process(file: TestFile, content: String): String
}
abstract class ReversibleSourceFilePreprocessor(testServices: TestServices) : SourceFilePreprocessor(testServices) {
abstract fun revert(file: TestFile, actualContent: String): String
}
abstract class SourceFileProvider : TestService {
abstract val kotlinSourceDirectory: File
abstract val javaSourceDirectory: File
@@ -23,11 +27,12 @@ abstract class SourceFileProvider : TestService {
abstract fun getContentOfSourceFile(testFile: TestFile): String
abstract fun getRealFileForSourceFile(testFile: TestFile): File
abstract fun getRealFileForBinaryFile(testFile: TestFile): File
abstract val preprocessors: List<SourceFilePreprocessor>
}
val TestServices.sourceFileProvider: SourceFileProvider by TestServices.testServiceAccessor()
class SourceFileProviderImpl(val testServices: TestServices, val preprocessors: List<SourceFilePreprocessor>) : SourceFileProvider() {
class SourceFileProviderImpl(val testServices: TestServices, override val preprocessors: List<SourceFilePreprocessor>) : SourceFileProvider() {
override val kotlinSourceDirectory: File = testServices.getOrCreateTempDirectory("kotlin-files")
override val javaSourceDirectory: File = testServices.getOrCreateTempDirectory("java-files")
override val javaBinaryDirectory: File = testServices.getOrCreateTempDirectory("java-binary-files")
@@ -18908,7 +18908,7 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
@Test
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
public void testBoxResultInlineClassOfConstructorCall() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::replaceOptionalJvmInlineAnnotationWithReal);
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal());
}
@Test
@@ -19292,13 +19292,13 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
@Test
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
public void testBoxResultInlineClassOfConstructorCall() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::replaceOptionalJvmInlineAnnotationWithReal);
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal());
}
@Test
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
public void testBoxResultInlineClassOfConstructorCall_valueClasses() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::removeOptionalJvmInlineAnnotation);
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@Test
@@ -9,18 +9,14 @@ import java.io.File
object TransformersFunctions {
@JvmStatic
fun replaceOptionalJvmInlineAnnotationWithReal(source: String): String {
return source.replace("OPTIONAL_JVM_INLINE_ANNOTATION", "@JvmInline")
}
val replaceOptionalJvmInlineAnnotationWithReal = ReplacingSourceTransformer("OPTIONAL_JVM_INLINE_ANNOTATION", "@JvmInline")
@JvmStatic
fun removeOptionalJvmInlineAnnotation(source: String): String {
return source.replace("OPTIONAL_JVM_INLINE_ANNOTATION", "")
}
val removeOptionalJvmInlineAnnotation = ReplacingSourceTransformer("OPTIONAL_JVM_INLINE_ANNOTATION", "")
object Android {
val forAll: List<(String) -> String> = listOf(
TransformersFunctions::replaceOptionalJvmInlineAnnotationWithReal,
replaceOptionalJvmInlineAnnotationWithReal,
)
val forSpecificFile: Map<File, (String) -> String> = mapOf(
)
@@ -15781,7 +15781,7 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
public void testBoxResultInlineClassOfConstructorCall() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::replaceOptionalJvmInlineAnnotationWithReal);
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal());
}
@TestMetadata("boxUnboxInlineClassesWithOperatorsGetSet.kt")
@@ -11,8 +11,8 @@ class WithoutJvmInlineTestMethodModel(
withPostfix: Boolean,
) : TransformingTestMethodModel(
source,
transformer = "TransformersFunctions::" +
if (withAnnotation) "replaceOptionalJvmInlineAnnotationWithReal" else "removeOptionalJvmInlineAnnotation"
transformer = "TransformersFunctions.get" +
if (withAnnotation) "ReplaceOptionalJvmInlineAnnotationWithReal()" else "RemoveOptionalJvmInlineAnnotation()"
) {
override val name: String = source.name + if (withPostfix) "_valueClasses" else ""
}
@@ -14842,7 +14842,7 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
@Test
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
public void testBoxResultInlineClassOfConstructorCall() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::removeOptionalJvmInlineAnnotation);
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@Test
@@ -14806,7 +14806,7 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
@Test
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
public void testBoxResultInlineClassOfConstructorCall() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::removeOptionalJvmInlineAnnotation);
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@Test
@@ -12473,7 +12473,7 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
public void testBoxResultInlineClassOfConstructorCall() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::removeOptionalJvmInlineAnnotation);
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@TestMetadata("boxUnboxInlineClassesWithOperatorsGetSet.kt")
@@ -15646,7 +15646,7 @@ public class NativeExtBlackBoxTestGenerated extends AbstractNativeBlackBoxTest {
@NativeBlackBoxTestCaseGroupProvider(ExtTestCaseGroupProvider.class)
public class InlineClasses {
public InlineClasses() {
register("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::removeOptionalJvmInlineAnnotation);
register("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@Test
@@ -15705,7 +15705,7 @@ public class NativeExtBlackBoxTestGenerated extends AbstractNativeBlackBoxTest {
@Test
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
public void testBoxResultInlineClassOfConstructorCall() throws Exception {
// There is a registered source transformer for the testcase: TransformersFunctions::removeOptionalJvmInlineAnnotation
// There is a registered source transformer for the testcase: TransformersFunctions.getRemoveOptionalJvmInlineAnnotation()
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt");
}