Skip to content

Commit

Permalink
Add a new source set to share test kits (#1081)
Browse files Browse the repository at this point in the history
* Share Utils.kt

* Rename testFixtures to testKit

* Depend on the output of main
  • Loading branch information
Goooler authored Dec 3, 2024
1 parent 9f9d6f0 commit 6c19205
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 16 deletions.
10 changes: 9 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ 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
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))
Expand All @@ -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)

Expand All @@ -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'))

Expand All @@ -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'))

Expand All @@ -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'))

Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 6c19205

Please sign in to comment.