From 529edc1fe366d268bf707d34a10b1c5e8c69e2f2 Mon Sep 17 00:00:00 2001 From: Zongle Wang Date: Tue, 28 Jan 2025 05:18:38 -0500 Subject: [PATCH] Shorten caching tests (#1211) * Tweak MinimizationCachingTest * Tweak RelocationCachingTest * Tweak ShadowJarCachingTest --- .../shadow/caching/MinimizationCachingTest.kt | 32 ++++++--------- .../shadow/caching/RelocationCachingTest.kt | 32 ++++++--------- .../shadow/caching/ShadowJarCachingTest.kt | 41 +++++++++---------- 3 files changed, 46 insertions(+), 59 deletions(-) diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/caching/MinimizationCachingTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/caching/MinimizationCachingTest.kt index 3921a87a1..98e73f91a 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/caching/MinimizationCachingTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/caching/MinimizationCachingTest.kt @@ -40,27 +40,21 @@ class MinimizationCachingTest : BaseCachingTest() { } """.trimIndent(), ) - - assertFirstExecutionSuccess() - assertThat(outputShadowJar).useAll { - containsEntries( - "server/Server.class", - "junit/framework/Test.class", - ) - doesNotContainEntries( - "client/Client.class", - ) + val assertions = { + assertThat(outputShadowJar).useAll { + containsEntries( + "server/Server.class", + "junit/framework/Test.class", + ) + doesNotContainEntries( + "client/Client.class", + ) + } } + assertFirstExecutionSuccess() + assertions() assertExecutionsAreCachedAndUpToDate() - assertThat(outputShadowJar).useAll { - containsEntries( - "server/Server.class", - "junit/framework/Test.class", - ) - doesNotContainEntries( - "client/Client.class", - ) - } + assertions() } } diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/caching/RelocationCachingTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/caching/RelocationCachingTest.kt index 43a05f563..eda6b5189 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/caching/RelocationCachingTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/caching/RelocationCachingTest.kt @@ -36,27 +36,21 @@ class RelocationCachingTest : BaseCachingTest() { } """.trimIndent(), ) - - assertFirstExecutionSuccess() - assertThat(outputShadowJar).useAll { - containsEntries( - "shadow/Main.class", - "foo/junit/framework/Test.class", - ) - doesNotContainEntries( - "junit/framework/Test.class", - ) + val assertions = { + assertThat(outputShadowJar).useAll { + containsEntries( + "shadow/Main.class", + "foo/junit/framework/Test.class", + ) + doesNotContainEntries( + "junit/framework/Test.class", + ) + } } + assertFirstExecutionSuccess() + assertions() assertExecutionsAreCachedAndUpToDate() - assertThat(outputShadowJar).useAll { - containsEntries( - "shadow/Main.class", - "foo/junit/framework/Test.class", - ) - doesNotContainEntries( - "junit/framework/Test.class", - ) - } + assertions() } } diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/caching/ShadowJarCachingTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/caching/ShadowJarCachingTest.kt index e22cafd94..c61248abc 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/caching/ShadowJarCachingTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/caching/ShadowJarCachingTest.kt @@ -27,11 +27,13 @@ class ShadowJarCachingTest : BaseCachingTest() { assertFirstExecutionSuccess() assertExecutionsAreCachedAndUpToDate() - val replaced = projectScriptPath.readText().lines().filter { - it != fromJar(projectJar) - }.joinToString(System.lineSeparator()) + val replaced = projectScriptPath.readText().lines() + .filterNot { it == fromJar(projectJar) } + .joinToString(System.lineSeparator()) projectScriptPath.writeText(replaced) + assertFirstExecutionSuccess() + assertExecutionsAreCachedAndUpToDate() } @Test @@ -45,6 +47,7 @@ class ShadowJarCachingTest : BaseCachingTest() { ) assertFirstExecutionSuccess() + assertThat(outputShadowJar).isRegular() projectScriptPath.appendText( """ @@ -53,6 +56,7 @@ class ShadowJarCachingTest : BaseCachingTest() { } """.trimIndent(), ) + assertExecutionsAreCachedAndUpToDate() assertThat(jarPath("build/libs/foo-1.0-all.jar")).isRegular() } @@ -154,6 +158,7 @@ class ShadowJarCachingTest : BaseCachingTest() { @Test fun shadowJarIsCachedCorrectlyWhenUsingDependencyIncludesExcludes() { + writeMainClass(withImports = true) projectScriptPath.appendText( """ dependencies { @@ -162,8 +167,6 @@ class ShadowJarCachingTest : BaseCachingTest() { """.trimIndent() + System.lineSeparator(), ) - writeMainClass(withImports = true) - assertFirstExecutionSuccess() assertThat(outputShadowJar).useAll { containsEntries( @@ -181,24 +184,20 @@ class ShadowJarCachingTest : BaseCachingTest() { } """.trimIndent(), ) - assertFirstExecutionSuccess() - assertThat(outputShadowJar).useAll { - containsEntries( - "shadow/Main.class", - ) - doesNotContainEntries( - "junit/framework/Test.class", - ) + val assertions = { + assertThat(outputShadowJar).useAll { + containsEntries( + "shadow/Main.class", + ) + doesNotContainEntries( + "junit/framework/Test.class", + ) + } } + assertFirstExecutionSuccess() + assertions() assertExecutionsAreCachedAndUpToDate() - assertThat(outputShadowJar).useAll { - containsEntries( - "shadow/Main.class", - ) - doesNotContainEntries( - "junit/framework/Test.class", - ) - } + assertions() } }