Skip to content

Commit de55c7b

Browse files
committed
Fix canDisableRelocateStringConstants
1 parent f3ae60f commit de55c7b

File tree

1 file changed

+22
-31
lines changed
  • src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow

1 file changed

+22
-31
lines changed

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

Lines changed: 22 additions & 31 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,31 @@ class RelocationTest : BasePluginTest() {
643625
""".trimIndent(),
644626
)
645627

646-
run(shadowJarTask) {
647-
it.withDebug(true)
648-
}
649-
650-
val pathString = outputShadowJar.use { it.toString() }
651-
val result = runProcess("java", "-jar", pathString)
628+
run(shadowJarTask)
629+
val result = runProcess("java", "-jar", outputShadowJar.use { it.toString() })
652630

653631
assertThat(result).contains(
654632
if (skipStringLiteral) {
655-
"the value is junit.framework.Test"
633+
"junit.framework.Test"
656634
} else {
657-
"the value is foo.junit.framework.Test"
635+
"foo.junit.framework.Test"
658636
},
659637
)
660638
}
661639

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

0 commit comments

Comments
 (0)