From 6c1920568d4c9c98ed5bb86ebf106a92ff63ef01 Mon Sep 17 00:00:00 2001 From: Zongle Wang Date: Mon, 2 Dec 2024 21:26:19 -0500 Subject: [PATCH] Add a new source set to share test kits (#1081) * Share Utils.kt * Rename testFixtures to testKit * Depend on the output of main --- build.gradle.kts | 10 +++++++++- .../PropertiesFileTransformerSpec.groovy | 13 +++++++------ .../transformers/TransformerSpecSupport.groovy | 3 --- .../ApacheNoticeResourceTransformerTest.kt | 2 +- .../shadow/transformers/AppendingTransformerTest.kt | 2 +- .../transformers/ManifestAppenderTransformerTest.kt | 2 +- .../transformers/PropertiesFileTransformerTest.kt | 2 +- .../transformers/XmlAppendingTransformerTest.kt | 2 +- .../gradle/plugins/shadow/testkit}/util/Utils.kt | 4 +++- 9 files changed, 24 insertions(+), 16 deletions(-) rename src/{test/kotlin/com/github/jengelman/gradle/plugins/shadow => testKit/kotlin/com/github/jengelman/gradle/plugins/shadow/testkit}/util/Utils.kt (65%) diff --git a/build.gradle.kts b/build.gradle.kts index aa4265751..bf84d0158 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -43,6 +43,9 @@ spotless { } } +val testKit: SourceSet by sourceSets.creating +val testKitImplementation: Configuration by configurations.getting + val intiTest: SourceSet by sourceSets.creating val intiTestImplementation: Configuration by configurations.getting { extendsFrom(configurations.testImplementation.get()) @@ -74,6 +77,11 @@ dependencies { implementation(libs.plexus.utils) implementation(libs.plexus.xml) + val mainOutput = sourceSets.main.map { it.output } + testKitImplementation(mainOutput) + testKitImplementation(gradleTestKit()) + + testImplementation(testKit.output) testImplementation(platform(libs.junit.bom)) testImplementation(libs.junit.jupiter) testImplementation(libs.assertk) @@ -85,7 +93,7 @@ dependencies { exclude(group = "org.codehaus.groovy") exclude(group = "org.hamcrest") } - funcTestImplementation(sourceSets.main.get().output) + funcTestImplementation(mainOutput) lintChecks(libs.androidx.gradlePluginLints) lintChecks(libs.assertk.lint) diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformerSpec.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformerSpec.groovy index 72a5e40c3..6fc067a6b 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformerSpec.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformerSpec.groovy @@ -22,6 +22,7 @@ package com.github.jengelman.gradle.plugins.shadow.transformers import com.github.jengelman.gradle.plugins.shadow.transformers.PropertiesFileTransformer.MergeStrategy import spock.lang.Unroll +import static com.github.jengelman.gradle.plugins.shadow.testkit.util.Utils.testObjectFactory import static groovy.lang.Closure.IDENTITY @Unroll @@ -29,7 +30,7 @@ class PropertiesFileTransformerSpec extends TransformerSpecSupport { void "Path #path #transform transformed"() { given: - Transformer transformer = new PropertiesFileTransformer(objectFactory) + Transformer transformer = new PropertiesFileTransformer(testObjectFactory) when: boolean actual = transformer.canTransformResource(getFileElement(path)) @@ -49,7 +50,7 @@ class PropertiesFileTransformerSpec extends TransformerSpecSupport { void exerciseAllTransformConfigurations() { given: def element = getFileElement(path) - Transformer transformer = new PropertiesFileTransformer(objectFactory) + Transformer transformer = new PropertiesFileTransformer(testObjectFactory) transformer.mergeStrategy.set(MergeStrategy.from(mergeStrategy)) transformer.mergeSeparator.set(mergeSeparator) @@ -73,7 +74,7 @@ class PropertiesFileTransformerSpec extends TransformerSpecSupport { void exerciseAllTransformConfigurationsWithPaths() { given: def element = getFileElement(path) - Transformer transformer = new PropertiesFileTransformer(objectFactory) + Transformer transformer = new PropertiesFileTransformer(testObjectFactory) transformer.paths.set(paths) transformer.mergeStrategy.set(MergeStrategy.from('first')) @@ -97,7 +98,7 @@ class PropertiesFileTransformerSpec extends TransformerSpecSupport { void exerciseAllTransformConfigurationsWithMappings() { given: def element = getFileElement(path) - Transformer transformer = new PropertiesFileTransformer(objectFactory) + Transformer transformer = new PropertiesFileTransformer(testObjectFactory) transformer.mappings.set(mappings) transformer.mergeStrategy.set(MergeStrategy.from('latest')) @@ -123,7 +124,7 @@ class PropertiesFileTransformerSpec extends TransformerSpecSupport { void appliesKeyTransformer() { given: def element = getFileElement(path) - Transformer transformer = new PropertiesFileTransformer(objectFactory) + Transformer transformer = new PropertiesFileTransformer(testObjectFactory) transformer.keyTransformer.set(keyTransformer) transformer.mergeStrategy.set(MergeStrategy.from('append')) @@ -147,7 +148,7 @@ class PropertiesFileTransformerSpec extends TransformerSpecSupport { void appliesCharset() { given: def element = getFileElement(path) - def transformer = new PropertiesFileTransformer(objectFactory) + def transformer = new PropertiesFileTransformer(testObjectFactory) transformer.charsetName.set(charset) when: diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/TransformerSpecSupport.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/TransformerSpecSupport.groovy index 818697e0b..86978937c 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/TransformerSpecSupport.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/TransformerSpecSupport.groovy @@ -4,14 +4,11 @@ import com.github.jengelman.gradle.plugins.shadow.ShadowStats import org.gradle.api.file.FileTreeElement import org.gradle.api.file.RelativePath import org.gradle.api.internal.file.DefaultFileTreeElement -import org.gradle.testfixtures.ProjectBuilder import spock.lang.Shared import spock.lang.Specification class TransformerSpecSupport extends Specification { - protected static final def objectFactory = ProjectBuilder.builder().build().objects - @Shared ShadowStats stats diff --git a/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNoticeResourceTransformerTest.kt b/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNoticeResourceTransformerTest.kt index 05d013dbf..f8cf651ff 100644 --- a/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNoticeResourceTransformerTest.kt +++ b/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNoticeResourceTransformerTest.kt @@ -4,7 +4,7 @@ import assertk.assertThat import assertk.assertions.isFalse import assertk.assertions.isTrue import assertk.fail -import com.github.jengelman.gradle.plugins.shadow.util.testObjectFactory +import com.github.jengelman.gradle.plugins.shadow.testkit.util.testObjectFactory import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test diff --git a/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/AppendingTransformerTest.kt b/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/AppendingTransformerTest.kt index b5eee7d89..681000705 100644 --- a/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/AppendingTransformerTest.kt +++ b/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/AppendingTransformerTest.kt @@ -3,7 +3,7 @@ package com.github.jengelman.gradle.plugins.shadow.transformers import assertk.assertThat import assertk.assertions.isFalse import assertk.assertions.isTrue -import com.github.jengelman.gradle.plugins.shadow.util.testObjectFactory +import com.github.jengelman.gradle.plugins.shadow.testkit.util.testObjectFactory import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test diff --git a/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ManifestAppenderTransformerTest.kt b/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ManifestAppenderTransformerTest.kt index 9c1e8c084..935c98da6 100644 --- a/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ManifestAppenderTransformerTest.kt +++ b/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ManifestAppenderTransformerTest.kt @@ -6,7 +6,7 @@ import assertk.assertions.isFalse import assertk.assertions.isGreaterThan import assertk.assertions.isNotEmpty import assertk.assertions.isTrue -import com.github.jengelman.gradle.plugins.shadow.util.testObjectFactory +import com.github.jengelman.gradle.plugins.shadow.testkit.util.testObjectFactory import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test diff --git a/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformerTest.kt b/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformerTest.kt index 3106cc9ba..81e084d43 100644 --- a/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformerTest.kt +++ b/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformerTest.kt @@ -6,7 +6,7 @@ import assertk.assertions.isEqualTo import assertk.assertions.isFalse import assertk.assertions.isNotEmpty import assertk.assertions.isTrue -import com.github.jengelman.gradle.plugins.shadow.util.testObjectFactory +import com.github.jengelman.gradle.plugins.shadow.testkit.util.testObjectFactory import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test diff --git a/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformerTest.kt b/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformerTest.kt index 1eaf76436..32895d9fc 100644 --- a/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformerTest.kt +++ b/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformerTest.kt @@ -3,7 +3,7 @@ package com.github.jengelman.gradle.plugins.shadow.transformers import assertk.assertThat import assertk.assertions.isFalse import assertk.assertions.isTrue -import com.github.jengelman.gradle.plugins.shadow.util.testObjectFactory +import com.github.jengelman.gradle.plugins.shadow.testkit.util.testObjectFactory import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test diff --git a/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/util/Utils.kt b/src/testKit/kotlin/com/github/jengelman/gradle/plugins/shadow/testkit/util/Utils.kt similarity index 65% rename from src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/util/Utils.kt rename to src/testKit/kotlin/com/github/jengelman/gradle/plugins/shadow/testkit/util/Utils.kt index a6acfd481..0785681b0 100644 --- a/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/util/Utils.kt +++ b/src/testKit/kotlin/com/github/jengelman/gradle/plugins/shadow/testkit/util/Utils.kt @@ -1,4 +1,6 @@ -package com.github.jengelman.gradle.plugins.shadow.util +@file:JvmName("Utils") + +package com.github.jengelman.gradle.plugins.shadow.testkit.util import org.gradle.api.model.ObjectFactory import org.gradle.testfixtures.ProjectBuilder