Skip to content

Commit e43bcb1

Browse files
committed
Add more cases
1 parent ffc0064 commit e43bcb1

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ import org.gradle.api.file.FileCopyDetails
1818
import org.junit.jupiter.api.Test
1919
import org.junit.jupiter.api.io.TempDir
2020

21+
/**
22+
* The cases reflect the cases in
23+
* [com.github.jengelman.gradle.plugins.shadow.relocation.RelocatorsTest], but operate on the
24+
* bytecode level to verify that the remapper correctly transforms class names in all relevant
25+
* bytecode structures.
26+
*/
2127
class RelocatorRemapperTest {
2228
@TempDir lateinit var tempDir: Path
2329

@@ -102,6 +108,51 @@ class RelocatorRemapperTest {
102108
.contains($$"Lcom/example/relocated/RelocatorRemapperTest$FixtureAnnotation;")
103109
}
104110

111+
@Test
112+
fun remapArrayFieldDescriptorIsRelocated() {
113+
val details = FixtureSubject::class.toFileCopyDetails()
114+
115+
val result = details.remapClass(relocators)
116+
117+
val classModel = ClassFile.of().parse(result)
118+
val fieldDescriptors = classModel.fields().map { it.fieldType().stringValue() }
119+
assertThat(fieldDescriptors).contains("[L$relocatedFixtureBase;")
120+
}
121+
122+
@Test
123+
fun remapArray2dFieldDescriptorIsRelocated() {
124+
val details = FixtureSubject::class.toFileCopyDetails()
125+
126+
val result = details.remapClass(relocators)
127+
128+
val classModel = ClassFile.of().parse(result)
129+
val fieldDescriptors = classModel.fields().map { it.fieldType().stringValue() }
130+
assertThat(fieldDescriptors).contains("[[L$relocatedFixtureBase;")
131+
}
132+
133+
@Test
134+
fun remapMethodMultipleArgsIsRelocated() {
135+
val details = FixtureSubject::class.toFileCopyDetails()
136+
137+
val result = details.remapClass(relocators)
138+
139+
val classModel = ClassFile.of().parse(result)
140+
val methodDescriptors = classModel.methods().map { it.methodType().stringValue() }
141+
assertThat(methodDescriptors)
142+
.contains("(L$relocatedFixtureBase;L$relocatedFixtureBase;)L$relocatedFixtureBase;")
143+
}
144+
145+
@Test
146+
fun remapMethodPrimitivePlusClassIsRelocated() {
147+
val details = FixtureSubject::class.toFileCopyDetails()
148+
149+
val result = details.remapClass(relocators)
150+
151+
val classModel = ClassFile.of().parse(result)
152+
val methodDescriptors = classModel.methods().map { it.methodType().stringValue() }
153+
assertThat(methodDescriptors).contains("(BL$relocatedFixtureBase;)L$relocatedFixtureBase;")
154+
}
155+
105156
@Test
106157
fun remapBaseClassNameIsRelocated() {
107158
// Verify relocation also works on a simple class (FixtureBase has no fields/methods
@@ -144,7 +195,13 @@ class RelocatorRemapperTest {
144195
@FixtureAnnotation
145196
class FixtureSubject : FixtureBase() {
146197
val field: FixtureBase = FixtureBase()
198+
val arrayField: Array<FixtureBase> = emptyArray()
199+
val array2dField: Array<Array<FixtureBase>> = emptyArray()
147200

148201
fun method(arg: FixtureBase): FixtureBase = arg
202+
203+
fun methodMultiArgs(a: FixtureBase, b: FixtureBase): FixtureBase = a
204+
205+
fun methodWithPrimitivePlusClass(b: Byte, arg: FixtureBase): FixtureBase = arg
149206
}
150207
}

0 commit comments

Comments
 (0)