Skip to content

Commit

Permalink
Make configuration inheritance consistent with Gradle (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalh authored Dec 11, 2024
1 parent 913c667 commit 5b31ee0
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.coditory.gradle.integration

import com.coditory.gradle.integration.base.GradleTestVersions.GRADLE_MAX_SUPPORTED_VERSION
import com.coditory.gradle.integration.base.GradleTestVersions.GRADLE_MIN_SUPPORTED_VERSION
import com.coditory.gradle.integration.base.TestProjectBuilder
import org.assertj.core.api.Assertions.assertThat
import org.gradle.testkit.runner.TaskOutcome
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.AutoClose
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource

class ConfigurationInheritanceTest {
companion object {
@AutoClose
private val project = TestProjectBuilder
.project("project-${ConfigurationInheritanceTest::class.simpleName}")
.withBuildGradleKts(
"""
plugins {
id("com.coditory.integration-test")
}
repositories {
mavenCentral()
}
testing {
suites {
register<JvmTestSuite>("customTest")
}
}
val customTestImplementation by configurations.getting {
extendsFrom(configurations.integrationImplementation.get())
}
val customTestRuntimeOnly by configurations.getting {
extendsFrom(configurations.integrationRuntimeOnly.get())
}
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:${Versions.junit}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${Versions.junit}")
// sample dependency
implementation("com.google.code.gson:gson:${Versions.gson}")
}
tasks.withType<Test>().configureEach {
useJUnitPlatform()
testLogging {
events("passed", "failed", "skipped")
setExceptionFormat("full")
}
}
""",
).withFile(
"src/customTest/java/TestSpec.java",
"""
import org.junit.jupiter.api.Test;
import com.google.gson.Gson;
public class TestSpec {
@Test
void shouldResolveCompileDependencyFromMainConfig() {
// Gson class import is the actual test
}
}
""",
)
.build()
}

@AfterEach
fun cleanProject() {
project.clean()
}

@ParameterizedTest(name = "should resolve compile dependencies in custom test suite for gradle {0}")
@ValueSource(strings = [GRADLE_MAX_SUPPORTED_VERSION, GRADLE_MIN_SUPPORTED_VERSION])
fun `should resolve compile dependencies in custom test suite`(gradleVersion: String?) {
// when
val result = project.runGradle(listOf("customTest"), gradleVersion)
// then
assertThat(result.task(":customTest")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@ internal object TestSuitesConfiguration {
val testSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME)
val integrationSourceSet = testSuite.sources

project.configurations.getByName(integrationSourceSet.compileClasspathConfigurationName)
.extendsFrom(project.configurations.getByName(testSourceSet.compileClasspathConfigurationName))
project.configurations.getByName(integrationSourceSet.implementationConfigurationName)
.extendsFrom(project.configurations.getByName(testSourceSet.implementationConfigurationName))

project.configurations.getByName(integrationSourceSet.runtimeOnlyConfigurationName)
.extendsFrom(project.configurations.getByName(testSourceSet.runtimeClasspathConfigurationName))
.extendsFrom(project.configurations.getByName(testSourceSet.runtimeOnlyConfigurationName))

project.configurations.getByName(integrationSourceSet.compileOnlyConfigurationName)
.extendsFrom(project.configurations.getByName(testSourceSet.compileOnlyConfigurationName))

project.configurations.getByName(integrationSourceSet.annotationProcessorConfigurationName)
.extendsFrom(project.configurations.getByName(testSourceSet.annotationProcessorConfigurationName))
Expand Down

0 comments on commit 5b31ee0

Please sign in to comment.