[SAM with receiver] Partially migrate tests to new infrastructure

Script tests still use old infrastructure, because there is no support
  for them in new framework
This commit is contained in:
Dmitriy Novozhilov
2022-06-22 13:57:21 +03:00
committed by teamcity
parent 04bf5bfe0b
commit 49c836e706
13 changed files with 66 additions and 37 deletions
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.kapt3.test.AbstractKotlinKaptContextTest
import org.jetbrains.kotlin.lombok.* import org.jetbrains.kotlin.lombok.*
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.AbstractSamWithReceiverScriptNewDefTest
import org.jetbrains.kotlin.samWithReceiver.AbstractSamWithReceiverScriptTest import org.jetbrains.kotlin.samWithReceiver.AbstractSamWithReceiverScriptTest
import org.jetbrains.kotlin.samWithReceiver.AbstractSamWithReceiverTest import org.jetbrains.kotlin.samWithReceiver.AbstractSamWithReceiverTest
import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.TargetBackend
@@ -224,12 +225,13 @@ fun main(args: Array<String>) {
} }
testGroup("plugins/sam-with-receiver/tests-gen", "plugins/sam-with-receiver/testData") { testGroup("plugins/sam-with-receiver/tests-gen", "plugins/sam-with-receiver/testData") {
testClass<AbstractSamWithReceiverTest> {
model("diagnostics")
}
testClass<AbstractSamWithReceiverScriptTest> { testClass<AbstractSamWithReceiverScriptTest> {
model("script", extension = "kts") model("script", extension = "kts")
} }
testClass<AbstractSamWithReceiverScriptNewDefTest> {
model("script", extension = "kts")
}
} }
testGroup( testGroup(
@@ -449,5 +451,11 @@ fun main(args: Array<String>) {
model("diagnostics", excludedPattern = excludedFirTestdataPattern) model("diagnostics", excludedPattern = excludedFirTestdataPattern)
} }
} }
testGroup("plugins/sam-with-receiver/tests-gen", "plugins/sam-with-receiver/testData") {
testClass<AbstractSamWithReceiverTest> {
model("diagnostics", excludedPattern = excludedFirTestdataPattern)
}
}
} }
} }
@@ -5,20 +5,36 @@
package org.jetbrains.kotlin.samWithReceiver package org.jetbrains.kotlin.samWithReceiver
import org.jetbrains.kotlin.ObsoleteTestInfrastructure import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.checkers.AbstractDiagnosticsTest import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives
import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives.DIAGNOSTICS
import org.jetbrains.kotlin.test.model.TestModule
import org.jetbrains.kotlin.test.runners.AbstractDiagnosticTest
import org.jetbrains.kotlin.test.services.EnvironmentConfigurator
import org.jetbrains.kotlin.test.services.TestServices
@OptIn(ObsoleteTestInfrastructure::class) abstract class AbstractSamWithReceiverTest : AbstractDiagnosticTest() {
abstract class AbstractSamWithReceiverTest : AbstractDiagnosticsTest() { override fun configure(builder: TestConfigurationBuilder) {
private companion object { super.configure(builder)
builder.configurePlugin()
}
}
fun TestConfigurationBuilder.configurePlugin() {
useConfigurators(::SamWithReceiverEnvironmentConfigurator)
}
class SamWithReceiverEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigurator(testServices) {
companion object {
private val TEST_ANNOTATIONS = listOf("SamWithReceiver") private val TEST_ANNOTATIONS = listOf("SamWithReceiver")
} }
override fun setupEnvironment(environment: KotlinCoreEnvironment) { override fun registerCompilerExtensions(project: Project, module: TestModule, configuration: CompilerConfiguration) {
StorageComponentContainerContributor.registerExtension( StorageComponentContainerContributor.registerExtension(
environment.project, project,
CliSamWithReceiverComponentContributor(TEST_ANNOTATIONS) CliSamWithReceiverComponentContributor(TEST_ANNOTATIONS)
) )
} }
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER,-UNUSED_VARIABLE // FIR_IDENTICAL
// FILE: Sam.java // FILE: Sam.java
@SamWithReceiver @SamWithReceiver
@@ -18,4 +18,4 @@ fun test() {
val a: String = <!NO_THIS!>this<!> val a: String = <!NO_THIS!>this<!>
System.out.println(a) System.out.println(a)
} }
} }
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER,-UNUSED_VARIABLE // FIR_IDENTICAL
// FILE: Sam.java // FILE: Sam.java
@SamWithReceiver @SamWithReceiver
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER,-UNUSED_VARIABLE // FIR_IDENTICAL
// FILE: Sam.java // FILE: Sam.java
@SamWithReceiver @SamWithReceiver
@@ -25,4 +25,4 @@ fun test() {
val a: String = <!NO_THIS!>this<!> val a: String = <!NO_THIS!>this<!>
System.out.println(a) System.out.println(a)
} }
} }
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER,-UNUSED_VARIABLE // FIR_IDENTICAL
// FILE: Sam.java // FILE: Sam.java
@SamWithReceiver @SamWithReceiver
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER,-UNUSED_VARIABLE // FIR_IDENTICAL
// FILE: Sam.java // FILE: Sam.java
public interface Sam { public interface Sam {
@@ -16,4 +16,4 @@ fun test() {
e.exec { a -> System.out.println(a) } e.exec { a -> System.out.println(a) }
e.exec { System.out.println(<!NO_THIS!>this<!>) } e.exec { System.out.println(<!NO_THIS!>this<!>) }
} }
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER,-UNUSED_VARIABLE // FIR_IDENTICAL
// FILE: Sam.java // FILE: Sam.java
@SamWithReceiver @SamWithReceiver
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER,-UNUSED_VARIABLE // FIR_IDENTICAL
// FILE: Sam.java // FILE: Sam.java
public interface Sam { public interface Sam {
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER,-UNUSED_VARIABLE // FIR_IDENTICAL
// FILE: Sam.java // FILE: Sam.java
@SamWithReceiver @SamWithReceiver
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER,-UNUSED_VARIABLE // FIR_IDENTICAL
// FILE: Sam.java // FILE: Sam.java
public interface Sam { public interface Sam {
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. * 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. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.samWithReceiver;
import com.intellij.testFramework.TestDataPath; import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils; import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.test.TestMetadata; import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@@ -16,8 +17,8 @@ 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 org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all") @SuppressWarnings("all")
@TestMetadata("plugins/sam-with-receiver/sam-with-receiver-cli/testData/script") @TestMetadata("plugins/sam-with-receiver/testData/script")
@TestDataPath("/") @TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class) @RunWith(JUnit3RunnerWithInners.class)
public class SamWithReceiverScriptNewDefTestGenerated extends AbstractSamWithReceiverScriptNewDefTest { public class SamWithReceiverScriptNewDefTestGenerated extends AbstractSamWithReceiverScriptNewDefTest {
private void runTest(String testDataFilePath) throws Exception { private void runTest(String testDataFilePath) throws Exception {
@@ -25,7 +26,7 @@ public class SamWithReceiverScriptNewDefTestGenerated extends AbstractSamWithRec
} }
public void testAllFilesPresentInScript() throws Exception { public void testAllFilesPresentInScript() throws Exception {
org.jetbrains.kotlin.test.util.KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/sam-with-receiver/sam-with-receiver-cli/testData/script"), Pattern.compile("^(.+)\\.kts$"), null, true); KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/sam-with-receiver/testData/script"), Pattern.compile("^(.+)\\.kts$"), null, true);
} }
@TestMetadata("samConversionSimple.kts") @TestMetadata("samConversionSimple.kts")
@@ -6,69 +6,73 @@
package org.jetbrains.kotlin.samWithReceiver; package org.jetbrains.kotlin.samWithReceiver;
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.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/sam-with-receiver/testData/diagnostics") @TestMetadata("plugins/sam-with-receiver/testData/diagnostics")
@TestDataPath("$PROJECT_ROOT") @TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class SamWithReceiverTestGenerated extends AbstractSamWithReceiverTest { public class SamWithReceiverTestGenerated extends AbstractSamWithReceiverTest {
private void runTest(String testDataFilePath) throws Exception { @Test
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInDiagnostics() throws Exception { public void testAllFilesPresentInDiagnostics() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/sam-with-receiver/testData/diagnostics"), Pattern.compile("^(.+)\\.kt$"), null, true); KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/sam-with-receiver/testData/diagnostics"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
} }
@Test
@TestMetadata("noParameters.kt") @TestMetadata("noParameters.kt")
public void testNoParameters() throws Exception { public void testNoParameters() throws Exception {
runTest("plugins/sam-with-receiver/testData/diagnostics/noParameters.kt"); runTest("plugins/sam-with-receiver/testData/diagnostics/noParameters.kt");
} }
@Test
@TestMetadata("noReturnType.kt") @TestMetadata("noReturnType.kt")
public void testNoReturnType() throws Exception { public void testNoReturnType() throws Exception {
runTest("plugins/sam-with-receiver/testData/diagnostics/noReturnType.kt"); runTest("plugins/sam-with-receiver/testData/diagnostics/noReturnType.kt");
} }
@Test
@TestMetadata("samConversionNoParameters.kt") @TestMetadata("samConversionNoParameters.kt")
public void testSamConversionNoParameters() throws Exception { public void testSamConversionNoParameters() throws Exception {
runTest("plugins/sam-with-receiver/testData/diagnostics/samConversionNoParameters.kt"); runTest("plugins/sam-with-receiver/testData/diagnostics/samConversionNoParameters.kt");
} }
@Test
@TestMetadata("samConversionSimple.kt") @TestMetadata("samConversionSimple.kt")
public void testSamConversionSimple() throws Exception { public void testSamConversionSimple() throws Exception {
runTest("plugins/sam-with-receiver/testData/diagnostics/samConversionSimple.kt"); runTest("plugins/sam-with-receiver/testData/diagnostics/samConversionSimple.kt");
} }
@Test
@TestMetadata("samConversionSimpleWithoutAnnotation.kt") @TestMetadata("samConversionSimpleWithoutAnnotation.kt")
public void testSamConversionSimpleWithoutAnnotation() throws Exception { public void testSamConversionSimpleWithoutAnnotation() throws Exception {
runTest("plugins/sam-with-receiver/testData/diagnostics/samConversionSimpleWithoutAnnotation.kt"); runTest("plugins/sam-with-receiver/testData/diagnostics/samConversionSimpleWithoutAnnotation.kt");
} }
@Test
@TestMetadata("samWithAnnotation.kt") @TestMetadata("samWithAnnotation.kt")
public void testSamWithAnnotation() throws Exception { public void testSamWithAnnotation() throws Exception {
runTest("plugins/sam-with-receiver/testData/diagnostics/samWithAnnotation.kt"); runTest("plugins/sam-with-receiver/testData/diagnostics/samWithAnnotation.kt");
} }
@Test
@TestMetadata("samWithoutAnnotation.kt") @TestMetadata("samWithoutAnnotation.kt")
public void testSamWithoutAnnotation() throws Exception { public void testSamWithoutAnnotation() throws Exception {
runTest("plugins/sam-with-receiver/testData/diagnostics/samWithoutAnnotation.kt"); runTest("plugins/sam-with-receiver/testData/diagnostics/samWithoutAnnotation.kt");
} }
@Test
@TestMetadata("singleParameter.kt") @TestMetadata("singleParameter.kt")
public void testSingleParameter() throws Exception { public void testSingleParameter() throws Exception {
runTest("plugins/sam-with-receiver/testData/diagnostics/singleParameter.kt"); runTest("plugins/sam-with-receiver/testData/diagnostics/singleParameter.kt");
} }
@Test
@TestMetadata("singleParameterWithoutAnnotation.kt") @TestMetadata("singleParameterWithoutAnnotation.kt")
public void testSingleParameterWithoutAnnotation() throws Exception { public void testSingleParameterWithoutAnnotation() throws Exception {
runTest("plugins/sam-with-receiver/testData/diagnostics/singleParameterWithoutAnnotation.kt"); runTest("plugins/sam-with-receiver/testData/diagnostics/singleParameterWithoutAnnotation.kt");