From f640a7be2e4001eca507779a69e72674c0315bf9 Mon Sep 17 00:00:00 2001 From: "Aleksei.Cherepanov" Date: Wed, 15 Feb 2023 16:24:19 +0100 Subject: [PATCH] Add the possibility to mute Gradle IC tests by folder If you need to mute a test for Gradle IC, the only way is to add exclude pattern and regenerate tests aka remove unnecessary tests. But the filter is absolute, so if you have the same test name in different subfolders (e.g. `pureKotlin/classRemoved/` and `classHierarchyAffected/classRemoved`) you cannot disable only one of them. This commit adds logic to specify which name pattern in which subfolder should be excluded --- ...ghtTreeJvmCompilerRunnerTestGenerated.java | 2 +- ...ntalFirJvmCompilerRunnerTestGenerated.java | 2 +- ...ghtTreeJvmCompilerRunnerTestGenerated.java | 2 +- ...ementalJvmCompilerRunnerTestGenerated.java | 2 +- .../kotlin/generators/tests/GenerateTests.kt | 25 ++---- .../tests/IncrementalTestsGeneratorUtil.kt | 83 +++++++++++++++++++ 6 files changed, 94 insertions(+), 22 deletions(-) create mode 100644 generators/tests/org/jetbrains/kotlin/generators/tests/IncrementalTestsGeneratorUtil.kt diff --git a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalFirICLightTreeJvmCompilerRunnerTestGenerated.java b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalFirICLightTreeJvmCompilerRunnerTestGenerated.java index f85d11b1f74..449398dafee 100644 --- a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalFirICLightTreeJvmCompilerRunnerTestGenerated.java +++ b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalFirICLightTreeJvmCompilerRunnerTestGenerated.java @@ -59,7 +59,7 @@ public class IncrementalFirICLightTreeJvmCompilerRunnerTestGenerated extends Abs } public void testAllFilesPresentInPureKotlin() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("jps/jps-plugin/testData/incremental/pureKotlin"), Pattern.compile("^([^\\.]+)$"), Pattern.compile("^.*Expect.*"), TargetBackend.JVM_IR, false); + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("jps/jps-plugin/testData/incremental/pureKotlin"), Pattern.compile("^([^\\.]+)$"), Pattern.compile("(^.*Expect.*)"), TargetBackend.JVM_IR, false); } @TestMetadata("annotations") diff --git a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalFirJvmCompilerRunnerTestGenerated.java b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalFirJvmCompilerRunnerTestGenerated.java index 8a6db682921..28752aea41d 100644 --- a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalFirJvmCompilerRunnerTestGenerated.java +++ b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalFirJvmCompilerRunnerTestGenerated.java @@ -59,7 +59,7 @@ public class IncrementalFirJvmCompilerRunnerTestGenerated extends AbstractIncrem } public void testAllFilesPresentInPureKotlin() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("jps/jps-plugin/testData/incremental/pureKotlin"), Pattern.compile("^([^\\.]+)$"), Pattern.compile("^.*Expect.*"), TargetBackend.JVM_IR, false); + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("jps/jps-plugin/testData/incremental/pureKotlin"), Pattern.compile("^([^\\.]+)$"), Pattern.compile("(^.*Expect.*)"), TargetBackend.JVM_IR, false); } @TestMetadata("annotations") diff --git a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalFirLightTreeJvmCompilerRunnerTestGenerated.java b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalFirLightTreeJvmCompilerRunnerTestGenerated.java index 3c104aa8234..30d8cfe701b 100644 --- a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalFirLightTreeJvmCompilerRunnerTestGenerated.java +++ b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalFirLightTreeJvmCompilerRunnerTestGenerated.java @@ -59,7 +59,7 @@ public class IncrementalFirLightTreeJvmCompilerRunnerTestGenerated extends Abstr } public void testAllFilesPresentInPureKotlin() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("jps/jps-plugin/testData/incremental/pureKotlin"), Pattern.compile("^([^\\.]+)$"), Pattern.compile("^.*Expect.*"), TargetBackend.JVM_IR, false); + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("jps/jps-plugin/testData/incremental/pureKotlin"), Pattern.compile("^([^\\.]+)$"), Pattern.compile("(^.*Expect.*)"), TargetBackend.JVM_IR, false); } @TestMetadata("annotations") diff --git a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunnerTestGenerated.java b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunnerTestGenerated.java index 9de62c7331b..6ffe8cec857 100644 --- a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunnerTestGenerated.java +++ b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunnerTestGenerated.java @@ -59,7 +59,7 @@ public class IncrementalJvmCompilerRunnerTestGenerated extends AbstractIncrement } public void testAllFilesPresentInPureKotlin() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("jps/jps-plugin/testData/incremental/pureKotlin"), Pattern.compile("^([^\\.]+)$"), Pattern.compile(".*SinceK2"), TargetBackend.JVM_IR, false); + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("jps/jps-plugin/testData/incremental/pureKotlin"), Pattern.compile("^([^\\.]+)$"), Pattern.compile("(.*SinceK2)"), TargetBackend.JVM_IR, false); } @TestMetadata("annotations") diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index 4b2a4117b22..fa071fc9707 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -20,10 +20,11 @@ import org.jetbrains.kotlin.assignment.plugin.AbstractIrBlackBoxCodegenTestAssig import org.jetbrains.kotlin.assignment.plugin.AbstractAssignmentPluginDiagnosticTest import org.jetbrains.kotlin.fir.plugin.runners.AbstractFirPluginBlackBoxCodegenTest import org.jetbrains.kotlin.fir.plugin.runners.AbstractFirPluginDiagnosticTest -import org.jetbrains.kotlin.generators.TestGroup import org.jetbrains.kotlin.generators.generateTestGroupSuiteWithJUnit5 import org.jetbrains.kotlin.generators.impl.generateTestGroupSuite import org.jetbrains.kotlin.generators.model.annotation +import org.jetbrains.kotlin.generators.tests.IncrementalTestsGeneratorUtil.Companion.IcTestTypes.* +import org.jetbrains.kotlin.generators.tests.IncrementalTestsGeneratorUtil.Companion.incrementalJvmTestData import org.jetbrains.kotlin.incremental.* import org.jetbrains.kotlin.jvm.abi.* import org.jetbrains.kotlin.kapt.cli.test.AbstractArgumentParsingTest @@ -45,41 +46,29 @@ fun main(args: Array) { System.setProperty("java.awt.headless", "true") generateTestGroupSuite(args) { testGroup("compiler/incremental-compilation-impl/test", "jps/jps-plugin/testData") { - fun incrementalJvmTestData(targetBackend: TargetBackend, excludePattern: String? = null): TestGroup.TestClass.() -> Unit = { - model( - "incremental/pureKotlin", - extension = null, - recursive = false, - targetBackend = targetBackend, - excludedPattern = excludePattern - ) - model("incremental/classHierarchyAffected", extension = null, recursive = false, targetBackend = targetBackend) - model("incremental/inlineFunCallSite", extension = null, excludeParentDirs = true, targetBackend = targetBackend) - model("incremental/withJava", extension = null, excludeParentDirs = true, targetBackend = targetBackend) - model("incremental/incrementalJvmCompilerOnly", extension = null, excludeParentDirs = true, targetBackend = targetBackend) - } testClass( init = incrementalJvmTestData( targetBackend = TargetBackend.JVM_IR, - excludePattern = ".*SinceK2" + folderToExcludePatternMap = mapOf(PURE_KOTLIN to ".*SinceK2") ) ) + testClass( init = incrementalJvmTestData( TargetBackend.JVM_IR, - excludePattern = "^.*Expect.*" + folderToExcludePatternMap = mapOf(PURE_KOTLIN to "^.*Expect.*") ) ) testClass( init = incrementalJvmTestData( TargetBackend.JVM_IR, - excludePattern = "^.*Expect.*" + folderToExcludePatternMap = mapOf(PURE_KOTLIN to "^.*Expect.*") ) ) testClass( init = incrementalJvmTestData( TargetBackend.JVM_IR, - excludePattern = "^.*Expect.*" + folderToExcludePatternMap = mapOf(PURE_KOTLIN to "^.*Expect.*") ) ) diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/IncrementalTestsGeneratorUtil.kt b/generators/tests/org/jetbrains/kotlin/generators/tests/IncrementalTestsGeneratorUtil.kt new file mode 100644 index 00000000000..1d2c7b49f58 --- /dev/null +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/IncrementalTestsGeneratorUtil.kt @@ -0,0 +1,83 @@ +/* + * Copyright 2010-2023 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.generators.tests + +import org.jetbrains.kotlin.generators.TestGroup +import org.jetbrains.kotlin.generators.tests.IncrementalTestsGeneratorUtil.Companion.IcTestTypes.* +import org.jetbrains.kotlin.test.TargetBackend + +class IncrementalTestsGeneratorUtil { + companion object { + enum class IcTestTypes(val folderName: String) { + ALL("all"), + PURE_KOTLIN("pureKotlin"), + CLASS_HIERARCHY_AFFECTED("classHierarchyAffected"), + INLINE_FUN_CALL_SITE("inlineFunCallSite"), + WITH_JAVA("withJava"), + INCREMENTAL_JVM_COMPILER_ONLY("incrementalJvmCompilerOnly") + } + + private fun buildExcludePattern(excludePatterns: List): String? = + excludePatterns.joinToString("|") { "($it)" }.ifBlank { null } + + fun incrementalJvmTestData( + targetBackend: TargetBackend, + folderToExcludePatternMap: Map? = null + ): TestGroup.TestClass.() -> Unit = { + val excludeForAllTestData = folderToExcludePatternMap?.get(ALL) + model( + "incremental/${PURE_KOTLIN.folderName}", + extension = null, + recursive = false, + targetBackend = targetBackend, + excludedPattern = buildExcludePattern(listOfNotNull(folderToExcludePatternMap?.get(PURE_KOTLIN), excludeForAllTestData)) + ) + model( + "incremental/${CLASS_HIERARCHY_AFFECTED.folderName}", + extension = null, + recursive = false, + targetBackend = targetBackend, + excludedPattern = buildExcludePattern( + listOfNotNull( + folderToExcludePatternMap?.get(CLASS_HIERARCHY_AFFECTED), + excludeForAllTestData + ) + ) + ) + model( + "incremental/${INLINE_FUN_CALL_SITE.folderName}", + extension = null, + excludeParentDirs = true, + targetBackend = targetBackend, + excludedPattern = buildExcludePattern( + listOfNotNull( + folderToExcludePatternMap?.get(INLINE_FUN_CALL_SITE), + excludeForAllTestData + ) + ) + ) + model( + "incremental/${WITH_JAVA.folderName}", + extension = null, + excludeParentDirs = true, + targetBackend = targetBackend, + excludedPattern = buildExcludePattern(listOfNotNull(folderToExcludePatternMap?.get(WITH_JAVA), excludeForAllTestData)) + ) + model( + "incremental/${INCREMENTAL_JVM_COMPILER_ONLY.folderName}", + extension = null, + excludeParentDirs = true, + targetBackend = targetBackend, + excludedPattern = buildExcludePattern( + listOfNotNull( + folderToExcludePatternMap?.get(INCREMENTAL_JVM_COMPILER_ONLY), + excludeForAllTestData + ) + ) + ) + } + } +} \ No newline at end of file