Skip to content

Commit ad4a70a

Browse files
committed
Fix canDisableRelocateStringConstants
1 parent f3ae60f commit ad4a70a

File tree

1 file changed

+21
-28
lines changed
  • src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow

1 file changed

+21
-28
lines changed

src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -585,16 +585,7 @@ class RelocationTest : BasePluginTest() {
585585

586586
@Test
587587
fun relocateStringConstantsByDefault() {
588-
writeClass {
589-
"""
590-
package my;
591-
public class Main {
592-
public static void main(String[] args) {
593-
System.out.println("junit.framework.Test");
594-
}
595-
}
596-
""".trimIndent()
597-
}
588+
writeClassWithStringRef()
598589
projectScriptPath.appendText(
599590
"""
600591
$shadowJar {
@@ -614,22 +605,13 @@ class RelocationTest : BasePluginTest() {
614605
)
615606
}
616607

608+
@Issue(
609+
"https://github.com/GradleUp/shadow/issues/232",
610+
)
617611
@ParameterizedTest
618612
@ValueSource(booleans = [false, true])
619613
fun canDisableRelocateStringConstants(skipStringLiteral: Boolean) {
620-
writeClass {
621-
"""
622-
package my;
623-
public class Main {
624-
public static final String junit = "junit.framework.Test";
625-
public static void main(String[] args) {
626-
System.out.println(getValue() + junit);
627-
}
628-
// Use this method to force the compiler to not inline the string literal.
629-
private static String getValue() { return "the value is "; }
630-
}
631-
""".trimIndent()
632-
}
614+
writeClassWithStringRef()
633615
projectScriptPath.appendText(
634616
"""
635617
$shadowJar {
@@ -643,22 +625,33 @@ class RelocationTest : BasePluginTest() {
643625
""".trimIndent(),
644626
)
645627

646-
run(shadowJarTask) {
647-
it.withDebug(true)
648-
}
628+
run(shadowJarTask)
649629

650630
val pathString = outputShadowJar.use { it.toString() }
651631
val result = runProcess("java", "-jar", pathString)
652632

653633
assertThat(result).contains(
654634
if (skipStringLiteral) {
655-
"the value is junit.framework.Test"
635+
"junit.framework.Test"
656636
} else {
657-
"the value is foo.junit.framework.Test"
637+
"foo.junit.framework.Test"
658638
},
659639
)
660640
}
661641

642+
private fun writeClassWithStringRef() {
643+
writeClass {
644+
"""
645+
package my;
646+
public class Main {
647+
public static void main(String[] args) {
648+
System.out.println("junit.framework.Test");
649+
}
650+
}
651+
""".trimIndent()
652+
}
653+
}
654+
662655
private companion object {
663656
@JvmStatic
664657
fun prefixProvider() = listOf(

0 commit comments

Comments
 (0)