-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a whole integration test setup, cleanup mache extraction
- Loading branch information
1 parent
461b228
commit 74b0cf8
Showing
32 changed files
with
413 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
paperweight-core/src/test/kotlin/io/papermc/paperweight/FunctionalTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.papermc.paperweight | ||
|
||
import io.papermc.paperweight.util.* | ||
import java.net.URL | ||
import java.nio.file.Path | ||
import java.nio.file.Paths | ||
import kotlin.io.path.* | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import org.gradle.testkit.runner.TaskOutcome | ||
import org.junit.jupiter.api.io.CleanupMode | ||
import org.junit.jupiter.api.io.TempDir | ||
|
||
class FunctionalTest { | ||
|
||
@Test | ||
fun `test simple test project`(@TempDir(cleanup = CleanupMode.ON_SUCCESS) tempDir: Path) { | ||
setupMache("fake_mache", tempDir.resolve("mache.zip")) | ||
setupMojang("fake_mojang", tempDir.resolve("fake_mojang")) | ||
|
||
val result = tempDir.copyProject("functional_test") | ||
.gradleRunner() | ||
.withArguments("applyPatches", "dependencies", ":test-server:dependencies", "--stacktrace" , "--scan") | ||
.withDebug(true) | ||
.build() | ||
|
||
assertEquals(result.task(":applyPatches")?.outcome, TaskOutcome.SUCCESS) | ||
} | ||
|
||
fun setupMache(macheName: String, target: Path) { | ||
val macheDir = Paths.get("src/test/resources/$macheName") | ||
zip(macheDir, target); | ||
} | ||
|
||
fun setupMojang(mojangName: String, target: Path) { | ||
val mojangDir = Paths.get("src/test/resources/$mojangName") | ||
mojangDir.copyRecursivelyTo(target) | ||
|
||
val serverFolder = target.resolve("server") | ||
ProcessBuilder() | ||
.directory(serverFolder) | ||
.command("javac", serverFolder.resolve("Test.java").toString()) | ||
.redirectErrorStream(true) | ||
.start() | ||
.waitFor() | ||
|
||
ProcessBuilder() | ||
.directory(serverFolder) | ||
.command("jar", "-cf", "server.jar", "Test.class", "test.json") | ||
.redirectErrorStream(true) | ||
.start() | ||
.waitFor() | ||
|
||
val versionFolder = target.resolve("bundle/META-INF/versions/fake/") | ||
versionFolder.createDirectories() | ||
serverFolder.resolve("server.jar").copyTo(versionFolder.resolve("server.jar")) | ||
|
||
val oshiFolder = target.resolve("bundle/META-INF/libraries/com/github/oshi/oshi-core/6.4.5/") | ||
oshiFolder.createDirectories() | ||
oshiFolder.resolve("oshi-core-6.4.5.jar").writeBytes(URL("https://libraries.minecraft.net/com/github/oshi/oshi-core/6.4.5/oshi-core-6.4.5.jar").readBytes()) | ||
zip(target.resolve("bundle"), target.resolve("bundle.jar")) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
paperweight-core/src/test/kotlin/io/papermc/paperweight/util.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.papermc.paperweight | ||
|
||
import java.nio.file.Path | ||
import java.nio.file.Paths | ||
import kotlin.io.path.* | ||
import org.gradle.testkit.runner.GradleRunner | ||
|
||
fun Path.copyProject(resourcesProjectName: String): ProjectFiles { | ||
Paths.get("src/test/resources/$resourcesProjectName") | ||
.copyToRecursively(this, followLinks = false) | ||
return ProjectFiles(this) | ||
} | ||
|
||
class ProjectFiles(val projectDir: Path) { | ||
val gradleProperties: Path = resolve("gradle.properties") | ||
val buildGradle: Path = resolve("build.gradle") | ||
val buildGradleKts: Path = resolve("build.gradle.kts") | ||
val settingsGradle: Path = resolve("settings.gradle") | ||
val settingsGradleKts: Path = resolve("settings.gradle.kts") | ||
|
||
fun resolve(path: String): Path = projectDir.resolve(path) | ||
|
||
fun gradleRunner(): GradleRunner = GradleRunner.create() | ||
.forwardOutput() | ||
.withPluginClasspath() | ||
.withProjectDir(projectDir.toFile()) | ||
} |
Oops, something went wrong.