From c5c80b21becc51f9ab1a175280e324e37d599f3b Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Fri, 7 Jun 2024 00:03:34 -0500 Subject: [PATCH] automatic testing --- build.gradle.kts | 10 +- .../wagyourtail/gradle/shadow/ShadowJar.kt | 1 - expect-platform-test/build.gradle | 180 ---------------- expect-platform-test/build.gradle.kts | 204 ++++++++++++++++++ .../{settings.gradle => settings.gradle.kts} | 0 .../expect/ExpectPlatformExtension.kt | 10 +- .../expect/test/TestExpectPlatform.kt | 90 ++++++++ 7 files changed, 306 insertions(+), 189 deletions(-) delete mode 100644 expect-platform-test/build.gradle create mode 100644 expect-platform-test/build.gradle.kts rename expect-platform-test/{settings.gradle => settings.gradle.kts} (100%) create mode 100644 src/test/kotlin/xyz/wagyourtail/unimined/expect/test/TestExpectPlatform.kt diff --git a/build.gradle.kts b/build.gradle.kts index 19a9fa7..46d5aad 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -31,6 +31,11 @@ sourceSets.main { runtimeClasspath += shared.output } +sourceSets.test { + compileClasspath += shared.output + runtimeClasspath += shared.output +} + java { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 @@ -80,7 +85,7 @@ tasks.jar { } val annotationJar = tasks.register("annotationJar") { - archiveClassifier.set("annotations") + archiveBaseName.set("expect-platform-annotations") from(annotations.output) manifest { @@ -93,7 +98,8 @@ val annotationJar = tasks.register("annotationJar") { } val agentShadeJar = tasks.register("agentShadowJar") { - archiveClassifier.set("agent") + archiveBaseName.set("expect-platform-agent") + from(agent.output, shared.output) shadowContents.add(shade) diff --git a/buildSrc/src/main/kotlin/xyz/wagyourtail/gradle/shadow/ShadowJar.kt b/buildSrc/src/main/kotlin/xyz/wagyourtail/gradle/shadow/ShadowJar.kt index c370c45..7bd8dd8 100644 --- a/buildSrc/src/main/kotlin/xyz/wagyourtail/gradle/shadow/ShadowJar.kt +++ b/buildSrc/src/main/kotlin/xyz/wagyourtail/gradle/shadow/ShadowJar.kt @@ -25,7 +25,6 @@ abstract class ShadowJar : Jar() { shadowContents.convention(mutableListOf()).finalizeValueOnRead() relocatePackages.convention(mutableMapOf()).finalizeValueOnRead() - archiveClassifier.convention("all") } fun relocate(from: String, to: String) { diff --git a/expect-platform-test/build.gradle b/expect-platform-test/build.gradle deleted file mode 100644 index 202643a..0000000 --- a/expect-platform-test/build.gradle +++ /dev/null @@ -1,180 +0,0 @@ -import xyz.wagyourtail.unimined.expect.task.ExpectPlatformFiles -import xyz.wagyourtail.unimined.expect.task.ExpectPlatformJar - -buildscript { - repositories { - mavenCentral() - flatDir { - dirs("../build/libs") - } - } - dependencies { - classpath "xyz.wagyourtail.unimined.expect-platform:expect-platform:1.0.3" - classpath "org.ow2.asm:asm:9.7" - classpath "org.ow2.asm:asm-commons:9.7" - classpath "org.ow2.asm:asm-tree:9.7" - } -} - -plugins { - id 'java' -// id 'xyz.wagyourtail.unimined.expect-platform' -} - -apply plugin: 'xyz.wagyourtail.unimined.expect-platform' - - -sourceSets { - a { - compileClasspath += sourceSets.main.output - } - b { - compileClasspath += sourceSets.main.output - } - c { - compileClasspath += sourceSets.main.output - } -} - -repositories { - flatDir { - dirs "../build/libs" - } -} - -dependencies { - implementation(expectPlatform.annotationsDep) -} - -tasks.register("aExpectPlatform", ExpectPlatformFiles) { - platformName = "a" - inputCollection = sourceSets.main.output - - remap = [ - "xyz/wagyourtail/unimined/expect/annotation/Environment": "xyz/wagyourtail/ept/a/Env", - "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType": "xyz/wagyourtail/ept/a/Env\$EnvType", - "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType.COMBINED": "JOINED", - ] -} - -tasks.register("bExpectPlatform", ExpectPlatformFiles) { - platformName = "b" - inputCollection = sourceSets.main.output - - remap = [ - "xyz/wagyourtail/unimined/expect/annotation/Environment": "xyz/wagyourtail/ept/b/OnlyIn", - "xyz/wagyourtail/unimined/expect/annotation/Environment.value": "env", - "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType": "xyz/wagyourtail/ept/b/OnlyIn\$Type", - ] -} - -tasks.register("cExpectPlatform", ExpectPlatformFiles) { - platformName = "c" - inputCollection = sourceSets.main.output - - remap = [ - "xyz/wagyourtail/unimined/expect/annotation/Environment": "xyz/wagyourtail/ept/c/Environment", - "xyz/wagyourtail/unimined/expect/annotation/Environment.value": "type", - "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType": "xyz/wagyourtail/ept/c/Environment\$EnvType", - ] -} - -tasks.register('runA', JavaExec) { - dependsOn(tasks.aExpectPlatform) - classpath = sourceSets.a.runtimeClasspath + tasks.aExpectPlatform.outputCollection - mainClass = 'xyz.wagyourtail.ept.Main' - group = 'ept' -} - -tasks.register('runB', JavaExec) { - dependsOn(tasks.bExpectPlatform) - classpath = sourceSets.b.runtimeClasspath + tasks.bExpectPlatform.outputCollection - mainClass = 'xyz.wagyourtail.ept.Main' - group = 'ept' -} - -tasks.register('runC', JavaExec) { - dependsOn(tasks.cExpectPlatform) - classpath = sourceSets.c.runtimeClasspath + tasks.cExpectPlatform.outputCollection - mainClass = 'xyz.wagyourtail.ept.Main' - group = 'ept' -} - -tasks.register('runAgentA', JavaExec) { - classpath = sourceSets.a.runtimeClasspath + sourceSets.main.runtimeClasspath - mainClass = 'xyz.wagyourtail.ept.Main' - group = 'ept' - - expectPlatform.insertAgent(delegate, "a", [ - "xyz/wagyourtail/unimined/expect/annotation/Environment": "xyz/wagyourtail/ept/a/Env", - "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType": "xyz/wagyourtail/ept/a/Env\$EnvType", - "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType.COMBINED": "JOINED", - ]) -} - -tasks.register('runAgentB', JavaExec) { - classpath = sourceSets.b.runtimeClasspath + sourceSets.main.runtimeClasspath - mainClass = 'xyz.wagyourtail.ept.Main' - group = 'ept' - - expectPlatform.insertAgent(delegate, "b", [ - "xyz/wagyourtail/unimined/expect/annotation/Environment": "xyz/wagyourtail/ept/b/OnlyIn", - "xyz/wagyourtail/unimined/expect/annotation/Environment.value": "env", - "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType": "xyz/wagyourtail/ept/b/OnlyIn\$Type", - ]) -} - -tasks.register('runAgentC', JavaExec) { - classpath = sourceSets.c.runtimeClasspath + sourceSets.main.runtimeClasspath - mainClass = 'xyz.wagyourtail.ept.Main' - group = 'ept' - - expectPlatform.insertAgent(delegate, "c", [ - "xyz/wagyourtail/unimined/expect/annotation/Environment": "xyz/wagyourtail/ept/c/Environment", - "xyz/wagyourtail/expect/unimined/annotation/Environment.value": "type", - "xyz/wagyourtail/expect/unimined/annotation/Environment\$EnvType": "xyz/wagyourtail/ept/c/Environment\$EnvType", - ]) -} - -tasks.register('jarA', ExpectPlatformJar) { - platformName = "a" - inputFiles = sourceSets.main.output - from sourceSets.a.output - archiveFileName = "a.jar" - - remap = [ - "xyz/wagyourtail/unimined/expect/annotation/Environment": "xyz/wagyourtail/ept/a/Env", - "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType": "xyz/wagyourtail/ept/a/Env\$EnvType", - "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType.COMBINED": "JOINED", - ] -} - -tasks.register('jarB', ExpectPlatformJar) { - platformName = "b" - inputFiles = sourceSets.main.output - from sourceSets.b.output - archiveFileName = "b.jar" - - remap = [ - "xyz/wagyourtail/unimined/expect/annotation/Environment": "xyz/wagyourtail/ept/b/OnlyIn", - "xyz/wagyourtail/unimined/expect/annotation/Environment.value": "env", - "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType": "xyz/wagyourtail/ept/b/OnlyIn\$Type", - ] -} - -tasks.register('jarC', ExpectPlatformJar) { - platformName = "c" - inputFiles = sourceSets.main.output - from sourceSets.c.output - archiveFileName = "c.jar" - - remap = [ - "xyz/wagyourtail/expect/unimined/annotation/Environment": "xyz/wagyourtail/ept/c/Environment", - "xyz/wagyourtail/expect/unimined/annotation/Environment.value": "type", - "xyz/wagyourtail/expect/unimined/annotation/Environment\$EnvType": "xyz/wagyourtail/ept/c/Environment\$EnvType", - ] -} - -assemble.dependsOn(tasks.jarA) -assemble.dependsOn(tasks.jarB) -assemble.dependsOn(tasks.jarC) \ No newline at end of file diff --git a/expect-platform-test/build.gradle.kts b/expect-platform-test/build.gradle.kts new file mode 100644 index 0000000..0457b18 --- /dev/null +++ b/expect-platform-test/build.gradle.kts @@ -0,0 +1,204 @@ +@file:Suppress("DSL_SCOPE_VIOLATION") +import xyz.wagyourtail.unimined.expect.task.ExpectPlatformFiles +import xyz.wagyourtail.unimined.expect.task.ExpectPlatformJar +import xyz.wagyourtail.unimined.expect.ExpectPlatformExtension +import java.util.* + +buildscript { + repositories { + mavenCentral() + flatDir { + dirs("../build/libs") + } + } + dependencies { + + if (!project.hasProperty("runningTest")) { + classpath("xyz.wagyourtail.unimined.expect-platform:expect-platform:1.0.3") + classpath("org.ow2.asm:asm:9.7") + classpath("org.ow2.asm:asm-commons:9.7") + classpath("org.ow2.asm:asm-tree:9.7") + } + } +} + +plugins { + java + if (project.hasProperty("runningTest")) { + plugins { + id("xyz.wagyourtail.unimined.expect-platform") + } + } + +} + + +apply(plugin = "xyz.wagyourtail.unimined.expect-platform") + + +sourceSets { + create("a") { + compileClasspath += sourceSets.main.get().output + } + create("b") { + compileClasspath += sourceSets.main.get().output + } + create("c") { + compileClasspath += sourceSets.main.get().output + } +} + +repositories { + flatDir { + dirs("../build/libs") + } +} + +val expectPlatform = project.extensions.getByType(ExpectPlatformExtension::class) +expectPlatform.version = run { + projectDir.parentFile.resolve("gradle.properties").inputStream().use { + val props = Properties() + props.load(it) + props.getProperty("version") as String + } +} + +dependencies { + implementation(expectPlatform.annotationsDep) +} + +val aExpectPlatform by tasks.registering(ExpectPlatformFiles::class) { + platformName = "a" + inputCollection = sourceSets.main.get().output + + remap = mapOf( + "xyz/wagyourtail/unimined/expect/annotation/Environment" to "xyz/wagyourtail/ept/a/Env", + "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType" to "xyz/wagyourtail/ept/a/Env\$EnvType", + "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType.COMBINED" to "JOINED", + ) +} + +val bExpectPlatform by tasks.registering(ExpectPlatformFiles::class) { + platformName = "b" + inputCollection = sourceSets.main.get().output + + remap = mapOf( + "xyz/wagyourtail/unimined/expect/annotation/Environment" to "xyz/wagyourtail/ept/b/OnlyIn", + "xyz/wagyourtail/unimined/expect/annotation/Environment.value" to "env", + "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType" to "xyz/wagyourtail/ept/b/OnlyIn\$Type", + ) +} + +val cExpectPlatform by tasks.registering(ExpectPlatformFiles::class) { + platformName = "c" + inputCollection = sourceSets.main.get().output + + remap = mapOf( + "xyz/wagyourtail/unimined/expect/annotation/Environment" to "xyz/wagyourtail/ept/c/Environment", + "xyz/wagyourtail/unimined/expect/annotation/Environment.value" to "type", + "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType" to "xyz/wagyourtail/ept/c/Environment\$EnvType", + ) +} + +tasks.register("runA", JavaExec::class) { + dependsOn(aExpectPlatform) + classpath = sourceSets["a"].runtimeClasspath + aExpectPlatform.get().outputCollection + mainClass = "xyz.wagyourtail.ept.Main" + group = "ept" +} + +tasks.register("runB", JavaExec::class) { + dependsOn(bExpectPlatform) + classpath = sourceSets["b"].runtimeClasspath + bExpectPlatform.get().outputCollection + mainClass = "xyz.wagyourtail.ept.Main" + group = "ept" +} + +tasks.register("runC", JavaExec::class) { + dependsOn(cExpectPlatform) + classpath = sourceSets["c"].runtimeClasspath + cExpectPlatform.get().outputCollection + mainClass = "xyz.wagyourtail.ept.Main" + group = "ept" +} + +tasks.register("runAgentA", JavaExec::class) { + classpath = sourceSets["a"].runtimeClasspath + sourceSets.main.get().runtimeClasspath + mainClass = "xyz.wagyourtail.ept.Main" + group = "ept" + + expectPlatform.insertAgent(this, "a", mapOf( + "xyz/wagyourtail/unimined/expect/annotation/Environment" to "xyz/wagyourtail/ept/a/Env", + "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType" to "xyz/wagyourtail/ept/a/Env\$EnvType", + "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType.COMBINED" to "JOINED", + )) +} + +tasks.register("runAgentB", JavaExec::class) { + classpath = sourceSets["b"].runtimeClasspath + sourceSets.main.get().runtimeClasspath + mainClass = "xyz.wagyourtail.ept.Main" + group = "ept" + + expectPlatform.insertAgent(this, "b", mapOf( + "xyz/wagyourtail/unimined/expect/annotation/Environment" to "xyz/wagyourtail/ept/b/OnlyIn", + "xyz/wagyourtail/unimined/expect/annotation/Environment.value" to "env", + "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType" to "xyz/wagyourtail/ept/b/OnlyIn\$Type", + )) +} + +tasks.register("runAgentC", JavaExec::class) { + classpath = sourceSets["c"].runtimeClasspath + sourceSets.main.get().runtimeClasspath + mainClass = "xyz.wagyourtail.ept.Main" + group = "ept" + + expectPlatform.insertAgent(this, "c", mapOf( + "xyz/wagyourtail/unimined/expect/annotation/Environment" to "xyz/wagyourtail/ept/c/Environment", + "xyz/wagyourtail/expect/unimined/annotation/Environment.value" to "type", + "xyz/wagyourtail/expect/unimined/annotation/Environment\$EnvType" to "xyz/wagyourtail/ept/c/Environment\$EnvType", + )) +} + +val jarA by tasks.registering(ExpectPlatformJar::class) { + platformName = "a" + inputFiles = sourceSets.main.get().output + from(sourceSets["a"].output) + archiveFileName = "a.jar" + + remap = mapOf( + "xyz/wagyourtail/unimined/expect/annotation/Environment" to "xyz/wagyourtail/ept/a/Env", + "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType" to "xyz/wagyourtail/ept/a/Env\$EnvType", + "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType.COMBINED" to "JOINED", + ) +} + +val jarB by tasks.registering(ExpectPlatformJar::class) { + platformName = "b" + inputFiles = sourceSets.main.get().output + from(sourceSets["b"].output) + archiveFileName = "b.jar" + + remap = mapOf( + "xyz/wagyourtail/unimined/expect/annotation/Environment" to "xyz/wagyourtail/ept/b/OnlyIn", + "xyz/wagyourtail/unimined/expect/annotation/Environment.value" to "env", + "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType" to "xyz/wagyourtail/ept/b/OnlyIn\$Type", + ) +} + +val jarC by tasks.registering(ExpectPlatformJar::class) { + platformName = "c" + inputFiles = sourceSets.main.get().output + from(sourceSets["c"].output) + archiveFileName = "c.jar" + + remap = mapOf( + "xyz/wagyourtail/expect/unimined/annotation/Environment" to "xyz/wagyourtail/ept/c/Environment", + "xyz/wagyourtail/expect/unimined/annotation/Environment.value" to "type", + "xyz/wagyourtail/expect/unimined/annotation/Environment\$EnvType" to "xyz/wagyourtail/ept/c/Environment\$EnvType", + ) +} + +tasks.assemble { + dependsOn(jarA) + dependsOn(jarB) + dependsOn(jarC) + +} \ No newline at end of file diff --git a/expect-platform-test/settings.gradle b/expect-platform-test/settings.gradle.kts similarity index 100% rename from expect-platform-test/settings.gradle rename to expect-platform-test/settings.gradle.kts diff --git a/src/main/kotlin/xyz/wagyourtail/unimined/expect/ExpectPlatformExtension.kt b/src/main/kotlin/xyz/wagyourtail/unimined/expect/ExpectPlatformExtension.kt index 05a027f..1f56edd 100644 --- a/src/main/kotlin/xyz/wagyourtail/unimined/expect/ExpectPlatformExtension.kt +++ b/src/main/kotlin/xyz/wagyourtail/unimined/expect/ExpectPlatformExtension.kt @@ -3,22 +3,20 @@ package xyz.wagyourtail.unimined.expect import groovy.lang.Closure import groovy.lang.DelegatesTo import org.gradle.api.Project -import org.gradle.api.Task import org.gradle.api.artifacts.Configuration import org.gradle.api.attributes.Attribute import org.gradle.api.tasks.Internal -import org.gradle.api.tasks.JavaExec -import org.gradle.api.tasks.TaskProvider import org.gradle.process.JavaExecSpec import xyz.wagyourtail.unimined.expect.transform.ExpectPlatformParams import xyz.wagyourtail.unimined.expect.transform.ExpectPlatformTransform abstract class ExpectPlatformExtension(val project: Project) { @get:Internal - val version = ExpectPlatformExtension::class.java.`package`.implementationVersion ?: "1.0.0-SNAPSHOT" + @set:Internal + var version = ExpectPlatformExtension::class.java.`package`.implementationVersion ?: "1.0.0-SNAPSHOT" - val annotationsDep = "xyz.wagyourtail.unimined.expect-platform:expect-platform-annotations:$version" - val agentDep = "xyz.wagyourtail.unimined.expect-platform:expect-platform-agent:$version" + val annotationsDep by lazy { "xyz.wagyourtail.unimined.expect-platform:expect-platform-annotations:$version" } + val agentDep by lazy { "xyz.wagyourtail.unimined.expect-platform:expect-platform-agent:$version" } @JvmOverloads fun platform(platformName: String, configuration: Configuration, action: ExpectPlatformParams.() -> Unit = {}) { diff --git a/src/test/kotlin/xyz/wagyourtail/unimined/expect/test/TestExpectPlatform.kt b/src/test/kotlin/xyz/wagyourtail/unimined/expect/test/TestExpectPlatform.kt new file mode 100644 index 0000000..82d51b9 --- /dev/null +++ b/src/test/kotlin/xyz/wagyourtail/unimined/expect/test/TestExpectPlatform.kt @@ -0,0 +1,90 @@ +package xyz.wagyourtail.unimined.expect.test + +import org.gradle.testkit.runner.GradleRunner +import org.junit.jupiter.api.Test +import java.io.File +import java.nio.file.Paths +import java.util.* +import kotlin.io.path.inputStream + +class TestExpectPlatform { + val version = run { + Paths.get("./gradle.properties").inputStream().use { + val props = Properties() + props.load(it) + props.getProperty("asmVersion") as String + } + } + val classpath = System.getProperty("java.class.path") + + fun constructGradle() = GradleRunner.create() + .withProjectDir(File("expect-platform-test")) + .withPluginClasspath() + .withPluginClasspath(classpath.split(File.pathSeparator).map { File(it) }) + + @Test + fun build() { + + val result = constructGradle() + .withArguments("clean", "build", "--stacktrace", "-PrunningTest") + .build() + + assert(result.output.contains("BUILD SUCCESSFUL")) + + } + + @Test + fun runA() { + val result = constructGradle() + .withArguments("runA", "--stacktrace", "-PrunningTest") + .build() + + assert(result.output.contains("BUILD SUCCESSFUL")) + } + + @Test + fun runB() { + val result = constructGradle() + .withArguments("runB", "--stacktrace", "-PrunningTest") + .build() + + assert(result.output.contains("BUILD SUCCESSFUL")) + } + + @Test + fun runC() { + val result = constructGradle() + .withArguments("runC", "--stacktrace", "-PrunningTest") + .build() + + assert(result.output.contains("BUILD SUCCESSFUL")) + } + + @Test + fun runAgentA() { + val result = constructGradle() + .withArguments("runAgentA", "--stacktrace", "-PrunningTest") + .build() + + assert(result.output.contains("BUILD SUCCESSFUL")) + } + + @Test + fun runAgentB() { + val result = constructGradle() + .withArguments("runAgentB", "--stacktrace", "-PrunningTest") + .build() + + assert(result.output.contains("BUILD SUCCESSFUL")) + } + + @Test + fun runAgentC() { + val result = constructGradle() + .withArguments("runAgentC", "--stacktrace", "-PrunningTest") + .build() + + assert(result.output.contains("BUILD SUCCESSFUL")) + } + +}