Skip to content

Commit 3d9e356

Browse files
authored
Finish functional tests migration (#1117)
* Move funcTest sources back * Reduce extra doc package in intiTest * Seems we don't need an explicit ConfigurationCacheTest anymore * Close things in tests * Simplify task outcome checks * Cleanups * Simplify assertions for JarPath * Remove the workaround for projectRoot * Tweak lint configs * Remove TODO for excludeProjectFromMinimizeShallNotExcludeTransitiveDependenciesThatAreUsedInSubproject * Simplify checks for jarPath * Create jars in temp dir * Fix deprecations * Unify classLoader resource usages * Simplify requireResourceAsText and requireResourceAsStream * Optimize closable using * Fix org.junit.jupiter.api.extension.Extension path * Assert the bat file in integrationWithApplicationPluginAndJavaToolchains * Enable --build-cache for all func tests * Optimize assertions in BaseCachingTest and remove alternateDir logic
1 parent 710e7b8 commit 3d9e356

File tree

52 files changed

+813
-914
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+813
-914
lines changed

build.gradle.kts

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
22
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
33

44
plugins {
5-
alias(libs.plugins.kotlin)
5+
alias(libs.plugins.kotlin.jvm)
66
alias(libs.plugins.android.lint)
77
alias(libs.plugins.jetbrains.bcv)
88
alias(libs.plugins.spotless)
9-
groovy // Required for Spock tests.
109
id("shadow.convention.publish")
1110
id("shadow.convention.deploy")
1211
}
@@ -30,6 +29,8 @@ kotlin {
3029

3130
lint {
3231
baseline = file("lint-baseline.xml")
32+
ignoreTestSources = true
33+
warningsAsErrors = true
3334
}
3435

3536
spotless {
@@ -54,15 +55,12 @@ val intiTestRuntimeOnly: Configuration by configurations.getting {
5455
val funcTest: SourceSet by sourceSets.creating
5556
val funcTestImplementation: Configuration by configurations.getting {
5657
extendsFrom(configurations.testImplementation.get())
57-
// TODO: this will be removed after we migrated all functional tests to Kotlin.
58-
extendsFrom(intiTestImplementation)
5958
}
6059
val funcTestRuntimeOnly: Configuration by configurations.getting {
6160
extendsFrom(configurations.testRuntimeOnly.get())
6261
}
6362

6463
gradlePlugin {
65-
testSourceSets.add(intiTest)
6664
testSourceSets.add(funcTest)
6765
}
6866

@@ -80,26 +78,14 @@ dependencies {
8078
testImplementation(libs.junit.jupiter)
8179
testImplementation(libs.assertk)
8280
testImplementation(libs.xmlunit)
83-
testImplementation(libs.apache.commonsLang)
8481
testRuntimeOnly(libs.junit.platformLauncher)
8582

86-
funcTestImplementation(libs.spock) {
87-
exclude(group = "org.codehaus.groovy")
88-
exclude(group = "org.hamcrest")
89-
}
9083
funcTestImplementation(sourceSets.main.get().output)
91-
funcTestImplementation(intiTest.output)
92-
93-
intiTestImplementation(libs.okio)
94-
intiTestImplementation(libs.apache.maven.modelBuilder)
95-
intiTestImplementation(libs.apache.maven.repositoryMetadata)
96-
// TODO: this will be removed after we migrated all functional tests to Kotlin.
97-
intiTestImplementation(sourceSets.main.get().output)
98-
intiTestImplementation(libs.moshi)
99-
intiTestImplementation(libs.moshi.kotlin)
84+
funcTestImplementation(libs.apache.maven.modelBuilder)
85+
funcTestImplementation(libs.moshi)
86+
funcTestImplementation(libs.moshi.kotlin)
10087

10188
lintChecks(libs.androidx.gradlePluginLints)
102-
lintChecks(libs.assertk.lint)
10389
}
10490

10591
val integrationTest by tasks.registering(Test::class) {
@@ -108,10 +94,6 @@ val integrationTest by tasks.registering(Test::class) {
10894
testClassesDirs = intiTest.output.classesDirs
10995
classpath = intiTest.runtimeClasspath
11096

111-
// TODO: this should be moved into functionalTest after we migrated all functional tests to Kotlin.
112-
// Required to enable `IssueExtension` for all tests.
113-
systemProperty("junit.jupiter.extensions.autodetection.enabled", true)
114-
11597
val docsDir = file("src/docs")
11698
// Add src/docs as an input directory to trigger ManualCodeSnippetTests re-run on changes.
11799
inputs.dir(docsDir)
@@ -123,6 +105,9 @@ val functionalTest by tasks.registering(Test::class) {
123105
group = LifecycleBasePlugin.VERIFICATION_GROUP
124106
testClassesDirs = funcTest.output.classesDirs
125107
classpath = funcTest.runtimeClasspath
108+
109+
// Required to enable `IssueExtension` for all tests.
110+
systemProperty("junit.jupiter.extensions.autodetection.enabled", true)
126111
}
127112

128113
tasks.check {
@@ -147,14 +132,6 @@ tasks.withType<Test>().configureEach {
147132
)
148133
}
149134

150-
tasks.whenTaskAdded {
151-
if (name == "lintAnalyzeJvmTest") {
152-
// This task often fails on Windows CI devices.
153-
enabled = !providers.systemProperty("os.name").get().startsWith("Windows") &&
154-
!providers.environmentVariable("CI").isPresent
155-
}
156-
}
157-
158135
tasks.clean {
159136
val includedBuilds = gradle.includedBuilds
160137
dependsOn(includedBuilds.map { it.task(path) })

gradle/libs.versions.toml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
[versions]
2-
maven = "3.9.9"
32
moshi = "1.15.2"
43

54
[libraries]
65
apache-ant = "org.apache.ant:ant:1.10.15"
76
apache-commonsIo = "commons-io:commons-io:2.18.0"
8-
apache-commonsLang = "org.apache.commons:commons-lang3:3.17.0"
97
apache-log4j = "org.apache.logging.log4j:log4j-core:2.24.3"
10-
apache-maven-modelBuilder = { module = "org.apache.maven:maven-model-builder", version.ref = "maven" }
11-
apache-maven-repositoryMetadata = { module = "org.apache.maven:maven-repository-metadata", version.ref = "maven" }
8+
apache-maven-modelBuilder = "org.apache.maven:maven-model-builder:3.9.9"
129
asm = "org.ow2.asm:asm-commons:9.7.1"
1310
jdependency = "org.vafer:jdependency:2.11"
1411
jdom2 = "org.jdom:jdom2:2.0.6.1"
1512
plexus-utils = "org.codehaus.plexus:plexus-utils:4.0.2"
1613
plexus-xml = "org.codehaus.plexus:plexus-xml:4.0.4"
1714
xmlunit = "org.xmlunit:xmlunit-legacy:2.10.0"
18-
okio = "com.squareup.okio:okio:3.10.2"
1915
moshi = { module = "com.squareup.moshi:moshi", version.ref = "moshi" }
2016
moshi-kotlin = { module = "com.squareup.moshi:moshi-kotlin", version.ref = "moshi" }
2117

@@ -26,18 +22,16 @@ jetbrains-dokka = "org.jetbrains.dokka:dokka-gradle-plugin:2.0.0"
2622
node = "com.github.node-gradle:gradle-node-plugin:7.1.0"
2723

2824
androidx-gradlePluginLints = "androidx.lint:lint-gradle:1.0.0-alpha03"
29-
assertk-lint = "com.jzbrooks:assertk-lint:1.4.0"
3025
# Dummy to get renovate updates, the version is used in rootProject build.gradle with spotless.
3126
ktlint = "com.pinterest.ktlint:ktlint-cli:1.5.0"
3227

33-
spock = "org.spockframework:spock-core:2.3-groovy-3.0"
3428
junit-bom = "org.junit:junit-bom:5.11.4"
3529
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter" }
3630
junit-platformLauncher = { module = "org.junit.platform:junit-platform-launcher" }
3731
assertk = "com.willowtreeapps.assertk:assertk:0.28.1"
3832

3933
[plugins]
40-
kotlin = "org.jetbrains.kotlin.jvm:2.1.0"
34+
kotlin-jvm = "org.jetbrains.kotlin.jvm:2.1.0"
4135
android-lint = "com.android.lint:8.8.0"
4236
jetbrains-bcv = "org.jetbrains.kotlinx.binary-compatibility-validator:0.17.0"
4337
spotless = "com.diffplug.spotless:7.0.1"

lint-baseline.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
108108
<location
109109
file="src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt"
110-
line="30"
110+
line="31"
111111
column="1"/>
112112
</issue>
113113

@@ -118,7 +118,7 @@
118118
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
119119
<location
120120
file="src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt"
121-
line="31"
121+
line="32"
122122
column="1"/>
123123
</issue>
124124

@@ -129,7 +129,7 @@
129129
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
130130
<location
131131
file="src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt"
132-
line="32"
132+
line="33"
133133
column="1"/>
134134
</issue>
135135

@@ -140,7 +140,7 @@
140140
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
141141
<location
142142
file="src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt"
143-
line="33"
143+
line="34"
144144
column="1"/>
145145
</issue>
146146

src/funcTest/.editorconfig

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt renamed to src/funcTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.github.jengelman.gradle.plugins.shadow
22

3+
import assertk.all
34
import assertk.assertThat
45
import assertk.assertions.contains
56
import assertk.assertions.containsAtLeast
67
import assertk.assertions.exists
78
import assertk.assertions.isEqualTo
8-
import assertk.assertions.isNotEmpty
99
import com.github.jengelman.gradle.plugins.shadow.util.containsEntries
10+
import com.github.jengelman.gradle.plugins.shadow.util.getMainAttr
11+
import com.github.jengelman.gradle.plugins.shadow.util.isRegular
1012
import kotlin.io.path.appendText
1113
import kotlin.io.path.readText
1214
import kotlin.io.path.writeText
@@ -36,23 +38,33 @@ class ApplicationTest : BasePluginTest() {
3638

3739
val result = run(runShadowTask)
3840

39-
assertThat(result.output).contains("Running application with JDK 17")
40-
assertThat(result.output).contains("TestApp: Hello World! (foo)")
41-
42-
val installedJar = jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar")
43-
assertThat(installedJar).containsEntries(
44-
"a.properties",
45-
"a2.properties",
46-
"myapp/Main.class",
41+
assertThat(result.output).contains(
42+
"Running application with JDK 17",
43+
"TestApp: Hello World! (foo)",
4744
)
48-
assertThat(installedJar.manifest.mainAttributes.getValue("Main-Class"))
49-
.isEqualTo("myapp.Main")
5045

51-
path("build/install/myapp-shadow/bin/myapp").let { startScript ->
52-
assertThat(startScript).exists()
53-
assertThat(startScript.readText()).contains("CLASSPATH=\$APP_HOME/lib/myapp-1.0-all.jar")
54-
assertThat(startScript.readText()).contains("-jar \"\\\"\$CLASSPATH\\\"\" \"\$APP_ARGS\"")
55-
assertThat(startScript.readText()).contains("exec \"\$JAVACMD\" \"\$@\"")
46+
assertThat(jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar")).useAll {
47+
containsEntries(
48+
"a.properties",
49+
"a2.properties",
50+
"myapp/Main.class",
51+
)
52+
getMainAttr("Main-Class").isEqualTo("myapp.Main")
53+
}
54+
55+
assertThat(path("build/install/myapp-shadow/bin/myapp")).all {
56+
exists()
57+
transform { it.readText() }.contains(
58+
"CLASSPATH=\$APP_HOME/lib/myapp-1.0-all.jar",
59+
"-jar \"\\\"\$CLASSPATH\\\"\" \"\$APP_ARGS\"",
60+
"exec \"\$JAVACMD\" \"\$@\"",
61+
)
62+
}
63+
assertThat(path("build/install/myapp-shadow/bin/myapp.bat")).all {
64+
exists()
65+
transform { it.readText() }.contains(
66+
"set CLASSPATH=%APP_HOME%\\lib\\myapp-1.0-all.jar",
67+
)
5668
}
5769
}
5870

@@ -71,7 +83,7 @@ class ApplicationTest : BasePluginTest() {
7183
val zip = path("build/distributions/myapp-shadow-1.0.zip")
7284
assertThat(zip).exists()
7385

74-
val entries = ZipFile(zip.toFile()).entries.toList().map { it.name }
86+
val entries = ZipFile(zip.toFile()).use { it.entries }.toList().map { it.name }
7587
assertThat(entries).containsAtLeast(
7688
"myapp-shadow-1.0/lib/myapp-1.0-all.jar",
7789
"myapp-shadow-1.0/lib/a-1.0.jar",
@@ -84,7 +96,7 @@ class ApplicationTest : BasePluginTest() {
8496

8597
run(ShadowApplicationPlugin.SHADOW_INSTALL_TASK_NAME)
8698

87-
assertThat(jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar").entries().toList()).isNotEmpty()
99+
assertThat(jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar")).isRegular()
88100
}
89101

90102
private fun prepare(

0 commit comments

Comments
 (0)