Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.player.Player;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;

import java.util.Collection;
Expand All @@ -27,7 +28,7 @@ public class McGameTestRunner {
* @param playerUUID the uuid of the player.
* @param server the server to run the tests on.
*/
public static MultipleTestTracker runGameTests(UUID playerUUID, MinecraftServer server) throws ExecutionException, InterruptedException, TimeoutException {
public static @Nullable MultipleTestTracker runGameTests(UUID playerUUID, MinecraftServer server) throws ExecutionException, InterruptedException, TimeoutException {
return server.submit(() -> {
Player player = Objects.requireNonNull(server.getPlayerList().getPlayer(playerUUID));
ServerLevel level = (ServerLevel) player.level();
Expand All @@ -37,6 +38,8 @@ public static MultipleTestTracker runGameTests(UUID playerUUID, MinecraftServer
if (testFunctions.size() < McRuntimeTest.MIN_GAME_TESTS_TO_FIND) {
LOGGER.error("Failed to find the minimum amount of gametests, expected " + McRuntimeTest.MIN_GAME_TESTS_TO_FIND + ", but found " + testFunctions.size());
throw new IllegalStateException("Failed to find the minimum amount of gametests, expected " + McRuntimeTest.MIN_GAME_TESTS_TO_FIND + ", but found " + testFunctions.size());
} else if (testFunctions.isEmpty()) {
return null;
}

GameTestRegistry.forgetFailedTests();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ private void tickHook(CallbackInfo ci) throws ExecutionException, InterruptedExc
if (McRuntimeTest.RUN_GAME_TESTS) {
LOGGER.info("Running game tests...");
mcRuntimeTest$testTracker = McGameTestRunner.runGameTests(player.getUUID(), Objects.requireNonNull(singleplayerServer));
if (mcRuntimeTest$testTracker == null) {
mcRuntimeTest$testTracker = new MultipleTestTracker();
LOGGER.info("No tests found, Successfully finished.");
mcRuntime$stop();
}
} else {
LOGGER.info("Successfully finished.");
mcRuntime$stop();
Expand Down Expand Up @@ -120,8 +125,8 @@ private void tickHook(CallbackInfo ci) throws ExecutionException, InterruptedExc
private void mcRuntime$stop() {
IntegratedServer server = singleplayerServer;
if (server != null) {
this.disconnect();
server.halt(true);
this.disconnect();
}

running = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.player.Player;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;

import java.util.Collection;
Expand All @@ -27,7 +28,7 @@ public class McGameTestRunner {
* @param playerUUID the uuid of the player.
* @param server the server to run the tests on.
*/
public static MultipleTestTracker runGameTests(UUID playerUUID, MinecraftServer server) throws ExecutionException, InterruptedException, TimeoutException {
public static @Nullable MultipleTestTracker runGameTests(UUID playerUUID, MinecraftServer server) throws ExecutionException, InterruptedException, TimeoutException {
return server.submit(() -> {
Player player = Objects.requireNonNull(server.getPlayerList().getPlayer(playerUUID));
ServerLevel level = (ServerLevel) player.level();
Expand All @@ -37,6 +38,8 @@ public static MultipleTestTracker runGameTests(UUID playerUUID, MinecraftServer
if (testFunctions.size() < McRuntimeTest.MIN_GAME_TESTS_TO_FIND) {
LOGGER.error("Failed to find the minimum amount of gametests, expected " + McRuntimeTest.MIN_GAME_TESTS_TO_FIND + ", but found " + testFunctions.size());
throw new IllegalStateException("Failed to find the minimum amount of gametests, expected " + McRuntimeTest.MIN_GAME_TESTS_TO_FIND + ", but found " + testFunctions.size());
} else if (testFunctions.isEmpty()) {
return null;
}

GameTestRegistry.forgetFailedTests();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ private void tickHook(CallbackInfo ci) throws ExecutionException, InterruptedExc
if (McRuntimeTest.RUN_GAME_TESTS) {
LOGGER.info("Running game tests...");
mcRuntimeTest$testTracker = McGameTestRunner.runGameTests(player.getUUID(), Objects.requireNonNull(singleplayerServer));
if (mcRuntimeTest$testTracker == null) {
mcRuntimeTest$testTracker = new MultipleTestTracker();
LOGGER.info("No tests found, Successfully finished.");
mcRuntime$stop();
}
} else {
LOGGER.info("Successfully finished.");
mcRuntime$stop();
Expand Down Expand Up @@ -121,8 +126,8 @@ private void tickHook(CallbackInfo ci) throws ExecutionException, InterruptedExc
private void mcRuntime$stop() {
IntegratedServer server = singleplayerServer;
if (server != null) {
disconnect();
server.halt(true);
disconnect();
}

running = false;
Expand Down