Skip to content

Commit

Permalink
feature test
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniDigger committed Oct 26, 2024
1 parent 2ea397d commit 6861719
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ open class PaperExtension(objects: ObjectFactory, layout: ProjectLayout) {
val paperServerDir: DirectoryProperty = objects.dirFrom(baseTargetDir, "paper-server")
val sourcePatchDir: DirectoryProperty = objects.dirFrom(paperServerDir, "patches/sources")
val resourcePatchDir: DirectoryProperty = objects.dirFrom(paperServerDir, "patches/resources")
val featurePatchDir: DirectoryProperty = objects.dirFrom(paperServerDir, "patches/feature")
val featurePatchDir: DirectoryProperty = objects.dirFrom(paperServerDir, "patches/features")

@Suppress("MemberVisibilityCanBePrivate")
val buildDataDir: DirectoryProperty = objects.dirWithDefault(layout, "build-data")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import java.net.URL
import java.nio.file.Path
import java.nio.file.Paths
import kotlin.io.path.*
import kotlin.io.path.readText
import kotlin.io.path.writeText
import kotlin.test.Test
import kotlin.test.assertEquals
import org.gradle.testkit.runner.TaskOutcome
Expand All @@ -36,7 +38,7 @@ import org.junit.jupiter.api.io.TempDir

class FunctionalTest {

val debug = false
val debug = true

@Disabled
@Test
Expand Down Expand Up @@ -95,16 +97,18 @@ class FunctionalTest {
)

// add AT to source -> patch and AT file is updated
val sourceFile = tempDir.resolve("test-server/src/vanilla/java/Test.java")
val replacedContent = sourceFile.readText().replace(
"\"2\";",
"\"2\"; // Woo"
).replace("public String getTest2() {", "private final String getTest2() {// Paper-AT: private+f getTest2()Ljava/lang/String;")
sourceFile.writeText(replacedContent)
println("adding at to source")
modifyFile(tempDir.resolve("test-server/src/vanilla/java/Test.java")) {
it.replace(
"\"2\";",
"\"2\"; // Woo"
).replace("public String getTest2() {", "private final String getTest2() {// Paper-AT: private+f getTest2()Ljava/lang/String;")
}

Git(tempDir.resolve("test-server/src/vanilla/java")).let { git ->
git("add", ".").executeSilently()
git("commit", "--amend", "--no-edit").executeSilently()
git("commit", "--fixup", "file").executeSilently()
git("rebase", "--autosquash", "mache/main").executeSilently()
}

println("\nrunning rebuildPatches again\n")
Expand All @@ -119,6 +123,25 @@ class FunctionalTest {
tempDir.resolve("fake-patches/sources/Test.java.patch").readText()
)
assertEquals(testResource.resolve("build-data/expected.at").readText(), tempDir.resolve("build-data/fake.at").readText())

// feature patch
println("\nmodifying feature patch\n")
modifyFile(tempDir.resolve("test-server/src/vanilla/java/Test.java")) {
it.replace("wonderful feature", "amazing feature")
}

println("\nrebuilding feature patch\n")
val rebP3 = gradleRunner
.withArguments("rebuildPatches", "--stacktrace", "-Dfake=true")
.withDebug(debug)
.build()
assertEquals(rebP3.task(":rebuildPatches")?.outcome, TaskOutcome.SUCCESS)
assertEquals(
testResource.resolve("fake-patches/expected/0001-Feature.patch").readText(),
tempDir.resolve("fake-patches/features/0001-Feature.patch").readText()
)

// todo lib patches
}

@Test
Expand Down Expand Up @@ -176,4 +199,8 @@ class FunctionalTest {
).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"))
}

fun modifyFile(path: Path, action: (content: String) -> String) {
path.writeText(action.invoke(path.readText()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ paperweight {
paper {
sourcePatchDir.set(file('fake-patches/sources'))
resourcePatchDir.set(file('fake-patches/resources'))
featurePatchDir.set(file('fake-patches/feature'))
featurePatchDir.set(file('fake-patches/features'))

additionalAts.set(file('build-data/fake.at'))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MiniDigger | Martin <admin@benndorf.dev>
Date: Sun, 20 Oct 2024 09:24:36 +0200
Subject: [PATCH] Feature


diff --git a/Test.java b/Test.java
index 8bd0bab8fc2fb2f6a4459ed9f618214ec048afc4..6accbd08d129088975d63c13230eefb73bdc3fcb 100644
--- a/Test.java
+++ b/Test.java
@@ -13,4 +13,8 @@ public class Test {
private final String getTest2() {// Paper-AT: private+f getTest2()Ljava/lang/String;
return this.test + "2"; // Woo
}
+
+ public String feature() {
+ return "wonderful feature";
+ }
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
+ return this.test; // WOOOO
}

private final String getTest2() {
- private final String getTest2() {
- return this.test + "2";
+ private final String getTest2() {// Paper-AT: private+f getTest2()Ljava/lang/String;
+ return this.test + "2"; // Woo
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MiniDigger | Martin <admin@benndorf.dev>
Date: Sun, 20 Oct 2024 09:24:36 +0200
Subject: [PATCH] Feature


diff --git a/Test.java b/Test.java
index 418548ec7dd11e57f0838d1dae048b99a2669ea3..95266c0cad0b100367ca840d286b7a004b93f4ef 100644
--- a/Test.java
+++ b/Test.java
@@ -13,4 +13,8 @@ public class Test {
public String getTest2() {
return this.test + "2";
}
+
+ public String feature() {
+ return "wonderful feature";
+ }
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ abstract class RebuildFilePatches : BaseTask() {
.executionContext(InMemoryExecutionContext { it.printStackTrace() })
.build()

// mmmh, maybe add comment to base too?

val parsedInput = RestampInput.parseFrom(configuration)
val results = Restamp.run(parsedInput).allResults

Expand Down

0 comments on commit 6861719

Please sign in to comment.