Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate functional tests to Kotlin and Junit part 3 #1125

Merged
merged 13 commits into from
Jan 5, 2025
Prev Previous commit
Next Next commit
Cleanups
  • Loading branch information
Goooler committed Jan 4, 2025
commit d7cbb9d37e960f34a046e12cb516a9c036cce6f6
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,25 @@ import kotlin.io.path.writeText
sealed class BaseTransformerTest : BasePluginTest() {

fun buildJarOne(
builder: AppendableJar.() -> AppendableJar = {
builder: AppendableJar.() -> Unit = {
insert(ENTRY_SERVICES_SHADE, CONTENT_ONE)
insert(ENTRY_SERVICES_FOO, "one")
},
): Path {
return buildJar("one.jar")
.builder()
.write()
return buildJar("one.jar", builder)
}

fun buildJarTwo(
builder: AppendableJar.() -> AppendableJar = {
builder: AppendableJar.() -> Unit = {
insert(ENTRY_SERVICES_SHADE, CONTENT_TWO)
insert(ENTRY_SERVICES_FOO, "two")
},
): Path {
return buildJar("two.jar")
.builder()
.write()
return buildJar("two.jar", builder)
}

fun buildJar(path: String): AppendableJar {
return AppendableJar(path(path))
inline fun buildJar(path: String, builder: AppendableJar.() -> Unit): Path {
return AppendableJar(path(path)).apply(builder).write()
}

fun writeMainClass() {
Expand Down Expand Up @@ -68,12 +64,12 @@ sealed class BaseTransformerTest : BasePluginTest() {
}

inline fun <reified T : Transformer> transform(
shadowBlock: String = "",
shadowJarBlock: String = "",
transformerBlock: String = "",
): String {
return """
$shadowJar {
$shadowBlock
$shadowJarBlock
transform(${T::class.java.name}) {
$transformerBlock
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ServiceFileTransformerTest : BaseTransformerTest() {
fun serviceResourceTransformer() {
projectScriptPath.appendText(
transform<ServiceFileTransformer>(
shadowBlock = fromJar(buildJarOne(), buildJarTwo()),
shadowJarBlock = fromJar(buildJarOne(), buildJarTwo()),
transformerBlock = """
exclude 'META-INF/services/com.acme.*'
""".trimIndent(),
Expand Down Expand Up @@ -42,7 +42,7 @@ class ServiceFileTransformerTest : BaseTransformerTest() {
}
projectScriptPath.appendText(
transform<ServiceFileTransformer>(
shadowBlock = fromJar(one, two),
shadowJarBlock = fromJar(one, two),
transformerBlock = """
path = "META-INF/foo"
""".trimIndent(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TransformersTest : BaseTransformerTest() {
}
projectScriptPath.appendText(
transform<AppendingTransformer>(
shadowBlock = fromJar(one, two),
shadowJarBlock = fromJar(one, two),
transformerBlock = """
resource = '$ENTRY_TEST_PROPERTIES'
""".trimIndent(),
Expand Down Expand Up @@ -130,29 +130,32 @@ class TransformersTest : BaseTransformerTest() {
@Test
fun appendXmlFiles() {
val propertiesXml = "properties.xml"
val xml1 = buildJar("xml1.jar")
.insert(
val xml1 = buildJar("xml1.jar") {
insert(
propertiesXml,
"""
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties version="1.0">
<entry key="key1">val1</entry>
</properties>
""".trimIndent(),
).write()
val xml2 = buildJar("xml2.jar").insert(
propertiesXml,
"""
)
}
val xml2 = buildJar("xml2.jar") {
insert(
propertiesXml,
"""
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties version="1.0">
<entry key="key2">val2</entry>
</properties>
""".trimIndent(),
).write()
""".trimIndent(),
)
}

projectScriptPath.appendText(
transform<XmlAppendingTransformer>(
shadowBlock = fromJar(xml1, xml2),
shadowJarBlock = fromJar(xml1, xml2),
transformerBlock = """
resource = "properties.xml"
""".trimIndent(),
Expand Down Expand Up @@ -245,7 +248,7 @@ class TransformersTest : BaseTransformerTest() {
}
projectScriptPath.appendText(
transform<GroovyExtensionModuleTransformer>(
shadowBlock = fromJar(one, two),
shadowJarBlock = fromJar(one, two),
),
)

Expand Down Expand Up @@ -288,7 +291,7 @@ class TransformersTest : BaseTransformerTest() {
}
projectScriptPath.appendText(
transform<GroovyExtensionModuleTransformer>(
shadowBlock = fromJar(one, two),
shadowJarBlock = fromJar(one, two),
),
)

Expand Down
Loading