From 7c19f3b1ca21d3a6bcdfc8667c46777efb09554e Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Tue, 24 May 2022 11:03:45 +0300 Subject: [PATCH] [Lombok] Migrate tests to new test infrastructure --- .../impl/ModuleStructureExtractorImpl.kt | 2 +- .../kotlin/generators/tests/GenerateTests.kt | 18 +- plugins/lombok/build.gradle.kts | 25 +- .../compile/processErrors/annotationTypes.kt | 3 +- ...lackBoxCodegenTestForLombokGenerated.java} | 59 +++-- ...BlackBoxCodegenTestForLombokGenerated.java | 217 ++++++++++++++++++ .../lombok/AbstractLombokCompileTest.kt | 67 ------ .../jetbrains/kotlin/lombok/LombokBoxTests.kt | 73 ++++++ 8 files changed, 367 insertions(+), 97 deletions(-) rename plugins/lombok/tests-gen/org/jetbrains/kotlin/lombok/{LombokCompileTestGenerated.java => BlackBoxCodegenTestForLombokGenerated.java} (87%) create mode 100644 plugins/lombok/tests-gen/org/jetbrains/kotlin/lombok/IrBlackBoxCodegenTestForLombokGenerated.java delete mode 100644 plugins/lombok/tests/org/jetbrains/kotlin/lombok/AbstractLombokCompileTest.kt create mode 100644 plugins/lombok/tests/org/jetbrains/kotlin/lombok/LombokBoxTests.kt diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/impl/ModuleStructureExtractorImpl.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/impl/ModuleStructureExtractorImpl.kt index f39f8178514..95b3d0ebfbd 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/impl/ModuleStructureExtractorImpl.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/impl/ModuleStructureExtractorImpl.kt @@ -45,7 +45,7 @@ class ModuleStructureExtractorImpl( private val environmentConfigurators: List ) : ModuleStructureExtractor(testServices, additionalSourceProviders, moduleStructureTransformers) { companion object { - private val allowedExtensionsForFiles = listOf(".kt", ".kts", ".java", ".js", ".mjs") + private val allowedExtensionsForFiles = listOf(".kt", ".kts", ".java", ".js", ".mjs", ".config") /* * ([^()\n]+) module name diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index d3efe9ea171..152dcd6cc42 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -29,7 +29,8 @@ import org.jetbrains.kotlin.kapt3.test.AbstractClassFileToSourceStubConverterTes import org.jetbrains.kotlin.kapt3.test.AbstractIrClassFileToSourceStubConverterTest import org.jetbrains.kotlin.kapt3.test.AbstractIrKotlinKaptContextTest import org.jetbrains.kotlin.kapt3.test.AbstractKotlinKaptContextTest -import org.jetbrains.kotlin.lombok.AbstractLombokCompileTest +import org.jetbrains.kotlin.lombok.AbstractBlackBoxCodegenTestForLombok +import org.jetbrains.kotlin.lombok.AbstractIrBlackBoxCodegenTestForLombok import org.jetbrains.kotlin.noarg.* import org.jetbrains.kotlin.parcelize.test.runners.* import org.jetbrains.kotlin.samWithReceiver.AbstractSamWithReceiverScriptTest @@ -247,12 +248,6 @@ fun main(args: Array) { model("codegen") } } - - testGroup("plugins/lombok/tests-gen", "plugins/lombok/testData") { - testClass { - model("compile") - } - } /* testGroup("plugins/android-extensions/android-extensions-idea/tests", "plugins/android-extensions/android-extensions-idea/testData") { testClass { @@ -426,5 +421,14 @@ fun main(args: Array) { model("box") } } + + testGroup("plugins/lombok/tests-gen", "plugins/lombok/testData") { + testClass { + model("compile") + } + testClass { + model("compile") + } + } } } diff --git a/plugins/lombok/build.gradle.kts b/plugins/lombok/build.gradle.kts index 71adf816cf5..fb617e346e1 100644 --- a/plugins/lombok/build.gradle.kts +++ b/plugins/lombok/build.gradle.kts @@ -15,11 +15,30 @@ dependencies { testImplementation(project(":kotlin-lombok-compiler-plugin.k1")) testImplementation(project(":kotlin-lombok-compiler-plugin.cli")) - testImplementation(commonDependency("junit:junit")) - testImplementation(projectTests(":compiler:tests-common")) - testImplementation("org.projectlombok:lombok:1.18.16") + testApi(project(":compiler:util")) + testApi(project(":compiler:backend")) + testApi(project(":compiler:ir.backend.common")) + testApi(project(":compiler:backend.jvm")) + testApi(project(":compiler:cli")) + + testApi(projectTests(":compiler:tests-common-new")) + testApi(projectTests(":compiler:test-infrastructure")) + testApi(projectTests(":compiler:test-infrastructure-utils")) + + // FIR dependencies + testApi(project(":compiler:fir:checkers")) + testApi(project(":compiler:fir:checkers:checkers.jvm")) + testRuntimeOnly(project(":compiler:fir:fir-serialization")) + + testCompileOnly(project(":kotlin-reflect-api")) + testRuntimeOnly(project(":kotlin-reflect")) + testRuntimeOnly(project(":core:descriptors.runtime")) + + testApi(commonDependency("junit:junit")) + + testRuntimeOnly(toolsJar()) } diff --git a/plugins/lombok/testData/compile/processErrors/annotationTypes.kt b/plugins/lombok/testData/compile/processErrors/annotationTypes.kt index c38d4af7fdf..f420cb986d4 100644 --- a/plugins/lombok/testData/compile/processErrors/annotationTypes.kt +++ b/plugins/lombok/testData/compile/processErrors/annotationTypes.kt @@ -1,3 +1,4 @@ +// IGNORE_ERRORS // FILE: Anno.java import java.lang.*; @@ -22,7 +23,7 @@ public class Foo { // FILE: test.kt -@Anno +@Anno fun box(): String { val obj = Foo() return "OK" diff --git a/plugins/lombok/tests-gen/org/jetbrains/kotlin/lombok/LombokCompileTestGenerated.java b/plugins/lombok/tests-gen/org/jetbrains/kotlin/lombok/BlackBoxCodegenTestForLombokGenerated.java similarity index 87% rename from plugins/lombok/tests-gen/org/jetbrains/kotlin/lombok/LombokCompileTestGenerated.java rename to plugins/lombok/tests-gen/org/jetbrains/kotlin/lombok/BlackBoxCodegenTestForLombokGenerated.java index 2c70f041e6a..dca1a941d03 100644 --- a/plugins/lombok/tests-gen/org/jetbrains/kotlin/lombok/LombokCompileTestGenerated.java +++ b/plugins/lombok/tests-gen/org/jetbrains/kotlin/lombok/BlackBoxCodegenTestForLombokGenerated.java @@ -6,186 +6,209 @@ package org.jetbrains.kotlin.lombok; import com.intellij.testFramework.TestDataPath; -import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; -import org.jetbrains.kotlin.test.KotlinTestUtils; import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.jetbrains.kotlin.test.TargetBackend; import org.jetbrains.kotlin.test.TestMetadata; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.regex.Pattern; -/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +/** This class is generated by {@link GenerateNewCompilerTests.kt}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") @TestMetadata("plugins/lombok/testData/compile") @TestDataPath("$PROJECT_ROOT") -@RunWith(JUnit3RunnerWithInners.class) -public class LombokCompileTestGenerated extends AbstractLombokCompileTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); - } - +public class BlackBoxCodegenTestForLombokGenerated extends AbstractBlackBoxCodegenTestForLombok { + @Test @TestMetadata("accessorsStripPrefix.kt") public void testAccessorsStripPrefix() throws Exception { runTest("plugins/lombok/testData/compile/accessorsStripPrefix.kt"); } + @Test @TestMetadata("accessorsStripPrefixCombined.kt") public void testAccessorsStripPrefixCombined() throws Exception { runTest("plugins/lombok/testData/compile/accessorsStripPrefixCombined.kt"); } + @Test @TestMetadata("accessorsStripPrefixConfig.kt") public void testAccessorsStripPrefixConfig() throws Exception { runTest("plugins/lombok/testData/compile/accessorsStripPrefixConfig.kt"); } + @Test @TestMetadata("allArgsConstructor.kt") public void testAllArgsConstructor() throws Exception { runTest("plugins/lombok/testData/compile/allArgsConstructor.kt"); } + @Test @TestMetadata("allArgsConstructorStatic.kt") public void testAllArgsConstructorStatic() throws Exception { runTest("plugins/lombok/testData/compile/allArgsConstructorStatic.kt"); } + @Test public void testAllFilesPresentInCompile() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/lombok/testData/compile"), Pattern.compile("^(.+)\\.kt$"), null, true); + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/lombok/testData/compile"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @Test @TestMetadata("clashAccessors.kt") public void testClashAccessors() throws Exception { runTest("plugins/lombok/testData/compile/clashAccessors.kt"); } + @Test @TestMetadata("configAccessors.kt") public void testConfigAccessors() throws Exception { runTest("plugins/lombok/testData/compile/configAccessors.kt"); } + @Test @TestMetadata("configAccessorsOverride.kt") public void testConfigAccessorsOverride() throws Exception { runTest("plugins/lombok/testData/compile/configAccessorsOverride.kt"); } + @Test @TestMetadata("configCaseInsensitive.kt") public void testConfigCaseInsensitive() throws Exception { runTest("plugins/lombok/testData/compile/configCaseInsensitive.kt"); } + @Test @TestMetadata("configSimple.kt") public void testConfigSimple() throws Exception { runTest("plugins/lombok/testData/compile/configSimple.kt"); } + @Test @TestMetadata("data.kt") public void testData() throws Exception { runTest("plugins/lombok/testData/compile/data.kt"); } + @Test @TestMetadata("genericsAccessors.kt") public void testGenericsAccessors() throws Exception { runTest("plugins/lombok/testData/compile/genericsAccessors.kt"); } + @Test @TestMetadata("genericsConstructors.kt") public void testGenericsConstructors() throws Exception { runTest("plugins/lombok/testData/compile/genericsConstructors.kt"); } + @Test @TestMetadata("genericsConstructorsStatic.kt") public void testGenericsConstructorsStatic() throws Exception { runTest("plugins/lombok/testData/compile/genericsConstructorsStatic.kt"); } + @Test @TestMetadata("getters.kt") public void testGetters() throws Exception { runTest("plugins/lombok/testData/compile/getters.kt"); } + @Test @TestMetadata("gettersClassLevel.kt") public void testGettersClassLevel() throws Exception { runTest("plugins/lombok/testData/compile/gettersClassLevel.kt"); } + @Test @TestMetadata("gettersFluent.kt") public void testGettersFluent() throws Exception { runTest("plugins/lombok/testData/compile/gettersFluent.kt"); } + @Test @TestMetadata("noArgsConstructor.kt") public void testNoArgsConstructor() throws Exception { runTest("plugins/lombok/testData/compile/noArgsConstructor.kt"); } + @Test @TestMetadata("noArgsConstructorStatic.kt") public void testNoArgsConstructorStatic() throws Exception { runTest("plugins/lombok/testData/compile/noArgsConstructorStatic.kt"); } + @Test @TestMetadata("nullability.kt") public void testNullability() throws Exception { runTest("plugins/lombok/testData/compile/nullability.kt"); } + @Test @TestMetadata("propertyFromSuper.kt") public void testPropertyFromSuper() throws Exception { runTest("plugins/lombok/testData/compile/propertyFromSuper.kt"); } + @Test @TestMetadata("requiredArgsConstructor.kt") public void testRequiredArgsConstructor() throws Exception { runTest("plugins/lombok/testData/compile/requiredArgsConstructor.kt"); } + @Test @TestMetadata("requiredArgsConstructorStatic.kt") public void testRequiredArgsConstructorStatic() throws Exception { runTest("plugins/lombok/testData/compile/requiredArgsConstructorStatic.kt"); } + @Test @TestMetadata("setters.kt") public void testSetters() throws Exception { runTest("plugins/lombok/testData/compile/setters.kt"); } + @Test @TestMetadata("settersClassLevel.kt") public void testSettersClassLevel() throws Exception { runTest("plugins/lombok/testData/compile/settersClassLevel.kt"); } + @Test @TestMetadata("settersVariations.kt") public void testSettersVariations() throws Exception { runTest("plugins/lombok/testData/compile/settersVariations.kt"); } + @Test @TestMetadata("simple.kt") public void testSimple() throws Exception { runTest("plugins/lombok/testData/compile/simple.kt"); } + @Test @TestMetadata("value.kt") public void testValue() throws Exception { runTest("plugins/lombok/testData/compile/value.kt"); } + @Test @TestMetadata("with.kt") public void testWith() throws Exception { runTest("plugins/lombok/testData/compile/with.kt"); } + @Nested @TestMetadata("plugins/lombok/testData/compile/processErrors") @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class ProcessErrors extends AbstractLombokCompileTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); - } - + public class ProcessErrors { + @Test public void testAllFilesPresentInProcessErrors() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/lombok/testData/compile/processErrors"), Pattern.compile("^(.+)\\.kt$"), null, true); + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/lombok/testData/compile/processErrors"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @Test @TestMetadata("annotationTypes.kt") public void testAnnotationTypes() throws Exception { runTest("plugins/lombok/testData/compile/processErrors/annotationTypes.kt"); diff --git a/plugins/lombok/tests-gen/org/jetbrains/kotlin/lombok/IrBlackBoxCodegenTestForLombokGenerated.java b/plugins/lombok/tests-gen/org/jetbrains/kotlin/lombok/IrBlackBoxCodegenTestForLombokGenerated.java new file mode 100644 index 00000000000..1b5abe759d6 --- /dev/null +++ b/plugins/lombok/tests-gen/org/jetbrains/kotlin/lombok/IrBlackBoxCodegenTestForLombokGenerated.java @@ -0,0 +1,217 @@ +/* + * Copyright 2010-2021 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.lombok; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.jetbrains.kotlin.test.TargetBackend; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link GenerateNewCompilerTests.kt}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("plugins/lombok/testData/compile") +@TestDataPath("$PROJECT_ROOT") +public class IrBlackBoxCodegenTestForLombokGenerated extends AbstractIrBlackBoxCodegenTestForLombok { + @Test + @TestMetadata("accessorsStripPrefix.kt") + public void testAccessorsStripPrefix() throws Exception { + runTest("plugins/lombok/testData/compile/accessorsStripPrefix.kt"); + } + + @Test + @TestMetadata("accessorsStripPrefixCombined.kt") + public void testAccessorsStripPrefixCombined() throws Exception { + runTest("plugins/lombok/testData/compile/accessorsStripPrefixCombined.kt"); + } + + @Test + @TestMetadata("accessorsStripPrefixConfig.kt") + public void testAccessorsStripPrefixConfig() throws Exception { + runTest("plugins/lombok/testData/compile/accessorsStripPrefixConfig.kt"); + } + + @Test + @TestMetadata("allArgsConstructor.kt") + public void testAllArgsConstructor() throws Exception { + runTest("plugins/lombok/testData/compile/allArgsConstructor.kt"); + } + + @Test + @TestMetadata("allArgsConstructorStatic.kt") + public void testAllArgsConstructorStatic() throws Exception { + runTest("plugins/lombok/testData/compile/allArgsConstructorStatic.kt"); + } + + @Test + public void testAllFilesPresentInCompile() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/lombok/testData/compile"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Test + @TestMetadata("clashAccessors.kt") + public void testClashAccessors() throws Exception { + runTest("plugins/lombok/testData/compile/clashAccessors.kt"); + } + + @Test + @TestMetadata("configAccessors.kt") + public void testConfigAccessors() throws Exception { + runTest("plugins/lombok/testData/compile/configAccessors.kt"); + } + + @Test + @TestMetadata("configAccessorsOverride.kt") + public void testConfigAccessorsOverride() throws Exception { + runTest("plugins/lombok/testData/compile/configAccessorsOverride.kt"); + } + + @Test + @TestMetadata("configCaseInsensitive.kt") + public void testConfigCaseInsensitive() throws Exception { + runTest("plugins/lombok/testData/compile/configCaseInsensitive.kt"); + } + + @Test + @TestMetadata("configSimple.kt") + public void testConfigSimple() throws Exception { + runTest("plugins/lombok/testData/compile/configSimple.kt"); + } + + @Test + @TestMetadata("data.kt") + public void testData() throws Exception { + runTest("plugins/lombok/testData/compile/data.kt"); + } + + @Test + @TestMetadata("genericsAccessors.kt") + public void testGenericsAccessors() throws Exception { + runTest("plugins/lombok/testData/compile/genericsAccessors.kt"); + } + + @Test + @TestMetadata("genericsConstructors.kt") + public void testGenericsConstructors() throws Exception { + runTest("plugins/lombok/testData/compile/genericsConstructors.kt"); + } + + @Test + @TestMetadata("genericsConstructorsStatic.kt") + public void testGenericsConstructorsStatic() throws Exception { + runTest("plugins/lombok/testData/compile/genericsConstructorsStatic.kt"); + } + + @Test + @TestMetadata("getters.kt") + public void testGetters() throws Exception { + runTest("plugins/lombok/testData/compile/getters.kt"); + } + + @Test + @TestMetadata("gettersClassLevel.kt") + public void testGettersClassLevel() throws Exception { + runTest("plugins/lombok/testData/compile/gettersClassLevel.kt"); + } + + @Test + @TestMetadata("gettersFluent.kt") + public void testGettersFluent() throws Exception { + runTest("plugins/lombok/testData/compile/gettersFluent.kt"); + } + + @Test + @TestMetadata("noArgsConstructor.kt") + public void testNoArgsConstructor() throws Exception { + runTest("plugins/lombok/testData/compile/noArgsConstructor.kt"); + } + + @Test + @TestMetadata("noArgsConstructorStatic.kt") + public void testNoArgsConstructorStatic() throws Exception { + runTest("plugins/lombok/testData/compile/noArgsConstructorStatic.kt"); + } + + @Test + @TestMetadata("nullability.kt") + public void testNullability() throws Exception { + runTest("plugins/lombok/testData/compile/nullability.kt"); + } + + @Test + @TestMetadata("propertyFromSuper.kt") + public void testPropertyFromSuper() throws Exception { + runTest("plugins/lombok/testData/compile/propertyFromSuper.kt"); + } + + @Test + @TestMetadata("requiredArgsConstructor.kt") + public void testRequiredArgsConstructor() throws Exception { + runTest("plugins/lombok/testData/compile/requiredArgsConstructor.kt"); + } + + @Test + @TestMetadata("requiredArgsConstructorStatic.kt") + public void testRequiredArgsConstructorStatic() throws Exception { + runTest("plugins/lombok/testData/compile/requiredArgsConstructorStatic.kt"); + } + + @Test + @TestMetadata("setters.kt") + public void testSetters() throws Exception { + runTest("plugins/lombok/testData/compile/setters.kt"); + } + + @Test + @TestMetadata("settersClassLevel.kt") + public void testSettersClassLevel() throws Exception { + runTest("plugins/lombok/testData/compile/settersClassLevel.kt"); + } + + @Test + @TestMetadata("settersVariations.kt") + public void testSettersVariations() throws Exception { + runTest("plugins/lombok/testData/compile/settersVariations.kt"); + } + + @Test + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("plugins/lombok/testData/compile/simple.kt"); + } + + @Test + @TestMetadata("value.kt") + public void testValue() throws Exception { + runTest("plugins/lombok/testData/compile/value.kt"); + } + + @Test + @TestMetadata("with.kt") + public void testWith() throws Exception { + runTest("plugins/lombok/testData/compile/with.kt"); + } + + @Nested + @TestMetadata("plugins/lombok/testData/compile/processErrors") + @TestDataPath("$PROJECT_ROOT") + public class ProcessErrors { + @Test + public void testAllFilesPresentInProcessErrors() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/lombok/testData/compile/processErrors"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Test + @TestMetadata("annotationTypes.kt") + public void testAnnotationTypes() throws Exception { + runTest("plugins/lombok/testData/compile/processErrors/annotationTypes.kt"); + } + } +} diff --git a/plugins/lombok/tests/org/jetbrains/kotlin/lombok/AbstractLombokCompileTest.kt b/plugins/lombok/tests/org/jetbrains/kotlin/lombok/AbstractLombokCompileTest.kt deleted file mode 100644 index d24a14a148b..00000000000 --- a/plugins/lombok/tests/org/jetbrains/kotlin/lombok/AbstractLombokCompileTest.kt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2010-2021 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.lombok - -import lombok.Getter -import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment -import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot -import org.jetbrains.kotlin.cli.jvm.config.javaSourceRoots -import org.jetbrains.kotlin.codegen.CodegenTestCase -import org.jetbrains.kotlin.config.CompilerConfiguration -import org.jetbrains.kotlin.utils.PathUtil -import java.io.File -import java.net.URLClassLoader - -abstract class AbstractLombokCompileTest : CodegenTestCase() { - - private val commonClassLoader = URLClassLoader(arrayOf(getLombokJar().toURI().toURL())) - private val commonSourceFile = TestFile( - "common.kt", - File("plugins/lombok/testData/common.kt").readText() - ) - - override fun doMultiFileTest(wholeFile: File, files: List) { - compile(files + commonSourceFile, true, true) - } - - override fun setupEnvironment(environment: KotlinCoreEnvironment) { - LombokComponentRegistrar.registerComponents(environment.project, environment.configuration) - environment.updateClasspath(listOf(JvmClasspathRoot(getLombokJar()))) - } - - override fun updateJavaClasspath(javaClasspath: MutableList) { - javaClasspath += getLombokJar().absolutePath - } - - override fun configureTestSpecific(configuration: CompilerConfiguration, testFiles: List) { - writeLombokConfig(configuration.javaSourceRoots.first(), testFiles)?.let { file -> - configuration.put(LombokConfigurationKeys.CONFIG_FILE, file) - } - } - - override fun postCompile(kotlinOut: File, javaOut: File?) { - //run compiled code, Test.run() method is expected to be in generated classes - val cp = listOfNotNull(kotlinOut, javaOut).map { it.toURI().toURL() }.toTypedArray() - val classLoader = URLClassLoader(cp, commonClassLoader) - try { - val clazz = classLoader.loadClass("Test") - clazz.getMethod("run").invoke(clazz.newInstance()) - } catch (t: Throwable) { - LOG.error("Error running Test.run()", t) - fail("Error running compiled code: $t") - } - } - - private fun writeLombokConfig(directory: String, testFiles: List): File? = - testFiles.singleOrNull { it.name == "lombok.config" }?.let { - val file = File(directory, it.name) - file.writeText(it.content) - file - } - - - private fun getLombokJar(): File = PathUtil.getResourcePathForClass(Getter::class.java) -} diff --git a/plugins/lombok/tests/org/jetbrains/kotlin/lombok/LombokBoxTests.kt b/plugins/lombok/tests/org/jetbrains/kotlin/lombok/LombokBoxTests.kt new file mode 100644 index 00000000000..d5ec1c3556c --- /dev/null +++ b/plugins/lombok/tests/org/jetbrains/kotlin/lombok/LombokBoxTests.kt @@ -0,0 +1,73 @@ +/* + * Copyright 2010-2022 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.lombok + +import com.intellij.openapi.project.Project +import lombok.Getter +import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoot +import org.jetbrains.kotlin.config.CompilerConfiguration +import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder +import org.jetbrains.kotlin.test.directives.model.RegisteredDirectives +import org.jetbrains.kotlin.test.model.TestFile +import org.jetbrains.kotlin.test.model.TestModule +import org.jetbrains.kotlin.test.runners.codegen.AbstractBlackBoxCodegenTest +import org.jetbrains.kotlin.test.runners.codegen.AbstractIrBlackBoxCodegenTest +import org.jetbrains.kotlin.test.services.* +import org.jetbrains.kotlin.utils.PathUtil +import java.io.File + +open class AbstractBlackBoxCodegenTestForLombok : AbstractBlackBoxCodegenTest() { + override fun configure(builder: TestConfigurationBuilder) { + super.configure(builder) + builder.enableLombok() + } +} + +open class AbstractIrBlackBoxCodegenTestForLombok : AbstractIrBlackBoxCodegenTest() { + override fun configure(builder: TestConfigurationBuilder) { + super.configure(builder) + builder.enableLombok() + } +} + +fun TestConfigurationBuilder.enableLombok() { + useConfigurators(::LombokEnvironmentConfigurator) + useAdditionalSourceProviders(::LombokAdditionalSourceFileProvider) +} + +class LombokAdditionalSourceFileProvider(testServices: TestServices) : AdditionalSourceProvider(testServices) { + companion object { + const val COMMON_SOURCE_PATH = "plugins/lombok/testData/common.kt" + } + + override fun produceAdditionalFiles(globalDirectives: RegisteredDirectives, module: TestModule): List { + return listOf(File(COMMON_SOURCE_PATH).toTestFile()) + } +} + +class LombokEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigurator(testServices) { + companion object { + const val LOMBOK_CONFIG_NAME = "lombok.config" + } + + override fun configureCompilerConfiguration(configuration: CompilerConfiguration, module: TestModule) { + configuration.addJvmClasspathRoot(PathUtil.getResourcePathForClass(Getter::class.java)) + + val lombokConfig = findLombokConfig(module) ?: return + lombokConfig.copyTo(testServices.sourceFileProvider.javaSourceDirectory.resolve(lombokConfig.name)) + configuration.put(LombokConfigurationKeys.CONFIG_FILE, lombokConfig) + } + + private fun findLombokConfig(module: TestModule): File? { + return module.files.singleOrNull { it.name == LOMBOK_CONFIG_NAME }?.let { + testServices.sourceFileProvider.getRealFileForSourceFile(it) + } + } + + override fun registerCompilerExtensions(project: Project, module: TestModule, configuration: CompilerConfiguration) { + LombokComponentRegistrar.registerComponents(project, configuration) + } +}