Skip to content

Commit 769a25e

Browse files
committed
Add more cases
1 parent 645b50f commit 769a25e

File tree

1 file changed

+62
-3
lines changed

1 file changed

+62
-3
lines changed

src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/BytecodeRemappingTest.kt

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.github.jengelman.gradle.plugins.shadow.internal
22

33
import assertk.assertThat
44
import assertk.assertions.contains
5+
import assertk.assertions.doesNotContain
56
import assertk.assertions.isEqualTo
67
import assertk.assertions.isTrue
78
import com.github.jengelman.gradle.plugins.shadow.relocation.SimpleRelocator
@@ -19,6 +20,8 @@ import kotlin.reflect.KClass
1920
import org.gradle.api.file.FileCopyDetails
2021
import org.junit.jupiter.api.Test
2122
import org.junit.jupiter.api.io.TempDir
23+
import org.junit.jupiter.params.ParameterizedTest
24+
import org.junit.jupiter.params.provider.ValueSource
2225

2326
/**
2427
* The cases reflect the cases in
@@ -143,13 +146,15 @@ class BytecodeRemappingTest {
143146
.contains("(L$relocatedFixtureBase;L$relocatedFixtureBase;)L$relocatedFixtureBase;")
144147
}
145148

146-
@Test
147-
fun methodPrimitivePlusClassIsRelocated() {
149+
@ParameterizedTest
150+
@ValueSource(chars = ['B', 'C', 'D', 'F', 'I', 'J', 'S', 'Z'])
151+
fun primitivePlusClassMethodIsRelocated(primitiveDescriptor: Char) {
148152
val result = fixtureSubjectDetails.remapClass(relocators)
149153

150154
val classModel = ClassFile.of().parse(result)
151155
val methodDescriptors = classModel.methods().map { it.methodType().stringValue() }
152-
assertThat(methodDescriptors).contains("(BL$relocatedFixtureBase;)L$relocatedFixtureBase;")
156+
assertThat(methodDescriptors)
157+
.contains("(${primitiveDescriptor}L$relocatedFixtureBase;)L$relocatedFixtureBase;")
153158
}
154159

155160
@Test
@@ -165,6 +170,44 @@ class BytecodeRemappingTest {
165170
assertThat(stringConstants).contains("com.example.relocated.BytecodeRemappingTest\$FixtureBase")
166171
}
167172

173+
@Test
174+
fun stringConstantNotRelocatedWhenSkipEnabled() {
175+
val skipRelocators =
176+
setOf(
177+
SimpleRelocator(
178+
"com.github.jengelman.gradle.plugins.shadow.internal",
179+
"com.example.relocated",
180+
skipStringConstants = true,
181+
)
182+
)
183+
val result = fixtureSubjectDetails.remapClass(skipRelocators)
184+
185+
val classModel = ClassFile.of().parse(result)
186+
val stringConstants =
187+
classModel.constantPool().mapNotNull { entry ->
188+
if (entry is java.lang.classfile.constantpool.StringEntry) entry.stringValue() else null
189+
}
190+
assertThat(stringConstants)
191+
.doesNotContain("com.example.relocated.BytecodeRemappingTest\$FixtureBase")
192+
}
193+
194+
@Test
195+
fun multiClassDescriptorStringConstantIsRelocated() {
196+
val result = fixtureSubjectDetails.remapClass(relocators)
197+
198+
val classModel = ClassFile.of().parse(result)
199+
val stringConstants =
200+
classModel.constantPool().mapNotNull { entry ->
201+
if (entry is java.lang.classfile.constantpool.StringEntry) entry.stringValue() else null
202+
}
203+
// Verify that two adjacent class references in a single string constant are both relocated
204+
// (regression test for the issue-1403 pattern).
205+
assertThat(stringConstants)
206+
.contains(
207+
"()Lcom/example/relocated/BytecodeRemappingTest\$FixtureBase;Lcom/example/relocated/BytecodeRemappingTest\$FixtureBase;"
208+
)
209+
}
210+
168211
@Test
169212
fun interfaceIsRelocated() {
170213
val result = fixtureSubjectDetails.remapClass(relocators)
@@ -258,13 +301,29 @@ class BytecodeRemappingTest {
258301
val array2dField: Array<Array<FixtureBase>> = emptyArray()
259302
val stringConstant: String =
260303
$$"com.github.jengelman.gradle.plugins.shadow.internal.BytecodeRemappingTest$FixtureBase"
304+
val multiClassDescriptor: String =
305+
$$"()Lcom/github/jengelman/gradle/plugins/shadow/internal/BytecodeRemappingTest$FixtureBase;Lcom/github/jengelman/gradle/plugins/shadow/internal/BytecodeRemappingTest$FixtureBase;"
261306

262307
fun method(arg: FixtureBase): FixtureBase = arg
263308

264309
fun methodMultiArgs(a: FixtureBase, b: FixtureBase): FixtureBase = a
265310

266311
fun methodWithPrimitivePlusClass(b: Byte, arg: FixtureBase): FixtureBase = arg
267312

313+
fun methodWithCharPlusClass(c: Char, arg: FixtureBase): FixtureBase = arg
314+
315+
fun methodWithDoublePlusClass(d: Double, arg: FixtureBase): FixtureBase = arg
316+
317+
fun methodWithFloatPlusClass(f: Float, arg: FixtureBase): FixtureBase = arg
318+
319+
fun methodWithIntPlusClass(i: Int, arg: FixtureBase): FixtureBase = arg
320+
321+
fun methodWithLongPlusClass(l: Long, arg: FixtureBase): FixtureBase = arg
322+
323+
fun methodWithShortPlusClass(s: Short, arg: FixtureBase): FixtureBase = arg
324+
325+
fun methodWithBooleanPlusClass(z: Boolean, arg: FixtureBase): FixtureBase = arg
326+
268327
fun methodWithCheckCast(arg: Any): FixtureBase {
269328
(arg as FixtureBase).toString()
270329
return arg

0 commit comments

Comments
 (0)