[Lombok] Migrate tests to new test infrastructure

This commit is contained in:
Dmitriy Novozhilov
2022-05-24 11:03:45 +03:00
committed by teamcity
parent c9c24d27d7
commit 7c19f3b1ca
8 changed files with 367 additions and 97 deletions
@@ -45,7 +45,7 @@ class ModuleStructureExtractorImpl(
private val environmentConfigurators: List<AbstractEnvironmentConfigurator> private val environmentConfigurators: List<AbstractEnvironmentConfigurator>
) : ModuleStructureExtractor(testServices, additionalSourceProviders, moduleStructureTransformers) { ) : ModuleStructureExtractor(testServices, additionalSourceProviders, moduleStructureTransformers) {
companion object { companion object {
private val allowedExtensionsForFiles = listOf(".kt", ".kts", ".java", ".js", ".mjs") private val allowedExtensionsForFiles = listOf(".kt", ".kts", ".java", ".js", ".mjs", ".config")
/* /*
* ([^()\n]+) module name * ([^()\n]+) module name
@@ -29,7 +29,8 @@ import org.jetbrains.kotlin.kapt3.test.AbstractClassFileToSourceStubConverterTes
import org.jetbrains.kotlin.kapt3.test.AbstractIrClassFileToSourceStubConverterTest import org.jetbrains.kotlin.kapt3.test.AbstractIrClassFileToSourceStubConverterTest
import org.jetbrains.kotlin.kapt3.test.AbstractIrKotlinKaptContextTest import org.jetbrains.kotlin.kapt3.test.AbstractIrKotlinKaptContextTest
import org.jetbrains.kotlin.kapt3.test.AbstractKotlinKaptContextTest 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.noarg.*
import org.jetbrains.kotlin.parcelize.test.runners.* import org.jetbrains.kotlin.parcelize.test.runners.*
import org.jetbrains.kotlin.samWithReceiver.AbstractSamWithReceiverScriptTest import org.jetbrains.kotlin.samWithReceiver.AbstractSamWithReceiverScriptTest
@@ -247,12 +248,6 @@ fun main(args: Array<String>) {
model("codegen") model("codegen")
} }
} }
testGroup("plugins/lombok/tests-gen", "plugins/lombok/testData") {
testClass<AbstractLombokCompileTest> {
model("compile")
}
}
/* /*
testGroup("plugins/android-extensions/android-extensions-idea/tests", "plugins/android-extensions/android-extensions-idea/testData") { testGroup("plugins/android-extensions/android-extensions-idea/tests", "plugins/android-extensions/android-extensions-idea/testData") {
testClass<AbstractAndroidCompletionTest> { testClass<AbstractAndroidCompletionTest> {
@@ -426,5 +421,14 @@ fun main(args: Array<String>) {
model("box") model("box")
} }
} }
testGroup("plugins/lombok/tests-gen", "plugins/lombok/testData") {
testClass<AbstractBlackBoxCodegenTestForLombok> {
model("compile")
}
testClass<AbstractIrBlackBoxCodegenTestForLombok> {
model("compile")
}
}
} }
} }
+22 -3
View File
@@ -15,11 +15,30 @@ dependencies {
testImplementation(project(":kotlin-lombok-compiler-plugin.k1")) testImplementation(project(":kotlin-lombok-compiler-plugin.k1"))
testImplementation(project(":kotlin-lombok-compiler-plugin.cli")) testImplementation(project(":kotlin-lombok-compiler-plugin.cli"))
testImplementation(commonDependency("junit:junit"))
testImplementation(projectTests(":compiler:tests-common"))
testImplementation("org.projectlombok:lombok:1.18.16") 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()) testRuntimeOnly(toolsJar())
} }
@@ -1,3 +1,4 @@
// IGNORE_ERRORS
// FILE: Anno.java // FILE: Anno.java
import java.lang.*; import java.lang.*;
@@ -22,7 +23,7 @@ public class Foo {
// FILE: test.kt // FILE: test.kt
@Anno <!WRONG_ANNOTATION_TARGET!>@Anno<!>
fun box(): String { fun box(): String {
val obj = Foo() val obj = Foo()
return "OK" return "OK"
@@ -6,186 +6,209 @@
package org.jetbrains.kotlin.lombok; package org.jetbrains.kotlin.lombok;
import com.intellij.testFramework.TestDataPath; 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.util.KtTestUtil;
import org.jetbrains.kotlin.test.TargetBackend;
import org.jetbrains.kotlin.test.TestMetadata; 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.io.File;
import java.util.regex.Pattern; 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") @SuppressWarnings("all")
@TestMetadata("plugins/lombok/testData/compile") @TestMetadata("plugins/lombok/testData/compile")
@TestDataPath("$PROJECT_ROOT") @TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class) public class BlackBoxCodegenTestForLombokGenerated extends AbstractBlackBoxCodegenTestForLombok {
public class LombokCompileTestGenerated extends AbstractLombokCompileTest { @Test
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@TestMetadata("accessorsStripPrefix.kt") @TestMetadata("accessorsStripPrefix.kt")
public void testAccessorsStripPrefix() throws Exception { public void testAccessorsStripPrefix() throws Exception {
runTest("plugins/lombok/testData/compile/accessorsStripPrefix.kt"); runTest("plugins/lombok/testData/compile/accessorsStripPrefix.kt");
} }
@Test
@TestMetadata("accessorsStripPrefixCombined.kt") @TestMetadata("accessorsStripPrefixCombined.kt")
public void testAccessorsStripPrefixCombined() throws Exception { public void testAccessorsStripPrefixCombined() throws Exception {
runTest("plugins/lombok/testData/compile/accessorsStripPrefixCombined.kt"); runTest("plugins/lombok/testData/compile/accessorsStripPrefixCombined.kt");
} }
@Test
@TestMetadata("accessorsStripPrefixConfig.kt") @TestMetadata("accessorsStripPrefixConfig.kt")
public void testAccessorsStripPrefixConfig() throws Exception { public void testAccessorsStripPrefixConfig() throws Exception {
runTest("plugins/lombok/testData/compile/accessorsStripPrefixConfig.kt"); runTest("plugins/lombok/testData/compile/accessorsStripPrefixConfig.kt");
} }
@Test
@TestMetadata("allArgsConstructor.kt") @TestMetadata("allArgsConstructor.kt")
public void testAllArgsConstructor() throws Exception { public void testAllArgsConstructor() throws Exception {
runTest("plugins/lombok/testData/compile/allArgsConstructor.kt"); runTest("plugins/lombok/testData/compile/allArgsConstructor.kt");
} }
@Test
@TestMetadata("allArgsConstructorStatic.kt") @TestMetadata("allArgsConstructorStatic.kt")
public void testAllArgsConstructorStatic() throws Exception { public void testAllArgsConstructorStatic() throws Exception {
runTest("plugins/lombok/testData/compile/allArgsConstructorStatic.kt"); runTest("plugins/lombok/testData/compile/allArgsConstructorStatic.kt");
} }
@Test
public void testAllFilesPresentInCompile() throws Exception { 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") @TestMetadata("clashAccessors.kt")
public void testClashAccessors() throws Exception { public void testClashAccessors() throws Exception {
runTest("plugins/lombok/testData/compile/clashAccessors.kt"); runTest("plugins/lombok/testData/compile/clashAccessors.kt");
} }
@Test
@TestMetadata("configAccessors.kt") @TestMetadata("configAccessors.kt")
public void testConfigAccessors() throws Exception { public void testConfigAccessors() throws Exception {
runTest("plugins/lombok/testData/compile/configAccessors.kt"); runTest("plugins/lombok/testData/compile/configAccessors.kt");
} }
@Test
@TestMetadata("configAccessorsOverride.kt") @TestMetadata("configAccessorsOverride.kt")
public void testConfigAccessorsOverride() throws Exception { public void testConfigAccessorsOverride() throws Exception {
runTest("plugins/lombok/testData/compile/configAccessorsOverride.kt"); runTest("plugins/lombok/testData/compile/configAccessorsOverride.kt");
} }
@Test
@TestMetadata("configCaseInsensitive.kt") @TestMetadata("configCaseInsensitive.kt")
public void testConfigCaseInsensitive() throws Exception { public void testConfigCaseInsensitive() throws Exception {
runTest("plugins/lombok/testData/compile/configCaseInsensitive.kt"); runTest("plugins/lombok/testData/compile/configCaseInsensitive.kt");
} }
@Test
@TestMetadata("configSimple.kt") @TestMetadata("configSimple.kt")
public void testConfigSimple() throws Exception { public void testConfigSimple() throws Exception {
runTest("plugins/lombok/testData/compile/configSimple.kt"); runTest("plugins/lombok/testData/compile/configSimple.kt");
} }
@Test
@TestMetadata("data.kt") @TestMetadata("data.kt")
public void testData() throws Exception { public void testData() throws Exception {
runTest("plugins/lombok/testData/compile/data.kt"); runTest("plugins/lombok/testData/compile/data.kt");
} }
@Test
@TestMetadata("genericsAccessors.kt") @TestMetadata("genericsAccessors.kt")
public void testGenericsAccessors() throws Exception { public void testGenericsAccessors() throws Exception {
runTest("plugins/lombok/testData/compile/genericsAccessors.kt"); runTest("plugins/lombok/testData/compile/genericsAccessors.kt");
} }
@Test
@TestMetadata("genericsConstructors.kt") @TestMetadata("genericsConstructors.kt")
public void testGenericsConstructors() throws Exception { public void testGenericsConstructors() throws Exception {
runTest("plugins/lombok/testData/compile/genericsConstructors.kt"); runTest("plugins/lombok/testData/compile/genericsConstructors.kt");
} }
@Test
@TestMetadata("genericsConstructorsStatic.kt") @TestMetadata("genericsConstructorsStatic.kt")
public void testGenericsConstructorsStatic() throws Exception { public void testGenericsConstructorsStatic() throws Exception {
runTest("plugins/lombok/testData/compile/genericsConstructorsStatic.kt"); runTest("plugins/lombok/testData/compile/genericsConstructorsStatic.kt");
} }
@Test
@TestMetadata("getters.kt") @TestMetadata("getters.kt")
public void testGetters() throws Exception { public void testGetters() throws Exception {
runTest("plugins/lombok/testData/compile/getters.kt"); runTest("plugins/lombok/testData/compile/getters.kt");
} }
@Test
@TestMetadata("gettersClassLevel.kt") @TestMetadata("gettersClassLevel.kt")
public void testGettersClassLevel() throws Exception { public void testGettersClassLevel() throws Exception {
runTest("plugins/lombok/testData/compile/gettersClassLevel.kt"); runTest("plugins/lombok/testData/compile/gettersClassLevel.kt");
} }
@Test
@TestMetadata("gettersFluent.kt") @TestMetadata("gettersFluent.kt")
public void testGettersFluent() throws Exception { public void testGettersFluent() throws Exception {
runTest("plugins/lombok/testData/compile/gettersFluent.kt"); runTest("plugins/lombok/testData/compile/gettersFluent.kt");
} }
@Test
@TestMetadata("noArgsConstructor.kt") @TestMetadata("noArgsConstructor.kt")
public void testNoArgsConstructor() throws Exception { public void testNoArgsConstructor() throws Exception {
runTest("plugins/lombok/testData/compile/noArgsConstructor.kt"); runTest("plugins/lombok/testData/compile/noArgsConstructor.kt");
} }
@Test
@TestMetadata("noArgsConstructorStatic.kt") @TestMetadata("noArgsConstructorStatic.kt")
public void testNoArgsConstructorStatic() throws Exception { public void testNoArgsConstructorStatic() throws Exception {
runTest("plugins/lombok/testData/compile/noArgsConstructorStatic.kt"); runTest("plugins/lombok/testData/compile/noArgsConstructorStatic.kt");
} }
@Test
@TestMetadata("nullability.kt") @TestMetadata("nullability.kt")
public void testNullability() throws Exception { public void testNullability() throws Exception {
runTest("plugins/lombok/testData/compile/nullability.kt"); runTest("plugins/lombok/testData/compile/nullability.kt");
} }
@Test
@TestMetadata("propertyFromSuper.kt") @TestMetadata("propertyFromSuper.kt")
public void testPropertyFromSuper() throws Exception { public void testPropertyFromSuper() throws Exception {
runTest("plugins/lombok/testData/compile/propertyFromSuper.kt"); runTest("plugins/lombok/testData/compile/propertyFromSuper.kt");
} }
@Test
@TestMetadata("requiredArgsConstructor.kt") @TestMetadata("requiredArgsConstructor.kt")
public void testRequiredArgsConstructor() throws Exception { public void testRequiredArgsConstructor() throws Exception {
runTest("plugins/lombok/testData/compile/requiredArgsConstructor.kt"); runTest("plugins/lombok/testData/compile/requiredArgsConstructor.kt");
} }
@Test
@TestMetadata("requiredArgsConstructorStatic.kt") @TestMetadata("requiredArgsConstructorStatic.kt")
public void testRequiredArgsConstructorStatic() throws Exception { public void testRequiredArgsConstructorStatic() throws Exception {
runTest("plugins/lombok/testData/compile/requiredArgsConstructorStatic.kt"); runTest("plugins/lombok/testData/compile/requiredArgsConstructorStatic.kt");
} }
@Test
@TestMetadata("setters.kt") @TestMetadata("setters.kt")
public void testSetters() throws Exception { public void testSetters() throws Exception {
runTest("plugins/lombok/testData/compile/setters.kt"); runTest("plugins/lombok/testData/compile/setters.kt");
} }
@Test
@TestMetadata("settersClassLevel.kt") @TestMetadata("settersClassLevel.kt")
public void testSettersClassLevel() throws Exception { public void testSettersClassLevel() throws Exception {
runTest("plugins/lombok/testData/compile/settersClassLevel.kt"); runTest("plugins/lombok/testData/compile/settersClassLevel.kt");
} }
@Test
@TestMetadata("settersVariations.kt") @TestMetadata("settersVariations.kt")
public void testSettersVariations() throws Exception { public void testSettersVariations() throws Exception {
runTest("plugins/lombok/testData/compile/settersVariations.kt"); runTest("plugins/lombok/testData/compile/settersVariations.kt");
} }
@Test
@TestMetadata("simple.kt") @TestMetadata("simple.kt")
public void testSimple() throws Exception { public void testSimple() throws Exception {
runTest("plugins/lombok/testData/compile/simple.kt"); runTest("plugins/lombok/testData/compile/simple.kt");
} }
@Test
@TestMetadata("value.kt") @TestMetadata("value.kt")
public void testValue() throws Exception { public void testValue() throws Exception {
runTest("plugins/lombok/testData/compile/value.kt"); runTest("plugins/lombok/testData/compile/value.kt");
} }
@Test
@TestMetadata("with.kt") @TestMetadata("with.kt")
public void testWith() throws Exception { public void testWith() throws Exception {
runTest("plugins/lombok/testData/compile/with.kt"); runTest("plugins/lombok/testData/compile/with.kt");
} }
@Nested
@TestMetadata("plugins/lombok/testData/compile/processErrors") @TestMetadata("plugins/lombok/testData/compile/processErrors")
@TestDataPath("$PROJECT_ROOT") @TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class) public class ProcessErrors {
public static class ProcessErrors extends AbstractLombokCompileTest { @Test
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInProcessErrors() throws Exception { 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") @TestMetadata("annotationTypes.kt")
public void testAnnotationTypes() throws Exception { public void testAnnotationTypes() throws Exception {
runTest("plugins/lombok/testData/compile/processErrors/annotationTypes.kt"); runTest("plugins/lombok/testData/compile/processErrors/annotationTypes.kt");
@@ -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");
}
}
}
@@ -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<TestFile>) {
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<String>) {
javaClasspath += getLombokJar().absolutePath
}
override fun configureTestSpecific(configuration: CompilerConfiguration, testFiles: List<TestFile>) {
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<TestFile>): 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)
}
@@ -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<TestFile> {
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)
}
}