Skip to content

Commit

Permalink
Merge branch 'master' into 1.21.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed Oct 23, 2024
2 parents f47e055 + f33b916 commit 7a3dbd4
Show file tree
Hide file tree
Showing 7 changed files with 503 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,15 @@ jobs:
files: |
./build/libs/*.jar
continue-on-error: true

- name: Run the mod and take screenshots
uses: modmuss50/xvfb-action@v1
with:
run: ./gradlew runEndToEndTest --stacktrace --warning-mode=fail

- name: Upload test screenshots
uses: actions/upload-artifact@v4
if: always()
with:
name: Test Screenshots
path: run/screenshots
45 changes: 45 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,51 @@ loom {
accessWidenerPath = file("src/main/resources/wurst.accesswidener")
}

configurations {
productionRuntime {
extendsFrom configurations.minecraftLibraries
extendsFrom configurations.loaderLibraries
extendsFrom configurations.minecraftRuntimeLibraries
}
}

dependencies {
productionRuntime "net.fabricmc:fabric-loader:${project.loader_version}"
productionRuntime "net.fabricmc:intermediary:${project.minecraft_version}"
}

import net.fabricmc.loom.util.Platform
tasks.register('runEndToEndTest', JavaExec) {
dependsOn remapJar, downloadAssets
classpath.from configurations.productionRuntime
mainClass = "net.fabricmc.loader.impl.launch.knot.KnotClient"
workingDir = file("run")

doFirst {
classpath.from loom.minecraftProvider.minecraftClientJar
workingDir.mkdirs()

args(
"--assetIndex", loom.minecraftProvider.versionInfo.assetIndex().fabricId(loom.minecraftProvider.minecraftVersion()),
"--assetsDir", new File(loom.files.userCache, "assets").absolutePath,
"--gameDir", workingDir.absolutePath
)

if (Platform.CURRENT.operatingSystem.isMacOS()) {
jvmArgs("-XstartOnFirstThread")
}

jvmArgs(
"-Dfabric.addMods=${configurations.modImplementation.find { it.name.contains('fabric-api') }.absolutePath}${File.pathSeparator}${remapJar.archiveFile.get().asFile.absolutePath}",
"-Dwurst.e2eTest",
"-Dfabric-tag-conventions-v2.missingTagTranslationWarning=fail",
"-Dfabric-tag-conventions-v1.legacyTagWarning=fail",
"-Dmixin.debug.verify=true",
"-Dmixin.debug.countInjections=true"
)
}
}

processResources {
inputs.property "version", project.version

Expand Down
65 changes: 65 additions & 0 deletions src/main/java/net/wurstclient/test/WurstClientTestHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2014-2024 Wurst-Imperium and contributors.
*
* This source code is subject to the terms of the GNU General Public
* License, version 3. If a copy of the GPL was not distributed with this
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
*/
package net.wurstclient.test;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.Drawable;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.resource.language.I18n;

public enum WurstClientTestHelper
{
;

public static boolean testAltManagerButton(MinecraftClient mc)
{
System.out.println("Checking AltManager button position");

if(!(mc.currentScreen instanceof TitleScreen))
throw new RuntimeException("Not on the title screen");

ButtonWidget multiplayerButton = findButton(mc, "menu.multiplayer");
ButtonWidget realmsButton = findButton(mc, "menu.online");
ButtonWidget altManagerButton = findButton(mc, "Alt Manager");

checkButtonPosition(altManagerButton, realmsButton.getRight() + 4,
multiplayerButton.getBottom() + 4);

return true;
}

private static ButtonWidget findButton(MinecraftClient mc,
String translationKey)
{
String message = I18n.translate(translationKey);

for(Drawable drawable : mc.currentScreen.drawables)
if(drawable instanceof ButtonWidget button
&& button.getMessage().getString().equals(message))
return button;

throw new RuntimeException(message + " button could not be found");
}

private static void checkButtonPosition(ButtonWidget button, int expectedX,
int expectedY)
{
String buttonName = button.getMessage().getString();

if(button.getX() != expectedX)
throw new RuntimeException(buttonName
+ " button is at the wrong X coordinate. Expected X: "
+ expectedX + ", actual X: " + button.getX());

if(button.getY() != expectedY)
throw new RuntimeException(buttonName
+ " button is at the wrong Y coordinate. Expected Y: "
+ expectedY + ", actual Y: " + button.getY());
}
}
121 changes: 121 additions & 0 deletions src/main/java/net/wurstclient/test/WurstE2ETestClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Copyright (c) 2014-2024 Wurst-Imperium and contributors.
*
* This source code is subject to the terms of the GNU General Public
* License, version 3. If a copy of the GPL was not distributed with this
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
*/
package net.wurstclient.test;

import static net.wurstclient.test.fabric.FabricClientTestHelper.*;

import java.time.Duration;

import org.spongepowered.asm.mixin.MixinEnvironment;

import net.fabricmc.api.ModInitializer;
import net.minecraft.client.gui.screen.AccessibilityOnboardingScreen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.gui.screen.world.CreateWorldScreen;
import net.minecraft.client.gui.screen.world.SelectWorldScreen;

// It would be cleaner to have this test in src/test/java, but remapping that
// into a separate testmod is a whole can of worms.
public final class WurstE2ETestClient implements ModInitializer
{
@Override
public void onInitialize()
{
if(System.getProperty("wurst.e2eTest") == null)
return;

Thread.ofVirtual().name("Wurst End-to-End Test")
.uncaughtExceptionHandler((t, e) -> {
e.printStackTrace();
System.exit(1);
}).start(this::runTest);
}

private void runTest()
{
System.out.println("Starting Wurst End-to-End Test");
waitForLoadingComplete();

if(submitAndWait(mc -> mc.options.onboardAccessibility))
{
System.out.println("Onboarding is enabled. Waiting for it");
waitForScreen(AccessibilityOnboardingScreen.class);
System.out.println("Reached onboarding screen");
clickScreenButton("gui.continue");
}

waitForScreen(TitleScreen.class);
waitForTitleScreenFade();
System.out.println("Reached title screen");
takeScreenshot("title_screen", Duration.ZERO);

submitAndWait(WurstClientTestHelper::testAltManagerButton);
// TODO: Test more of AltManager

System.out.println("Clicking singleplayer button");
clickScreenButton("menu.singleplayer");

if(submitAndWait(mc -> !mc.getLevelStorage().getLevelList().isEmpty()))
{
System.out.println("World list is not empty. Waiting for it");
waitForScreen(SelectWorldScreen.class);
System.out.println("Reached select world screen");
takeScreenshot("select_world_screen");
clickScreenButton("selectWorld.create");
}

waitForScreen(CreateWorldScreen.class);
System.out.println("Reached create world screen");

// Select creative mode
clickScreenButton("selectWorld.gameMode");
clickScreenButton("selectWorld.gameMode");
takeScreenshot("create_world_screen");

System.out.println("Creating test world");
clickScreenButton("selectWorld.create");

waitForWorldTicks(200);
System.out.println("Reached singleplayer world");
takeScreenshot("in_game", Duration.ZERO);

System.out.println("Opening debug menu");
enableDebugHud();
takeScreenshot("debug_menu");

System.out.println("Closing debug menu");
enableDebugHud();// bad name, it actually toggles

System.out.println("Checking for broken mixins");
MixinEnvironment.getCurrentEnvironment().audit();

// TODO: Test some Wurst hacks

System.out.println("Opening inventory");
openInventory();
takeScreenshot("inventory");

System.out.println("Closing inventory");
closeScreen();

// TODO: Open ClickGUI and Navigator

System.out.println("Opening game menu");
openGameMenu();
takeScreenshot("game_menu");

// TODO: Check Wurst Options

System.out.println("Returning to title screen");
clickScreenButton("menu.returnToMenu");
waitForScreen(TitleScreen.class);

System.out.println("Stopping the game");
clickScreenButton("menu.quit");
}
}
Loading

0 comments on commit 7a3dbd4

Please sign in to comment.