Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
Late check and simple TestRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
melontini committed Jul 27, 2024
1 parent 11f1c88 commit 61f110a
Show file tree
Hide file tree
Showing 17 changed files with 549 additions and 368 deletions.
20 changes: 15 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
alias libs.plugins.fabric.loom
id 'maven-publish'
alias libs.plugins.spotless
}

def local = !System.getenv().containsKey("GITHUB_RUN_NUMBER")
Expand All @@ -24,15 +25,24 @@ dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation libs.fabric.loader

// Fabric API. This is technically optional, but you probably want it anyway.
def fabricModules = [
"fabric-api-base",
"fabric-lifecycle-events-v1"
]
fabricModules.each {
modImplementation include(fabricApi.module(it, project.fabric_version))
modImplementation include(fabricApi.module(it, libs.fabric.api.get().version))
}
}

spotless {
java {
removeUnusedImports()
palantirJavaFormat('2.47.0').style("GOOGLE")
trimTrailingWhitespace()
formatAnnotations()
}
}

Expand All @@ -50,13 +60,13 @@ loom {
processResources {
inputs.property "version", project.version
inputs.property "minecraft_version", project.minecraft_version
inputs.property "loader_version", project.loader_version
inputs.property "loader_version", libs.fabric.loader.get().version
filteringCharset "UTF-8"

filesMatching("fabric.mod.json") {
expand "version": project.version,
"minecraft_version": project.minecraft_version,
"loader_version": project.loader_version
"loader_version": libs.fabric.loader.get().version
}
}

Expand Down
6 changes: 1 addition & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ org.gradle.jvmargs=-Xmx1G
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.10
loader_version=0.15.10
# Mod Properties
mod_version=0.2.0
mod_version=0.3.0
maven_group=me.melontini
archives_base_name=handy-tests
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.92.1+1.20.1
7 changes: 7 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[libraries]
fabric-loader = { group = "net.fabricmc", name = "fabric-loader", version = "0.16.0" }
fabric-api = { group = "net.fabricmc.fabric-api", name = "fabric-api", version = "0.92.1+1.20.1" }

[plugins]
fabric-loom = { id = "fabric-loom", version = "1.7.2" }
spotless = { id = "com.diffplug.spotless", version = "6.25.0" }
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
153 changes: 78 additions & 75 deletions src/main/java/me/melontini/handytests/client/ClientTestContext.java
Original file line number Diff line number Diff line change
@@ -1,86 +1,89 @@
package me.melontini.handytests.client;

import me.melontini.handytests.util.TestContext;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.option.Perspective;
import static me.melontini.handytests.client.FabricClientTestHelper.submit;

import java.time.Duration;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;

import static me.melontini.handytests.client.FabricClientTestHelper.submit;
import me.melontini.handytests.util.TestContext;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.option.Perspective;

public record ClientTestContext(MinecraftClient client) implements TestContext<MinecraftClient> {

public void sendCommand(String command) {
FabricClientTestHelper.submitAndWait(client -> {
client.player.networkHandler.sendCommand(command);
return null;
});
}

public void waitForLoadingComplete() {
FabricClientTestHelper.waitForLoadingComplete();
}

public void waitForScreen(Class<? extends Screen> screenClass) {
FabricClientTestHelper.waitForScreen(screenClass);
}

public <T, S extends Screen> T executeForScreen(Class<S> screenClass, BiFunction<MinecraftClient, S, T> function) {
return FabricClientTestHelper.submitAndWait(client -> {
if (screenClass.isInstance(client.currentScreen)) {
return function.apply(client, screenClass.cast(client.currentScreen));
}
throw new IllegalStateException("Expected: %s, got: %s".formatted(screenClass.getName(), client.currentScreen != null ? client.currentScreen.getClass().getName() : "null"));
});
}

public void openGameMenu() {
FabricClientTestHelper.openGameMenu();
}

public void openInventory() {
FabricClientTestHelper.openInventory();
}

public void closeScreen() {
setScreen((client) -> null);
}

public void setScreen(Function<MinecraftClient, Screen> screenSupplier) {
FabricClientTestHelper.setScreen(screenSupplier);
}

public void takeScreenshot(String name) {
FabricClientTestHelper.takeScreenshot(name);
}

public void waitForWorldTicks(long ticks) {
FabricClientTestHelper.waitForWorldTicks(ticks);
}

public void enableDebugHud() {
FabricClientTestHelper.enableDebugHud();
}

public void setPerspective(Perspective perspective) {
FabricClientTestHelper.setPerspective(perspective);
}

@Override
public void waitFor(String what, Predicate<MinecraftClient> predicate, Duration timeout) {
FabricClientTestHelper.waitFor(what, predicate, timeout);
}

public <T> T submitAndWait(Function<MinecraftClient, T> function) {
return submit(function).join();
}

@Override
public MinecraftClient context() {
return client();
}
public void sendCommand(String command) {
FabricClientTestHelper.submitAndWait(client -> {
client.player.networkHandler.sendCommand(command);
return null;
});
}

public void waitForLoadingComplete() {
FabricClientTestHelper.waitForLoadingComplete();
}

public void waitForScreen(Class<? extends Screen> screenClass) {
FabricClientTestHelper.waitForScreen(screenClass);
}

public <T, S extends Screen> T executeForScreen(
Class<S> screenClass, BiFunction<MinecraftClient, S, T> function) {
return FabricClientTestHelper.submitAndWait(client -> {
if (screenClass.isInstance(client.currentScreen)) {
return function.apply(client, screenClass.cast(client.currentScreen));
}
throw new IllegalStateException("Expected: %s, got: %s"
.formatted(
screenClass.getName(),
client.currentScreen != null ? client.currentScreen.getClass().getName() : "null"));
});
}

public void openGameMenu() {
FabricClientTestHelper.openGameMenu();
}

public void openInventory() {
FabricClientTestHelper.openInventory();
}

public void closeScreen() {
setScreen((client) -> null);
}

public void setScreen(Function<MinecraftClient, Screen> screenSupplier) {
FabricClientTestHelper.setScreen(screenSupplier);
}

public void takeScreenshot(String name) {
FabricClientTestHelper.takeScreenshot(name);
}

public void waitForWorldTicks(long ticks) {
FabricClientTestHelper.waitForWorldTicks(ticks);
}

public void enableDebugHud() {
FabricClientTestHelper.enableDebugHud();
}

public void setPerspective(Perspective perspective) {
FabricClientTestHelper.setPerspective(perspective);
}

@Override
public void waitFor(String what, Predicate<MinecraftClient> predicate, Duration timeout) {
FabricClientTestHelper.waitFor(what, predicate, timeout);
}

public <T> T submitAndWait(Function<MinecraftClient, T> function) {
return submit(function).join();
}

@Override
public MinecraftClient context() {
return client();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package me.melontini.handytests.client;

public interface ClientTestEntrypoint {
void onClientTest(ClientTestContext context);
default void onClientTest(ClientTestContext context) {
context.runAllForEntrypoint(this);
}
}
Loading

0 comments on commit 61f110a

Please sign in to comment.