Skip to content

Commit 2c38f78

Browse files
committed
Actually finalize TestFramework + JUnit tests
1 parent 0721340 commit 2c38f78

File tree

19 files changed

+122
-140
lines changed

19 files changed

+122
-140
lines changed

.github/workflows/run-gametests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
path: neoforge-main/src/generated/resources
3434

3535
- name: Run Game Tests
36-
run: ./gradlew :neoforge-main:runGameTestServer
36+
run: ./gradlew :neoforge-main:test
3737
env:
3838
VERSION: ${{ inputs.version }}
3939
GITHUB_ACTOR: ${{ secrets.GITHUB_ACTOR }}

core-api/src/main/java/dev/compactmods/machines/api/CompactMachines.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
public class CompactMachines {
2323
public final static String MOD_ID = "compactmachines";
2424

25+
public static String id(String path) {
26+
return ResourceLocation.isValidPath(path) ? (MOD_ID + ":" + path) : MOD_ID + ":invalid";
27+
}
28+
2529
public static ResourceLocation modRL(String path) {
2630
return ResourceLocation.fromNamespaceAndPath(MOD_ID, path);
2731
}

neoforge-main/build.gradle.kts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ neoForge {
6060

6161
this.mods.create(modId) {
6262
modSourceSets.add(sourceSets.main)
63+
modSourceSets.add(sourceSets.test)
6364
this.dependency(coreApi)
6465
}
6566

@@ -83,12 +84,13 @@ neoForge {
8384
// jvmArgument("-XX:+AllowEnhancedClassRedefinition")
8485
}
8586

86-
additionalRuntimeClasspath.add("dev.compactmods:feather:${libraries.versions.feather.get()}")
87-
additionalRuntimeClasspath.add("com.aventrix.jnanoid:jnanoid:2.0.0")
87+
additionalRuntimeClasspath.add(libraries.feather)
88+
additionalRuntimeClasspath.add(libraries.jnanoid)
8889
}
8990

9091
create("client") {
9192
client()
93+
gameDirectory.set(file("runs/client"))
9294

9395
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
9496
systemProperty("forge.enabledGameTestNamespaces", modId)
@@ -108,17 +110,18 @@ neoForge {
108110
environment.put("CM_TEST_RESOURCES", file("src/test/resources").path)
109111

110112
sourceSet = project.sourceSets.test
111-
sourceSets.add(project.sourceSets.test.get())
113+
// sourceSets.add(project.sourceSets.test.get())
112114
}
113115

114116
create("gameTestServer") {
115117
type = "gameTestServer"
118+
gameDirectory.set(file("runs/gametest"))
116119

117120
systemProperty("forge.enabledGameTestNamespaces", modId)
118121
environment.put("CM_TEST_RESOURCES", file("src/test/resources").path)
119122

120123
sourceSet = project.sourceSets.test
121-
sourceSets.add(project.sourceSets.test.get())
124+
// sourceSets.add(project.sourceSets.test.get())
122125
}
123126
}
124127
}
@@ -170,6 +173,7 @@ dependencies {
170173
jarJar(libraries.feather) { isTransitive = false }
171174
}
172175

176+
runtimeOnly(neoforged.testframework)
173177
testImplementation(neoforged.testframework)
174178
testImplementation("org.junit.jupiter:junit-jupiter:5.7.1")
175179
testRuntimeOnly("org.junit.platform:junit-platform-launcher")

neoforge-main/src/test/java/dev/compactmods/machines/test/gametest/TestRoomApi.java renamed to neoforge-main/src/test/java/dev/compactmods/machines/test/TestRoomApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package dev.compactmods.machines.test.gametest;
1+
package dev.compactmods.machines.test;
22

33
import com.google.common.base.Predicates;
44
import dev.compactmods.machines.api.room.IRoomApi;

neoforge-main/src/test/java/dev/compactmods/machines/test/gametest/ServerEventHandler.java

Lines changed: 0 additions & 66 deletions
This file was deleted.

neoforge-main/src/test/java/dev/compactmods/machines/test/gametest/CompactGameTestHelper.java renamed to neoforge-main/src/test/java/dev/compactmods/machines/test/gametest/core/CompactGameTestHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package dev.compactmods.machines.test.gametest;
1+
package dev.compactmods.machines.test.gametest.core;
22

33
import net.minecraft.core.BlockPos;
44
import net.minecraft.core.Direction;

neoforge-main/src/test/java/dev/compactmods/machines/test/gametest/CompactMachinesTest.java renamed to neoforge-main/src/test/java/dev/compactmods/machines/test/gametest/core/CompactMachinesTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
package dev.compactmods.machines.test.gametest;
1+
package dev.compactmods.machines.test.gametest.core;
22

33
import dev.compactmods.machines.api.CompactMachines;
4+
import net.minecraft.commands.Commands;
45
import net.neoforged.bus.api.IEventBus;
56
import net.neoforged.fml.ModContainer;
67
import net.neoforged.fml.common.Mod;
@@ -13,9 +14,11 @@ public class CompactMachinesTest {
1314
public CompactMachinesTest(ModContainer container, IEventBus modBus) {
1415
final var config = FrameworkConfiguration.builder(CompactMachines.modRL("tests"))
1516
.enable(Feature.GAMETEST)
17+
.enable(Feature.MAGIC_ANNOTATIONS)
1618
.build();
1719

1820
var fw = config.create();
21+
fw.registerCommands(Commands.literal("cmtest"));
1922
fw.init(modBus, container);
2023
}
2124
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package dev.compactmods.machines.test.gametest.core;
2+
3+
import dev.compactmods.machines.api.CompactMachines;
4+
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
5+
import net.neoforged.testframework.annotation.OnInit;
6+
import net.neoforged.testframework.annotation.RegisterStructureTemplate;
7+
import net.neoforged.testframework.gametest.StructureTemplateBuilder;
8+
9+
public class EmptyTestSizes {
10+
11+
public static final String ONE_CUBED = "1x1x1";
12+
public static final String FIFTEEN_CUBED = "15x15x15";
13+
14+
@RegisterStructureTemplate(CompactMachines.MOD_ID + ":empty_1_cubed")
15+
public static final StructureTemplate empty_1 = StructureTemplateBuilder.empty(1, 1, 1);
16+
17+
@RegisterStructureTemplate(CompactMachines.MOD_ID + ":empty_15_cubed")
18+
public static final StructureTemplate empty_15 = StructureTemplateBuilder.empty(15, 15, 15);
19+
20+
@OnInit
21+
public static void init() {}
22+
}

neoforge-main/src/test/java/dev/compactmods/machines/test/gametest/data/PlayerHistoryTrackerTests.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,26 @@
55
import dev.compactmods.machines.player.PlayerEntryPointHistoryManager;
66
import dev.compactmods.machines.api.room.history.RoomEntryResult;
77
import dev.compactmods.machines.room.RoomCodeGenerator;
8-
import dev.compactmods.machines.test.gametest.TestRoomApi;
8+
import dev.compactmods.machines.test.gametest.core.EmptyTestSizes;
9+
import dev.compactmods.machines.test.TestRoomApi;
910
import net.minecraft.gametest.framework.GameTest;
1011
import net.minecraft.gametest.framework.GameTestHelper;
1112
import net.minecraft.nbt.NbtOps;
1213
import net.minecraft.world.level.GameType;
13-
import net.neoforged.neoforge.gametest.GameTestHolder;
14-
import net.neoforged.neoforge.gametest.PrefixGameTestTemplate;
14+
import net.neoforged.testframework.annotation.ForEachTest;
15+
import net.neoforged.testframework.annotation.TestHolder;
16+
import net.neoforged.testframework.gametest.EmptyTemplate;
1517

1618
import java.util.ArrayDeque;
1719
import java.util.Deque;
1820
import java.util.stream.Collectors;
1921

20-
@PrefixGameTestTemplate(false)
21-
@GameTestHolder(CompactMachines.MOD_ID)
22+
@ForEachTest(groups = "player_history_tracking")
2223
public class PlayerHistoryTrackerTests {
2324

24-
private static final String BATCH = "PLAYER_HISTORY_TRACKING";
25-
26-
@GameTest(template = "empty_1x1", batch = BATCH)
25+
@GameTest
26+
@TestHolder
27+
@EmptyTemplate(EmptyTestSizes.ONE_CUBED)
2728
public static void failsPlayerGoingTooFar(final GameTestHelper test) {
2829
CompactMachines.Internal.ROOM_API = TestRoomApi.forTest();
2930

@@ -39,7 +40,9 @@ public static void failsPlayerGoingTooFar(final GameTestHelper test) {
3940
test.succeed();
4041
}
4142

42-
@GameTest(template = "empty_1x1", batch = BATCH, timeoutTicks = 1400)
43+
@TestHolder
44+
@GameTest(timeoutTicks = 1400)
45+
@EmptyTemplate(EmptyTestSizes.ONE_CUBED)
4346
public static void canGetPlayerHistory(final GameTestHelper test) throws InterruptedException {
4447
CompactMachines.Internal.ROOM_API = TestRoomApi.forTest();
4548

@@ -68,7 +71,9 @@ public static void canGetPlayerHistory(final GameTestHelper test) throws Interru
6871
test.succeed();
6972
}
7073

71-
@GameTest(template = "empty_1x1", batch = BATCH, timeoutTicks = 1400)
74+
@TestHolder
75+
@GameTest(timeoutTicks = 1400)
76+
@EmptyTemplate(EmptyTestSizes.ONE_CUBED)
7277
public static void canRemovePlayerHistory(final GameTestHelper test) throws InterruptedException {
7378
CompactMachines.Internal.ROOM_API = TestRoomApi.forTest();
7479

@@ -95,7 +100,9 @@ public static void canRemovePlayerHistory(final GameTestHelper test) throws Inte
95100
test.succeed();
96101
}
97102

98-
@GameTest(template = "empty_1x1", batch = BATCH, timeoutTicks = 1400)
103+
@TestHolder
104+
@GameTest(timeoutTicks = 1400)
105+
@EmptyTemplate(EmptyTestSizes.ONE_CUBED)
99106
public static void testDataLogic(final GameTestHelper test) throws InterruptedException {
100107
CompactMachines.Internal.ROOM_API = TestRoomApi.forTest();
101108

neoforge-main/src/test/java/dev/compactmods/machines/test/gametest/worldgen/RoomGenerationTests.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import dev.compactmods.machines.api.room.RoomTemplate;
55
import dev.compactmods.machines.api.CompactMachines;
66
import dev.compactmods.machines.api.util.BlockSpaceUtil;
7-
import dev.compactmods.machines.test.gametest.CompactGameTestHelper;
7+
import dev.compactmods.machines.test.gametest.core.CompactGameTestHelper;
8+
import dev.compactmods.machines.test.gametest.core.EmptyTestSizes;
89
import net.minecraft.core.BlockPos;
910
import net.minecraft.core.Direction;
1011
import net.minecraft.gametest.framework.GameTest;
@@ -16,17 +17,18 @@
1617
import net.minecraft.world.level.block.Rotation;
1718
import net.minecraft.world.phys.AABB;
1819
import net.neoforged.testframework.annotation.ForEachTest;
20+
import net.neoforged.testframework.annotation.TestHolder;
21+
import net.neoforged.testframework.gametest.EmptyTemplate;
1922
import org.apache.logging.log4j.LogManager;
2023

2124
import java.util.ArrayList;
2225
import java.util.Collection;
2326
import java.util.List;
2427

25-
@ForEachTest(groups = RoomGenerationTests.BATCH)
28+
@ForEachTest(groups = "room_generation")
2629
public class RoomGenerationTests {
2730

28-
public static final String BATCH = "room_generation";
29-
31+
@TestHolder
3032
@GameTestGenerator
3133
public static Collection<TestFunction> roomTests() {
3234
List<TestFunction> funcs = new ArrayList<>();
@@ -45,7 +47,7 @@ private static void makeAndAddRoomTemplateTest(List<TestFunction> funcs, Resourc
4547
funcs.add(new TestFunction(
4648
"room_generation",
4749
"builtin_roomgen_" + id.getPath(),
48-
CompactMachines.MOD_ID + ":empty_15x15",
50+
CompactMachines.modRL("empty_15_cubed").toString(),
4951
Rotation.NONE,
5052
200,
5153
0,
@@ -65,7 +67,9 @@ private static void templateTest(CompactGameTestHelper testHelper, RoomTemplate
6567
testHelper.succeed();
6668
}
6769

68-
@GameTest(template = "empty_15x15")
70+
@TestHolder
71+
@GameTest
72+
@EmptyTemplate(EmptyTestSizes.FIFTEEN_CUBED)
6973
public static void checkOffsetsNormalTest(final CompactGameTestHelper testHelper) {
7074
final var logs = LogManager.getLogger();
7175

@@ -86,7 +90,9 @@ public static void checkOffsetsNormalTest(final CompactGameTestHelper testHelper
8690
testHelper.succeed();
8791
}
8892

89-
@GameTest(template = "empty_15x15")
93+
@TestHolder
94+
@GameTest
95+
@EmptyTemplate(EmptyTestSizes.FIFTEEN_CUBED)
9096
public static void checkRoomGeneratorNormal(final CompactGameTestHelper testHelper) {
9197

9298
AABB localBounds = testHelper.localBounds();
@@ -100,7 +106,9 @@ public static void checkRoomGeneratorNormal(final CompactGameTestHelper testHelp
100106
testHelper.succeed();
101107
}
102108

103-
@GameTest(template = "empty_15x15")
109+
@TestHolder
110+
@GameTest
111+
@EmptyTemplate(EmptyTestSizes.FIFTEEN_CUBED)
104112
public static void checkRoomGeneratorWeirdShape(final CompactGameTestHelper testHelper) {
105113

106114
AABB localBounds = testHelper.localBounds();

0 commit comments

Comments
 (0)