Skip to content

Commit

Permalink
Improved test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzo committed Dec 3, 2023
1 parent f5d12e6 commit df6cff4
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 34 deletions.
26 changes: 7 additions & 19 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
base
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.gradle.nexusPublish)
`git-versioning`
Expand All @@ -14,31 +15,18 @@ nexusPublishing {
}

allprojects {

group = "io.github.gmazzo.codeowners"

plugins.withId("java") {

apply(plugin = "jacoco-report-aggregation")

dependencies {
"testImplementation"(libs.kotlin.test)
"testImplementation"("org.junit.jupiter:junit-jupiter-params")
}
plugins.withId("jacoco") {
val jacocoTasks = tasks.withType<JacocoReport>()

tasks.withType<Test>().configureEach {
useJUnitPlatform()
workingDir(provider { temporaryDir })
jacocoTasks.configureEach {
reports.xml.required = true
}

tasks.withType<JacocoReport>().configureEach {
reports.xml.required.set(true)
tasks.check {
dependsOn(jacocoTasks)
}

tasks.named("check") {
dependsOn(tasks.withType<JacocoReport>())
}

}

}
12 changes: 12 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ plugins {
alias(libs.plugins.kotlin.jvm)
`java-test-fixtures`
`maven-central-publish`
jacoco
}

description = "CodeOwners Library"

java.toolchain.languageVersion.set(JavaLanguageVersion.of(8))

testing.suites.withType<JvmTestSuite> {
useKotlinTest(libs.versions.kotlin)
dependencies {
implementation(platform(libs.junit.bom))
}
}

publishing.publications {
create<MavenPublication>("java") { from(components["java"]) }
}
Expand All @@ -17,3 +25,7 @@ components.named<AdhocComponentWithVariants>("java") {
withVariantsFromConfiguration(configurations.testFixturesApiElements.get()) { skip() }
withVariantsFromConfiguration(configurations.testFixturesRuntimeElements.get()) { skip() }
}

publishing.repositories {
maven(layout.buildDirectory.dir("repo")) { name = "Local" }
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import foo.Foo
import foo.bar.FooBar
import foo.bar.impl.FooBarImpl
import foo.impl.FooImpl
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.lang.reflect.Proxy
import kotlin.test.Test
import kotlin.test.assertEquals

class CodeOwnersTest {

Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ kotlin = "1.9.21"

[libraries]
jgit = "org.eclipse.jgit:org.eclipse.jgit:6.7.0.202309050840-r"
junit-bom = "org.junit:junit-bom:5.8.1"
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }

[plugins]
Expand Down
18 changes: 17 additions & 1 deletion plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
alias(libs.plugins.gradle.pluginPublish)
`java-integration-tests`
`maven-central-publish`
jacoco
}

description = "CodeOwners Gradle Plugin"
Expand All @@ -29,11 +30,22 @@ dependencies {
testImplementation(gradleKotlinDsl())
testRuntimeOnly(plugin(libs.plugins.kotlin.jvm))

pluginUnderTestImplementation(projects.core)
pluginUnderTestImplementation(plugin(libs.plugins.android))
pluginUnderTestImplementation(plugin(libs.plugins.kotlin.jvm))
}

testing.suites.withType<JvmTestSuite> {
useKotlinTest(libs.versions.kotlin)
dependencies {
implementation(platform(libs.junit.bom))
}
targets.all {
testTask {
workingDir(provider { temporaryDir })
}
}
}

gradlePlugin {
website.set("https://github.com/gmazzo/gradle-codeowners-plugin")
vcsUrl.set("https://github.com/gmazzo/gradle-codeowners-plugin")
Expand Down Expand Up @@ -61,6 +73,10 @@ buildConfig {
tasks.integrationTest {
shouldRunAfter(tasks.test)

val core = projects.core.dependencyProject
dependsOn("${core.path}:publishAllPublicationsToLocalRepository")
environment("LOCAL_REPO", core.layout.buildDirectory.dir("repo").get().asFile.toRelativeString(workingDir))

// AGP 8 requires JDK 17, and we want to be compatible with previous JDKs
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(17))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class CodeOwnersPluginITest {
withEnvironment(
mapOf(
"ANDROID_HOME" to System.getenv("ANDROID_HOME"),
"pluginsClasspath" to pluginClasspath.joinToString(separator = File.pathSeparator)
"PLUGINS_CLASSPATH" to pluginClasspath.joinToString(separator = File.pathSeparator),
"LOCAL_REPO" to System.getenv("LOCAL_REPO"),
)
)
}
Expand Down
4 changes: 2 additions & 2 deletions plugin/src/integrationTest/resources/project/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
val pluginsClasspath: String? by System.getenv().withDefault { null }
val PLUGINS_CLASSPATH: String? by System.getenv().withDefault { null }

if (pluginsClasspath == null) {
if (PLUGINS_CLASSPATH == null) {
// meant to allow open this test project as a standalone project
id("com.android.application") version "7.4.0" apply false
kotlin("jvm") version "1.7.21" apply false
Expand Down
13 changes: 4 additions & 9 deletions plugin/src/integrationTest/resources/project/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import java.io.File

val pluginsClasspath: String? by System.getenv().withDefault { null }
val PLUGINS_CLASSPATH: String? by System.getenv().withDefault { null }
val LOCAL_REPO: String? by System.getenv().withDefault { null }

if (pluginsClasspath == null) {
if (PLUGINS_CLASSPATH == null) {
// meant to allow open this test project as a standalone project
pluginManagement {
repositories {
Expand All @@ -19,13 +20,7 @@ dependencyResolutionManagement {
mavenLocal()
mavenCentral()
google()

// allows resolution of the local core dependency added by the plugin
pluginsClasspath?.split(File.pathSeparatorChar)?.let { paths ->
flatDir {
dir(paths.map { file(it).parentFile })
}
}
LOCAL_REPO?.let { maven(File(it)) }
}
}

Expand Down

0 comments on commit df6cff4

Please sign in to comment.