Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make configuration inheritance consistent with Gradle #165

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading