9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-21 16:09:19 +00:00

Add Leaf JUnit test suite

This commit is contained in:
Dreeam
2025-07-12 16:03:27 +08:00
parent af39f5cf5f
commit abb8b1fda4
54 changed files with 134 additions and 5 deletions

View File

@@ -234,7 +234,7 @@
doFirst { doFirst {
workingDir.mkdirs() workingDir.mkdirs()
@@ -391,3 +_,62 @@ @@ -391,3 +_,78 @@
} }
} }
} }
@@ -297,3 +297,19 @@
+ } + }
+} +}
+// Gale end - branding changes - package license into jar +// Gale end - branding changes - package license into jar
+
+// Leaf start - Leaf JUnit test suite
+tasks.register<Test>("runLeafTests") {
+ group = LifecycleBasePlugin.VERIFICATION_GROUP
+ include("**/LeafTestSuite.class")
+ workingDir = temporaryDir
+ useJUnitPlatform {
+ forkEvery = 1
+ }
+
+ // Configure mockito agent that is needed in newer java versions
+ val provider = objects.newInstance<MockitoAgentProvider>()
+ provider.fileCollection.from(mockitoAgent)
+ jvmArgumentProviders.add(provider)
+}
+// Leaf end - Leaf JUnit test suite

View File

@@ -0,0 +1,111 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Sat, 12 Jul 2025 15:33:40 +0800
Subject: [PATCH] Leaf JUnit test suite
diff --git a/src/test/java/org/bukkit/support/environment/LeafTest.java b/src/test/java/org/bukkit/support/environment/LeafTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..d8741167ee7003265540bb3010eb7b9587a181ce
--- /dev/null
+++ b/src/test/java/org/bukkit/support/environment/LeafTest.java
@@ -0,0 +1,22 @@
+package org.bukkit.support.environment;
+
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.bukkit.support.extension.LeafExtension;
+import org.bukkit.support.extension.VanillaFeatureExtension;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Indicates that a class or method should be tested when tested Leaf JUnit tests.
+ * All Minecraft feature flags set will be used.
+ */
+@Target({ElementType.TYPE, ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Tag("LeafTest")
+@ExtendWith({LeafExtension.class})
+public @interface LeafTest {
+}
diff --git a/src/test/java/org/bukkit/support/extension/LeafExtension.java b/src/test/java/org/bukkit/support/extension/LeafExtension.java
new file mode 100644
index 0000000000000000000000000000000000000000..1b66f5fdb4af3cf1d1f01dc219577ab6b6f52f4e
--- /dev/null
+++ b/src/test/java/org/bukkit/support/extension/LeafExtension.java
@@ -0,0 +1,50 @@
+package org.bukkit.support.extension;
+
+import java.util.HashMap;
+import java.util.Map;
+import net.minecraft.world.flag.FeatureFlags;
+import org.bukkit.Bukkit;
+import org.bukkit.Keyed;
+import org.bukkit.Registry;
+import org.bukkit.Server;
+import org.bukkit.craftbukkit.CraftRegistry;
+import org.bukkit.support.DummyServerHelper;
+import org.bukkit.support.RegistryHelper;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+/**
+ * Identical with {@link org.bukkit.support.extension.AllFeaturesExtension}
+ */
+public class LeafExtension extends BaseExtension {
+
+ private static final Map<Class<? extends Keyed>, Registry<?>> realRegistries = new HashMap<>();
+
+ public LeafExtension() {
+ super("LeafTest");
+ }
+
+ public static <T extends Keyed> Registry<T> getRealRegistry(Class<T> clazz) {
+ return (Registry<T>) LeafExtension.realRegistries.get(clazz);
+ }
+
+ public static Map<Class<? extends Keyed>, Registry<?>> getRealRegistries() {
+ return LeafExtension.realRegistries;
+ }
+
+ @Override
+ public void init(ExtensionContext extensionContext) {
+ RegistryHelper.setup(FeatureFlags.REGISTRY.allFlags());
+
+ Server server = DummyServerHelper.setup();
+
+ Bukkit.setServer(server);
+
+ // Paper - Add RegistryAccess for managing registries - replaced with registry access
+
+ CraftRegistry.setMinecraftRegistry(RegistryHelper.getRegistry());
+ }
+
+ @Override
+ void runBeforeEach(ExtensionContext extensionContext) {
+ }
+}
diff --git a/src/test/java/org/bukkit/support/suite/LeafTestSuite.java b/src/test/java/org/bukkit/support/suite/LeafTestSuite.java
new file mode 100644
index 0000000000000000000000000000000000000000..28417468c8d5faeef37eeeb940f0cf9a90b7d9e8
--- /dev/null
+++ b/src/test/java/org/bukkit/support/suite/LeafTestSuite.java
@@ -0,0 +1,15 @@
+package org.bukkit.support.suite;
+
+import org.junit.platform.suite.api.ConfigurationParameter;
+import org.junit.platform.suite.api.IncludeTags;
+import org.junit.platform.suite.api.SelectPackages;
+import org.junit.platform.suite.api.Suite;
+import org.junit.platform.suite.api.SuiteDisplayName;
+
+@Suite(failIfNoTests = false)
+@SuiteDisplayName("Test suite for tests used by Leaf")
+@SelectPackages({"net.minecraft"})
+@IncludeTags("LeafTest")
+@ConfigurationParameter(key = "TestSuite", value = "LeafTest")
+public class LeafTestSuite {
+}

View File

@@ -22,10 +22,10 @@ This includes a test to ensure that the behavior is as expected and fixes the in
diff --git a/src/test/java/net/minecraft/network/VarIntLongTest.java b/src/test/java/net/minecraft/network/VarIntLongTest.java diff --git a/src/test/java/net/minecraft/network/VarIntLongTest.java b/src/test/java/net/minecraft/network/VarIntLongTest.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..bbea09ffc2180c3c62e15d7dff51f8c220425bfe index 0000000000000000000000000000000000000000..04959045a14ccdce3f836e43e270bcf3349b28bb
--- /dev/null --- /dev/null
+++ b/src/test/java/net/minecraft/network/VarIntLongTest.java +++ b/src/test/java/net/minecraft/network/VarIntLongTest.java
@@ -0,0 +1,159 @@ @@ -0,0 +1,161 @@
+// Gale - Velocity - VarInt and VarLong optimizations +// Gale - Velocity - VarInt and VarLong optimizations
+ +
+package net.minecraft.network; +package net.minecraft.network;
@@ -36,7 +36,9 @@ index 0000000000000000000000000000000000000000..bbea09ffc2180c3c62e15d7dff51f8c2
+import it.unimi.dsi.fastutil.longs.LongSet; +import it.unimi.dsi.fastutil.longs.LongSet;
+import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Test;
+import org.bukkit.support.environment.LeafTest;
+ +
+@LeafTest
+public class VarIntLongTest { +public class VarIntLongTest {
+ +
+ private static String padStringWithLeadingZeros(String string, int length) { + private static String padStringWithLeadingZeros(String string, int length) {

View File

@@ -21,7 +21,7 @@ Given that we do a lot of varint writing as well, this should provide a small pe
This includes a test to ensure that the behavior is as expected and fixes the initialization loop so that the correct results will be given. Much thanks to @octylFractal for acting as my duck while trying to figure this out. This includes a test to ensure that the behavior is as expected and fixes the initialization loop so that the correct results will be given. Much thanks to @octylFractal for acting as my duck while trying to figure this out.
diff --git a/src/test/java/net/minecraft/network/VarIntLongTest.java b/src/test/java/net/minecraft/network/VarIntLongTest.java diff --git a/src/test/java/net/minecraft/network/VarIntLongTest.java b/src/test/java/net/minecraft/network/VarIntLongTest.java
index bbea09ffc2180c3c62e15d7dff51f8c220425bfe..0c11670d8d7307307a7cd12be5d0dca40155829d 100644 index 04959045a14ccdce3f836e43e270bcf3349b28bb..96853a1db7998e68cb0404eb1c339e807cfd339e 100644
--- a/src/test/java/net/minecraft/network/VarIntLongTest.java --- a/src/test/java/net/minecraft/network/VarIntLongTest.java
+++ b/src/test/java/net/minecraft/network/VarIntLongTest.java +++ b/src/test/java/net/minecraft/network/VarIntLongTest.java
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
@@ -32,7 +32,7 @@ index bbea09ffc2180c3c62e15d7dff51f8c220425bfe..0c11670d8d7307307a7cd12be5d0dca4
import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet; import it.unimi.dsi.fastutil.ints.IntSet;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
@@ -156,4 +157,46 @@ public class VarIntLongTest { @@ -158,4 +159,46 @@ public class VarIntLongTest {
} }
// Gale end - Velocity - pre-compute VarInt and VarLong sizes // Gale end - Velocity - pre-compute VarInt and VarLong sizes