From 2a805bd5847082be34d61e34f620a1d4084a0ca4 Mon Sep 17 00:00:00 2001 From: Dogboy21 Date: Mon, 3 Jun 2024 12:19:34 +0200 Subject: [PATCH 1/5] Added client test for the Chat Box peripheral --- build.gradle | 1 + .../gametest/core/ClientTestEvents.java | 21 +++ .../test/APClientTestExtensions.kt | 33 ++++ .../advancedperipherals/test/ChatBoxTest.kt | 161 ++++++++++++++++++ .../test/ComponentFormattedCharSink.kt | 44 +++++ .../resources/META-INF/accesstransformer.cfg | 6 +- .../computer/tests/chatboxtest.chatbox.lua | 97 +++++++++++ .../structures/chatboxtest.chatbox.snbt | 138 +++++++++++++++ 8 files changed, 500 insertions(+), 1 deletion(-) create mode 100644 src/testMod/java/dan200/computercraft/gametest/core/ClientTestEvents.java create mode 100644 src/testMod/kotlin/de/srendi/advancedperipherals/test/APClientTestExtensions.kt create mode 100644 src/testMod/kotlin/de/srendi/advancedperipherals/test/ChatBoxTest.kt create mode 100644 src/testMod/kotlin/de/srendi/advancedperipherals/test/ComponentFormattedCharSink.kt create mode 100644 src/testMod/resources/data/advancedperipheralstest/computer/tests/chatboxtest.chatbox.lua create mode 100644 src/testMod/resources/data/advancedperipheralstest/structures/chatboxtest.chatbox.snbt diff --git a/build.gradle b/build.gradle index a24ec0d47..49a464dab 100644 --- a/build.gradle +++ b/build.gradle @@ -171,6 +171,7 @@ minecraft { property 'forge.logging.console.level', 'debug' property 'forge.enabledGameTestNamespaces', 'advancedperipherals,advancedperipheralstest' property 'advancedperipheralstest.sources', file("src/testMod/resources/data/advancedperipheralstest").absolutePath + property 'advancedperipheralstest.tags', 'common,client' args "--mixin.config=ccgametest.mixins.json" args "--mixin.config=advancedperipheralstest.mixins.json" diff --git a/src/testMod/java/dan200/computercraft/gametest/core/ClientTestEvents.java b/src/testMod/java/dan200/computercraft/gametest/core/ClientTestEvents.java new file mode 100644 index 000000000..9956894b9 --- /dev/null +++ b/src/testMod/java/dan200/computercraft/gametest/core/ClientTestEvents.java @@ -0,0 +1,21 @@ +package dan200.computercraft.gametest.core; + +import com.google.common.collect.Lists; +import net.minecraft.client.gui.components.toasts.Toast; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.client.event.ToastAddEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; + +import java.util.List; + +@Mod.EventBusSubscriber(modid = TestMod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) +public class ClientTestEvents { + public static final List toasts = Lists.newArrayList(); + + @SubscribeEvent + public static void onToast(ToastAddEvent event) { + toasts.add(event.getToast()); + } + +} diff --git a/src/testMod/kotlin/de/srendi/advancedperipherals/test/APClientTestExtensions.kt b/src/testMod/kotlin/de/srendi/advancedperipherals/test/APClientTestExtensions.kt new file mode 100644 index 000000000..985c59db5 --- /dev/null +++ b/src/testMod/kotlin/de/srendi/advancedperipherals/test/APClientTestExtensions.kt @@ -0,0 +1,33 @@ +package de.srendi.advancedperipherals.test + +import net.minecraft.client.Minecraft +import net.minecraft.gametest.framework.GameTestAssertException +import net.minecraft.gametest.framework.GameTestHelper +import net.minecraft.network.chat.Component +import java.util.function.Predicate + +fun GameTestHelper.chatContains(filter: Predicate) = Minecraft.getInstance().gui.chat.allMessages.any { filter.test(it.content) } + +fun GameTestHelper.assertChatContains(component: Component) { + if (!chatContains { it == component }) { + throw GameTestAssertException("Expected chat to contain $component") + } +} + +fun GameTestHelper.assertChatContains(filter: Predicate) { + if (!chatContains(filter)) { + throw GameTestAssertException("Expected chat to contain message matching filter") + } +} + +fun GameTestHelper.assertChatNotContains(component: Component) { + if (chatContains { it == component }) { + throw GameTestAssertException("Expected chat to not contain $component") + } +} + +fun GameTestHelper.assertChatNotContains(filter: Predicate) { + if (chatContains(filter)) { + throw GameTestAssertException("Expected chat to not contain message matching filter") + } +} \ No newline at end of file diff --git a/src/testMod/kotlin/de/srendi/advancedperipherals/test/ChatBoxTest.kt b/src/testMod/kotlin/de/srendi/advancedperipherals/test/ChatBoxTest.kt new file mode 100644 index 000000000..b112647f1 --- /dev/null +++ b/src/testMod/kotlin/de/srendi/advancedperipherals/test/ChatBoxTest.kt @@ -0,0 +1,161 @@ +package de.srendi.advancedperipherals.test + +import dan200.computercraft.gametest.api.* +import dan200.computercraft.gametest.api.Timeouts.SECOND +import dan200.computercraft.gametest.core.ClientTestEvents +import net.minecraft.ChatFormatting +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.components.toasts.SystemToast +import net.minecraft.core.BlockPos +import net.minecraft.gametest.framework.GameTestHelper +import net.minecraft.network.chat.ClickEvent +import net.minecraft.network.chat.Component +import java.util.function.BiPredicate + +@GameTestHolder +class ChatBoxTest { + + private fun getFormattedMessage(bracketColor: String, openBracket: Char, closeBracket: Char, prefix: String, message: String): Component { + return Component.literal("$bracketColor$openBracket§r") + .append(prefix) + .append("$bracketColor$closeBracket§r ") + .append( + Component.literal("Red ").withStyle(ChatFormatting.RED) + .append(Component.literal("Bold ").withStyle(ChatFormatting.BOLD).withStyle(ChatFormatting.WHITE)) + .append(Component.literal("Click ").withStyle(ChatFormatting.UNDERLINE).withStyle(ChatFormatting.WHITE) + .withStyle { it.withClickEvent(ClickEvent(ClickEvent.Action.OPEN_URL, "https://advancedperipherals.madefor.cc/")) }) + .append(Component.literal(message).withStyle(ChatFormatting.ITALIC).withStyle(ChatFormatting.AQUA)) + ) + } + + private fun getFormattedToast(bracketColor: ChatFormatting?, openBracket: Char, closeBracket: Char, prefix: String, message: String): List { + val prefixComponents = if (bracketColor != null) { + listOf( + Component.literal("$openBracket").withStyle(bracketColor), + Component.literal(prefix), + Component.literal("$closeBracket").withStyle(bracketColor), + Component.literal(" ") + ) + } else { + listOf( + Component.literal("$openBracket$prefix$closeBracket ") + ) + } + + return prefixComponents + listOf( + Component.literal("Red ").withStyle(ChatFormatting.RED), + Component.literal("Bold ").withStyle(ChatFormatting.WHITE).withStyle(ChatFormatting.BOLD), + Component.literal("Click ").withStyle(ChatFormatting.WHITE).withStyle(ChatFormatting.UNDERLINE) + .withStyle { it.withClickEvent(ClickEvent(ClickEvent.Action.OPEN_URL, "https://advancedperipherals.madefor.cc/")) }, + Component.literal(message).withStyle(ChatFormatting.AQUA).withStyle(ChatFormatting.ITALIC) + ) + } + + private fun containsToast(filter: BiPredicate>): Boolean { + return ClientTestEvents.toasts.filterIsInstance().any { + val sink = ComponentFormattedCharSink() + it.messageLines.forEachIndexed { index, line -> + line.accept(sink) + if (index < it.messageLines.size - 1) { + sink.accept(0, sink.currentStyle!!, ' '.code) + } + } + + filter.test(it.title, sink.getComponents()) + } + } + + private fun assertContainsToast(title: Component, components: List) { + if (!containsToast { toastTitle, toastComponents -> toastTitle == title && toastComponents == components }) { + throw AssertionError("Toast with title $title and components $components not found") + } + } + + private fun assertNotContainsToast(title: Component, components: List) { + if (containsToast { toastTitle, toastComponents -> toastTitle == title && toastComponents == components }) { + throw AssertionError("Toast with title $title and components $components found") + } + } + + private fun assertNotContainsToast(filter: BiPredicate>) { + if (containsToast(filter)) { + throw AssertionError("Toast matching filter found") + } + } + + @ClientGameTest(timeoutTicks = 60 * SECOND) + fun chatBox(context: GameTestHelper) = context.sequence { + thenExecute { context.positionAt(BlockPos(2, 6, 2), 90f) } + thenOnClient { + Minecraft.getInstance().gui.chat.clearMessages(false) + ClientTestEvents.toasts.clear() + } + thenComputerOk() + thenOnClient { + // sendMessage + context.assertChatContains(Component.literal("[§r").append("AP").append("]§r ").append("Default message")) + context.assertChatContains(Component.literal("[§r").append("GameTest").append("]§r ").append("Message with prefix")) + context.assertChatContains(Component.literal("<§r").append("GameTest").append(">§r ").append("Message with brackets")) + context.assertChatContains(Component.literal("§a<§r").append("GameTest").append("§a>§r ").append("Message with bracket color")) + context.assertChatNotContains(Component.literal("§a<§r").append("GameTest").append("§a>§r ").append("Message with short range")) + context.assertChatNotContains { it.toString().contains("Message with invalid brackets") } + + // sendMessageToPlayer + context.assertChatContains(Component.literal("[§r").append("AP").append("]§r ").append("Default message to player")) + context.assertChatContains(Component.literal("[§r").append("GameTest").append("]§r ").append("Message with prefix to player")) + context.assertChatContains(Component.literal("<§r").append("GameTest").append(">§r ").append("Message with brackets to player")) + context.assertChatContains(Component.literal("§a<§r").append("GameTest").append("§a>§r ").append("Message with bracket color to player")) + context.assertChatNotContains(Component.literal("§a<§r").append("GameTest").append("§a>§r ").append("Message with short range to player")) + context.assertChatNotContains { it.toString().contains("Message with invalid brackets to player") } + context.assertChatNotContains(Component.literal("[§r").append("AP").append("]§r ").append("Default message to invalid player")) + + // sendFormattedMessage + context.assertChatContains(getFormattedMessage("", '[', ']', "AP", "Default formatted message")) + context.assertChatContains(getFormattedMessage("", '[', ']', "GameTest", "Formatted message with prefix")) + context.assertChatContains(getFormattedMessage("", '<', '>', "GameTest", "Formatted message with brackets")) + context.assertChatContains(getFormattedMessage("§a", '<', '>', "GameTest", "Formatted message with bracket color")) + context.assertChatNotContains(getFormattedMessage("§a", '<', '>', "GameTest", "Formatted message with short range")) + context.assertChatNotContains { it.toString().contains("Formatted message with invalid brackets") } + + // sendFormattedMessageToPlayer + context.assertChatContains(getFormattedMessage("", '[', ']', "AP", "Default formatted message to player")) + context.assertChatContains(getFormattedMessage("", '[', ']', "GameTest", "Formatted message with prefix to player")) + context.assertChatContains(getFormattedMessage("", '<', '>', "GameTest", "Formatted message with brackets to player")) + context.assertChatContains(getFormattedMessage("§a", '<', '>', "GameTest", "Formatted message with bracket color to player")) + context.assertChatNotContains(getFormattedMessage("§a", '<', '>', "GameTest", "Formatted message with short range to player")) + context.assertChatNotContains { it.toString().contains("Formatted message with invalid brackets to player") } + context.assertChatNotContains(getFormattedMessage("", '[', ']', "AP", "Default formatted message to invalid player")) + + // sendToastToPlayer + val defaultToastTitle = Component.literal("Toast Title") + assertContainsToast(defaultToastTitle, listOf(Component.literal("[AP] Default toast to player"))) + assertContainsToast(defaultToastTitle, listOf(Component.literal("[GameTest] Toast with prefix to player"))) + assertContainsToast(defaultToastTitle, listOf(Component.literal(" Toast with brackets to player"))) + assertContainsToast(defaultToastTitle, listOf( + Component.literal("<").withStyle(ChatFormatting.GREEN), + Component.literal("GameTest"), + Component.literal(">").withStyle(ChatFormatting.GREEN), + Component.literal(" Toast with bracket color to player") + )) + assertNotContainsToast(defaultToastTitle, listOf( + Component.literal("<").withStyle(ChatFormatting.GREEN), + Component.literal("GameTest"), + Component.literal(">").withStyle(ChatFormatting.GREEN), + Component.literal(" Toast with short range to player") + )) + assertNotContainsToast { title, components -> title == defaultToastTitle && components.any { it.toString().contains("Toast with invalid brackets to player") } } + assertNotContainsToast(defaultToastTitle, listOf(Component.literal("[AP] Default toast to invalid player"))) + + // sendFormattedToastToPlayer + val formattedToastTitle = Component.literal("Formatted Toast Title").withStyle(ChatFormatting.DARK_PURPLE) + assertContainsToast(formattedToastTitle, getFormattedToast(null, '[', ']', "AP", "Default formatted toast to player")) + assertContainsToast(formattedToastTitle, getFormattedToast(null, '[', ']', "GameTest", "Formatted toast with prefix to player")) + assertContainsToast(formattedToastTitle, getFormattedToast(null, '<', '>', "GameTest", "Formatted toast with brackets to player")) + assertContainsToast(formattedToastTitle, getFormattedToast(ChatFormatting.GREEN, '<', '>', "GameTest", "Formatted toast with bracket color to player")) + assertNotContainsToast(formattedToastTitle, getFormattedToast(ChatFormatting.GREEN, '<', '>', "GameTest", "Formatted toast with short range to player")) + assertNotContainsToast { title, components -> title == formattedToastTitle && components.any { it.toString().contains("Formatted toast with invalid brackets to player") } } + assertNotContainsToast(formattedToastTitle, getFormattedToast(null, '[', ']', "AP", "Default formatted toast to invalid player")) + } + } + +} \ No newline at end of file diff --git a/src/testMod/kotlin/de/srendi/advancedperipherals/test/ComponentFormattedCharSink.kt b/src/testMod/kotlin/de/srendi/advancedperipherals/test/ComponentFormattedCharSink.kt new file mode 100644 index 000000000..bc62f38b9 --- /dev/null +++ b/src/testMod/kotlin/de/srendi/advancedperipherals/test/ComponentFormattedCharSink.kt @@ -0,0 +1,44 @@ +package de.srendi.advancedperipherals.test + +import net.minecraft.network.chat.Component +import net.minecraft.network.chat.Style +import net.minecraft.util.FormattedCharSink + +class ComponentFormattedCharSink : FormattedCharSink { + var currentStyle: Style? = null; + private var currentText: String = ""; + private val components = mutableListOf(); + + override fun accept(pPositionInCurrentSequence: Int, pStyle: Style, pCodePoint: Int): Boolean { + if (currentStyle?.equals(pStyle) == false) { + if (currentText.isNotEmpty()) { + components.add(Component.literal(currentText).withStyle(simplifyStyle(currentStyle!!))) + currentText = "" + } + } + + currentStyle = pStyle + currentText += String(Character.toChars(pCodePoint)) + + return true + } + + fun getComponents(): List{ + if (currentText.isNotEmpty()) { + components.add(Component.literal(currentText).withStyle(simplifyStyle(currentStyle!!))) + currentText = "" + } + + return components + } + + private fun simplifyStyle(style: Style): Style { + return style + .withBold(if (style.isBold) true else null) + .withItalic(if (style.isItalic) true else null) + .withUnderlined(if (style.isUnderlined) true else null) + .withStrikethrough(if (style.isStrikethrough) true else null) + .withObfuscated(if (style.isObfuscated) true else null) + } + +} \ No newline at end of file diff --git a/src/testMod/resources/META-INF/accesstransformer.cfg b/src/testMod/resources/META-INF/accesstransformer.cfg index 8fcc2e072..a8570dd52 100644 --- a/src/testMod/resources/META-INF/accesstransformer.cfg +++ b/src/testMod/resources/META-INF/accesstransformer.cfg @@ -4,4 +4,8 @@ public net.minecraft.gametest.framework.GameTestHelper m_177448_()Lnet/minecraft public net.minecraft.gametest.framework.GameTestHelper f_127595_ # testInfo public net.minecraft.gametest.framework.GameTestSequence f_127774_ # parent -public net.minecraft.gametest.framework.MultipleTestTracker f_127798_ # tests \ No newline at end of file +public net.minecraft.gametest.framework.MultipleTestTracker f_127798_ # tests + +public net.minecraft.client.gui.components.ChatComponent f_93760_ # allMessages +public net.minecraft.client.gui.components.toasts.SystemToast f_94821_ # title +public net.minecraft.client.gui.components.toasts.SystemToast f_94822_ # messageLines \ No newline at end of file diff --git a/src/testMod/resources/data/advancedperipheralstest/computer/tests/chatboxtest.chatbox.lua b/src/testMod/resources/data/advancedperipheralstest/computer/tests/chatboxtest.chatbox.lua new file mode 100644 index 000000000..6ed39caf7 --- /dev/null +++ b/src/testMod/resources/data/advancedperipheralstest/computer/tests/chatboxtest.chatbox.lua @@ -0,0 +1,97 @@ +--- +--- Advanced Peripherals Chat Box tests +--- Covers `sendMessage`, `sendMessageToPlayer`, `sendToastToPlayer`, `sendFormattedToastToPlayer`, +--- `sendFormattedMessage`, `sendFormattedMessageToPlayer` +--- + +sleep(3) + +chatBox = peripheral.find("chatBox") +test.assert(chatBox, "Peripheral not found") +config = chatBox.getConfiguration() + +function assertCooldown() + local currentCooldown = chatBox.getOperationCooldown("chatMessage") + test.assert(currentCooldown > 0 and currentCooldown <= config["chatMessage"]["cooldown"], "Cooldown should be active after a message was sent") + + while chatBox.getOperationCooldown("chatMessage") > 0 do + sleep(0.1) + end +end + +function assertSendMessage(fn, ...) + local message = arg[1] + test.assert(fn(unpack(arg)), message .. " should be sent") + assertCooldown() +end + +function assertFailedSendMessage(fn, ...) + local message = arg[1] + test.assert(not fn(unpack(arg)), message .. " should not be sent") + -- test.eq(0, chatBox.getOperationCooldown("chatMessage"), "Cooldown should not be active after a failed message") failed messages still trigger cooldown, maybe a bug? + assertCooldown() -- TODO Remove when fixed +end + +function getFormattedMessage(message) + local message = { + { text = "Red ", color = "red" }, + { text = "Bold ", color = "white", bold = true }, + { text = "Click ", underlined = true, color = "white", clickEvent = { action = "open_url", value = "https://advancedperipherals.madefor.cc/" } }, + { text = message, color = "aqua", italic = true } + } + local json = textutils.serialiseJSON(message) + return json +end + +-- Test sendMessage in different formats +assertSendMessage(chatBox.sendMessage, "Default message") +assertSendMessage(chatBox.sendMessage, "Message with prefix", "GameTest") +assertSendMessage(chatBox.sendMessage, "Message with brackets", "GameTest", "<>") +assertSendMessage(chatBox.sendMessage, "Message with bracket color", "GameTest", "<>", "&a") +assertSendMessage(chatBox.sendMessage, "Message with short range", "GameTest", "<>", "&a", 3) +assertFailedSendMessage(chatBox.sendMessage, "Message with invalid brackets", "GameTest", "<") + +-- Test sendMessageToPlayer in different formats +assertSendMessage(chatBox.sendMessageToPlayer, "Default message to player", "Dev") +assertSendMessage(chatBox.sendMessageToPlayer, "Message with prefix to player", "Dev", "GameTest") +assertSendMessage(chatBox.sendMessageToPlayer, "Message with brackets to player", "Dev", "GameTest", "<>") +assertSendMessage(chatBox.sendMessageToPlayer, "Message with bracket color to player", "Dev", "GameTest", "<>", "&a") +assertSendMessage(chatBox.sendMessageToPlayer, "Message with short range to player", "Dev", "GameTest", "<>", "&a", 3) +assertFailedSendMessage(chatBox.sendMessageToPlayer, "Message with invalid brackets to player", "Dev", "GameTest", "<") +assertFailedSendMessage(chatBox.sendMessageToPlayer, "Default message to invalid player", "InvalidPlayer") + +-- Test sendFormattedMessage in different formats +assertSendMessage(chatBox.sendFormattedMessage, getFormattedMessage("Default formatted message")) +assertSendMessage(chatBox.sendFormattedMessage, getFormattedMessage("Formatted message with prefix"), "GameTest") +assertSendMessage(chatBox.sendFormattedMessage, getFormattedMessage("Formatted message with brackets"), "GameTest", "<>") +assertSendMessage(chatBox.sendFormattedMessage, getFormattedMessage("Formatted message with bracket color"), "GameTest", "<>", "&a") +assertSendMessage(chatBox.sendFormattedMessage, getFormattedMessage("Formatted message with short range"), "GameTest", "<>", "&a", 3) +assertFailedSendMessage(chatBox.sendFormattedMessage, getFormattedMessage("Formatted message with invalid brackets"), "GameTest", "<") + +-- Test sendFormattedMessageToPlayer in different formats +assertSendMessage(chatBox.sendFormattedMessageToPlayer, getFormattedMessage("Default formatted message to player"), "Dev") +assertSendMessage(chatBox.sendFormattedMessageToPlayer, getFormattedMessage("Formatted message with prefix to player"), "Dev", "GameTest") +assertSendMessage(chatBox.sendFormattedMessageToPlayer, getFormattedMessage("Formatted message with brackets to player"), "Dev", "GameTest", "<>") +assertSendMessage(chatBox.sendFormattedMessageToPlayer, getFormattedMessage("Formatted message with bracket color to player"), "Dev", "GameTest", "<>", "&a") +assertSendMessage(chatBox.sendFormattedMessageToPlayer, getFormattedMessage("Formatted message with short range to player"), "Dev", "GameTest", "<>", "&a", 3) +assertFailedSendMessage(chatBox.sendFormattedMessageToPlayer, getFormattedMessage("Formatted message with invalid brackets to player"), "Dev", "GameTest", "<") +assertFailedSendMessage(chatBox.sendFormattedMessageToPlayer, getFormattedMessage("Default formatted message to invalid player"), "InvalidPlayer") + +-- Test sendToastToPlayer in different formats +assertSendMessage(chatBox.sendToastToPlayer, "Default toast to player", "Toast Title", "Dev") +assertSendMessage(chatBox.sendToastToPlayer, "Toast with prefix to player", "Toast Title", "Dev", "GameTest") +assertSendMessage(chatBox.sendToastToPlayer, "Toast with brackets to player", "Toast Title", "Dev", "GameTest", "<>") +assertSendMessage(chatBox.sendToastToPlayer, "Toast with bracket color to player", "Toast Title", "Dev", "GameTest", "<>", "&a") +assertSendMessage(chatBox.sendToastToPlayer, "Toast with short range to player", "Toast Title", "Dev", "GameTest", "<>", "&a", 3) +assertFailedSendMessage(chatBox.sendToastToPlayer, "Toast with invalid brackets to player", "Toast Title", "Dev", "GameTest", "<") +assertFailedSendMessage(chatBox.sendToastToPlayer, "Default toast to invalid player", "Toast Title", "InvalidPlayer") + +-- Test sendFormattedToastToPlayer in different formats +formattedToastTitle = textutils.serialiseJSON({ { text = "Formatted Toast Title", color = "dark_purple" } }) +assertSendMessage(chatBox.sendFormattedToastToPlayer, getFormattedMessage("Default formatted toast to player"), formattedToastTitle, "Dev") +assertSendMessage(chatBox.sendFormattedToastToPlayer, getFormattedMessage("Formatted toast with prefix to player"), formattedToastTitle, "Dev", "GameTest") +assertSendMessage(chatBox.sendFormattedToastToPlayer, getFormattedMessage("Formatted toast with brackets to player"), formattedToastTitle, "Dev", "GameTest", "<>") +assertSendMessage(chatBox.sendFormattedToastToPlayer, getFormattedMessage("Formatted toast with bracket color to player"), formattedToastTitle, "Dev", "GameTest", "<>", "&a") +assertSendMessage(chatBox.sendFormattedToastToPlayer, getFormattedMessage("Formatted toast with short range to player"),formattedToastTitle, "Dev", "GameTest", "<>", "&a", 3) +assertFailedSendMessage(chatBox.sendFormattedToastToPlayer, getFormattedMessage("Formatted toast with invalid brackets to player"), formattedToastTitle, "Dev", "GameTest", "<") +assertFailedSendMessage(chatBox.sendFormattedToastToPlayer, getFormattedMessage("Default formatted toast to invalid player"), formattedToastTitle, "InvalidPlayer") diff --git a/src/testMod/resources/data/advancedperipheralstest/structures/chatboxtest.chatbox.snbt b/src/testMod/resources/data/advancedperipheralstest/structures/chatboxtest.chatbox.snbt new file mode 100644 index 000000000..b9dde7cfa --- /dev/null +++ b/src/testMod/resources/data/advancedperipheralstest/structures/chatboxtest.chatbox.snbt @@ -0,0 +1,138 @@ +{ + DataVersion: 3120, + size: [5, 5, 5], + data: [ + {pos: [0, 0, 0], state: "minecraft:polished_andesite"}, + {pos: [0, 0, 1], state: "minecraft:polished_andesite"}, + {pos: [0, 0, 2], state: "minecraft:polished_andesite"}, + {pos: [0, 0, 3], state: "minecraft:polished_andesite"}, + {pos: [0, 0, 4], state: "minecraft:polished_andesite"}, + {pos: [1, 0, 0], state: "minecraft:polished_andesite"}, + {pos: [1, 0, 1], state: "minecraft:polished_andesite"}, + {pos: [1, 0, 2], state: "minecraft:polished_andesite"}, + {pos: [1, 0, 3], state: "minecraft:polished_andesite"}, + {pos: [1, 0, 4], state: "minecraft:polished_andesite"}, + {pos: [2, 0, 0], state: "minecraft:polished_andesite"}, + {pos: [2, 0, 1], state: "minecraft:polished_andesite"}, + {pos: [2, 0, 2], state: "minecraft:polished_andesite"}, + {pos: [2, 0, 3], state: "minecraft:polished_andesite"}, + {pos: [2, 0, 4], state: "minecraft:polished_andesite"}, + {pos: [3, 0, 0], state: "minecraft:polished_andesite"}, + {pos: [3, 0, 1], state: "minecraft:polished_andesite"}, + {pos: [3, 0, 2], state: "minecraft:polished_andesite"}, + {pos: [3, 0, 3], state: "minecraft:polished_andesite"}, + {pos: [3, 0, 4], state: "minecraft:polished_andesite"}, + {pos: [4, 0, 0], state: "minecraft:polished_andesite"}, + {pos: [4, 0, 1], state: "minecraft:polished_andesite"}, + {pos: [4, 0, 2], state: "minecraft:polished_andesite"}, + {pos: [4, 0, 3], state: "minecraft:polished_andesite"}, + {pos: [4, 0, 4], state: "minecraft:polished_andesite"}, + {pos: [0, 1, 0], state: "minecraft:air"}, + {pos: [0, 1, 1], state: "minecraft:air"}, + {pos: [0, 1, 2], state: "minecraft:air"}, + {pos: [0, 1, 3], state: "minecraft:air"}, + {pos: [0, 1, 4], state: "minecraft:air"}, + {pos: [1, 1, 0], state: "minecraft:air"}, + {pos: [1, 1, 1], state: "minecraft:air"}, + {pos: [1, 1, 2], state: "minecraft:air"}, + {pos: [1, 1, 3], state: "minecraft:air"}, + {pos: [1, 1, 4], state: "minecraft:air"}, + {pos: [2, 1, 0], state: "minecraft:air"}, + {pos: [2, 1, 1], state: "computercraft:computer_advanced{facing:west,state:on}", nbt: {ComputerId: 1, ForgeCaps: {}, Label: "chatboxtest.chatbox_events", On: 1b, id: "computercraft:computer_advanced"}}, + {pos: [2, 1, 2], state: "advancedperipherals:chat_box{orientation:west_up}", nbt: {ForgeCaps: {}, ForgeData: {CustomName: "[Chat Box]"}, Items: [], id: "advancedperipherals:chat_box", peripheralSettings: {cooldowns: {chatMessage: 1717353228235L}}}}, + {pos: [2, 1, 3], state: "computercraft:computer_advanced{facing:west,state:on}", nbt: {ComputerId: 0, ForgeCaps: {}, Label: "chatboxtest.chatbox", On: 1b, id: "computercraft:computer_advanced"}}, + {pos: [2, 1, 4], state: "minecraft:air"}, + {pos: [3, 1, 0], state: "minecraft:air"}, + {pos: [3, 1, 1], state: "minecraft:air"}, + {pos: [3, 1, 2], state: "minecraft:air"}, + {pos: [3, 1, 3], state: "minecraft:air"}, + {pos: [3, 1, 4], state: "minecraft:air"}, + {pos: [4, 1, 0], state: "minecraft:air"}, + {pos: [4, 1, 1], state: "minecraft:air"}, + {pos: [4, 1, 2], state: "minecraft:air"}, + {pos: [4, 1, 3], state: "minecraft:air"}, + {pos: [4, 1, 4], state: "minecraft:air"}, + {pos: [0, 2, 0], state: "minecraft:air"}, + {pos: [0, 2, 1], state: "minecraft:air"}, + {pos: [0, 2, 2], state: "minecraft:air"}, + {pos: [0, 2, 3], state: "minecraft:air"}, + {pos: [0, 2, 4], state: "minecraft:air"}, + {pos: [1, 2, 0], state: "minecraft:air"}, + {pos: [1, 2, 1], state: "minecraft:air"}, + {pos: [1, 2, 2], state: "minecraft:air"}, + {pos: [1, 2, 3], state: "minecraft:air"}, + {pos: [1, 2, 4], state: "minecraft:air"}, + {pos: [2, 2, 0], state: "minecraft:air"}, + {pos: [2, 2, 1], state: "minecraft:air"}, + {pos: [2, 2, 2], state: "minecraft:air"}, + {pos: [2, 2, 3], state: "minecraft:air"}, + {pos: [2, 2, 4], state: "minecraft:air"}, + {pos: [3, 2, 0], state: "minecraft:air"}, + {pos: [3, 2, 1], state: "minecraft:air"}, + {pos: [3, 2, 2], state: "minecraft:air"}, + {pos: [3, 2, 3], state: "minecraft:air"}, + {pos: [3, 2, 4], state: "minecraft:air"}, + {pos: [4, 2, 0], state: "minecraft:air"}, + {pos: [4, 2, 1], state: "minecraft:air"}, + {pos: [4, 2, 2], state: "minecraft:air"}, + {pos: [4, 2, 3], state: "minecraft:air"}, + {pos: [4, 2, 4], state: "minecraft:air"}, + {pos: [0, 3, 0], state: "minecraft:air"}, + {pos: [0, 3, 1], state: "minecraft:air"}, + {pos: [0, 3, 2], state: "minecraft:air"}, + {pos: [0, 3, 3], state: "minecraft:air"}, + {pos: [0, 3, 4], state: "minecraft:air"}, + {pos: [1, 3, 0], state: "minecraft:air"}, + {pos: [1, 3, 1], state: "minecraft:air"}, + {pos: [1, 3, 2], state: "minecraft:air"}, + {pos: [1, 3, 3], state: "minecraft:air"}, + {pos: [1, 3, 4], state: "minecraft:air"}, + {pos: [2, 3, 0], state: "minecraft:air"}, + {pos: [2, 3, 1], state: "minecraft:air"}, + {pos: [2, 3, 2], state: "minecraft:air"}, + {pos: [2, 3, 3], state: "minecraft:air"}, + {pos: [2, 3, 4], state: "minecraft:air"}, + {pos: [3, 3, 0], state: "minecraft:air"}, + {pos: [3, 3, 1], state: "minecraft:air"}, + {pos: [3, 3, 2], state: "minecraft:air"}, + {pos: [3, 3, 3], state: "minecraft:air"}, + {pos: [3, 3, 4], state: "minecraft:air"}, + {pos: [4, 3, 0], state: "minecraft:air"}, + {pos: [4, 3, 1], state: "minecraft:air"}, + {pos: [4, 3, 2], state: "minecraft:air"}, + {pos: [4, 3, 3], state: "minecraft:air"}, + {pos: [4, 3, 4], state: "minecraft:air"}, + {pos: [0, 4, 0], state: "minecraft:air"}, + {pos: [0, 4, 1], state: "minecraft:air"}, + {pos: [0, 4, 2], state: "minecraft:air"}, + {pos: [0, 4, 3], state: "minecraft:air"}, + {pos: [0, 4, 4], state: "minecraft:air"}, + {pos: [1, 4, 0], state: "minecraft:air"}, + {pos: [1, 4, 1], state: "minecraft:air"}, + {pos: [1, 4, 2], state: "minecraft:air"}, + {pos: [1, 4, 3], state: "minecraft:air"}, + {pos: [1, 4, 4], state: "minecraft:air"}, + {pos: [2, 4, 0], state: "minecraft:air"}, + {pos: [2, 4, 1], state: "minecraft:air"}, + {pos: [2, 4, 2], state: "minecraft:polished_andesite"}, + {pos: [2, 4, 3], state: "minecraft:air"}, + {pos: [2, 4, 4], state: "minecraft:air"}, + {pos: [3, 4, 0], state: "minecraft:air"}, + {pos: [3, 4, 1], state: "minecraft:air"}, + {pos: [3, 4, 2], state: "minecraft:air"}, + {pos: [3, 4, 3], state: "minecraft:air"}, + {pos: [3, 4, 4], state: "minecraft:air"}, + {pos: [4, 4, 0], state: "minecraft:air"}, + {pos: [4, 4, 1], state: "minecraft:air"}, + {pos: [4, 4, 2], state: "minecraft:air"}, + {pos: [4, 4, 3], state: "minecraft:air"}, + {pos: [4, 4, 4], state: "minecraft:air"} + ], + entities: [], + palette: [ + "minecraft:polished_andesite", + "minecraft:air", + "computercraft:computer_advanced{facing:west,state:on}", + "advancedperipherals:chat_box{orientation:west_up}" + ] +} From fe249527f8ad04585af3714658b1615c9f3184d7 Mon Sep 17 00:00:00 2001 From: Dogboy21 Date: Sat, 29 Jun 2024 18:59:38 +0200 Subject: [PATCH 2/5] Fix NPE on client test start with existing world --- .../dan200/computercraft/gametest/core/ClientTestHooks.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/testMod/kotlin/dan200/computercraft/gametest/core/ClientTestHooks.kt b/src/testMod/kotlin/dan200/computercraft/gametest/core/ClientTestHooks.kt index 5a2384351..505407067 100644 --- a/src/testMod/kotlin/dan200/computercraft/gametest/core/ClientTestHooks.kt +++ b/src/testMod/kotlin/dan200/computercraft/gametest/core/ClientTestHooks.kt @@ -56,7 +56,7 @@ object ClientTestHooks { fun onOpenScreen(screen: Screen): Boolean = when { enabled && !loadedWorld && (screen is TitleScreen || screen is AccessibilityOptionsScreen) -> { loadedWorld = true - openWorld() + openWorld(screen) true } @@ -66,7 +66,7 @@ object ClientTestHooks { /** * Open or create our test world immediately on game launch. */ - private fun openWorld() { + private fun openWorld(screen: Screen) { val minecraft = Minecraft.getInstance() // Clear some options before we get any further. @@ -81,7 +81,7 @@ object ClientTestHooks { if (minecraft.levelSource.levelExists(LEVEL_NAME)) { LOG.info("World already exists, opening.") - minecraft.createWorldOpenFlows().loadLevel(minecraft.screen!!, LEVEL_NAME) + minecraft.createWorldOpenFlows().loadLevel(screen, LEVEL_NAME) } else { LOG.info("World does not exist, creating it.") val rules = GameRules() From e5b46ad62dc33c96e2525489268cbc81d26444c6 Mon Sep 17 00:00:00 2001 From: Dogboy21 Date: Sat, 29 Jun 2024 19:32:43 +0200 Subject: [PATCH 3/5] Add Chat Box event test --- .../advancedperipherals/test/ChatBoxTest.kt | 11 ++ .../tests/chatboxtest.chatbox_events.lua | 19 +++ .../structures/chatboxtest.chatbox.snbt | 2 +- .../chatboxtest.chatbox_events.snbt | 138 ++++++++++++++++++ 4 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 src/testMod/resources/data/advancedperipheralstest/computer/tests/chatboxtest.chatbox_events.lua create mode 100644 src/testMod/resources/data/advancedperipheralstest/structures/chatboxtest.chatbox_events.snbt diff --git a/src/testMod/kotlin/de/srendi/advancedperipherals/test/ChatBoxTest.kt b/src/testMod/kotlin/de/srendi/advancedperipherals/test/ChatBoxTest.kt index b112647f1..245063187 100644 --- a/src/testMod/kotlin/de/srendi/advancedperipherals/test/ChatBoxTest.kt +++ b/src/testMod/kotlin/de/srendi/advancedperipherals/test/ChatBoxTest.kt @@ -91,6 +91,7 @@ class ChatBoxTest { ClientTestEvents.toasts.clear() } thenComputerOk() + thenOnClient { // sendMessage context.assertChatContains(Component.literal("[§r").append("AP").append("]§r ").append("Default message")) @@ -158,4 +159,14 @@ class ChatBoxTest { } } + @ClientGameTest + fun chatBox_Events(context: GameTestHelper) = context.sequence { + thenIdle(20) + thenOnClient { Minecraft.getInstance().player!!.chatSigned("This is a normal chat message", null) } + thenIdle(20) + thenOnClient { Minecraft.getInstance().player!!.chatSigned("\$This is a hidden chat message", null) } + thenIdle(20) + thenComputerOk() + } + } \ No newline at end of file diff --git a/src/testMod/resources/data/advancedperipheralstest/computer/tests/chatboxtest.chatbox_events.lua b/src/testMod/resources/data/advancedperipheralstest/computer/tests/chatboxtest.chatbox_events.lua new file mode 100644 index 000000000..526b9b54a --- /dev/null +++ b/src/testMod/resources/data/advancedperipheralstest/computer/tests/chatboxtest.chatbox_events.lua @@ -0,0 +1,19 @@ +--- +--- Advanced Peripherals Chat Box tests +--- Covers `sendMessage`, `sendMessageToPlayer`, `sendToastToPlayer`, `sendFormattedToastToPlayer`, +--- `sendFormattedMessage`, `sendFormattedMessageToPlayer` +--- + +chatBox = peripheral.find("chatBox") +test.assert(chatBox, "Peripheral not found") + +function assertMessage(msg, hidden) + local event, username, message, uuid, isHidden = os.pullEvent("chat") + test.eq("chat", event, "Event should be 'chat'") + test.eq("Dev", username, "Username of sender should be 'Dev'") + test.eq(msg, message, "Message should be '" .. msg .. "'") + test.eq(hidden, isHidden, "Message should be " .. (hidden and "hidden" or "visible")) +end + +assertMessage("This is a normal chat message", false) +assertMessage("This is a hidden chat message", true) diff --git a/src/testMod/resources/data/advancedperipheralstest/structures/chatboxtest.chatbox.snbt b/src/testMod/resources/data/advancedperipheralstest/structures/chatboxtest.chatbox.snbt index b9dde7cfa..017725869 100644 --- a/src/testMod/resources/data/advancedperipheralstest/structures/chatboxtest.chatbox.snbt +++ b/src/testMod/resources/data/advancedperipheralstest/structures/chatboxtest.chatbox.snbt @@ -38,7 +38,7 @@ {pos: [1, 1, 3], state: "minecraft:air"}, {pos: [1, 1, 4], state: "minecraft:air"}, {pos: [2, 1, 0], state: "minecraft:air"}, - {pos: [2, 1, 1], state: "computercraft:computer_advanced{facing:west,state:on}", nbt: {ComputerId: 1, ForgeCaps: {}, Label: "chatboxtest.chatbox_events", On: 1b, id: "computercraft:computer_advanced"}}, + {pos: [2, 1, 1], state: "minecraft:air"}, {pos: [2, 1, 2], state: "advancedperipherals:chat_box{orientation:west_up}", nbt: {ForgeCaps: {}, ForgeData: {CustomName: "[Chat Box]"}, Items: [], id: "advancedperipherals:chat_box", peripheralSettings: {cooldowns: {chatMessage: 1717353228235L}}}}, {pos: [2, 1, 3], state: "computercraft:computer_advanced{facing:west,state:on}", nbt: {ComputerId: 0, ForgeCaps: {}, Label: "chatboxtest.chatbox", On: 1b, id: "computercraft:computer_advanced"}}, {pos: [2, 1, 4], state: "minecraft:air"}, diff --git a/src/testMod/resources/data/advancedperipheralstest/structures/chatboxtest.chatbox_events.snbt b/src/testMod/resources/data/advancedperipheralstest/structures/chatboxtest.chatbox_events.snbt new file mode 100644 index 000000000..c3bc156f8 --- /dev/null +++ b/src/testMod/resources/data/advancedperipheralstest/structures/chatboxtest.chatbox_events.snbt @@ -0,0 +1,138 @@ +{ + DataVersion: 3120, + size: [5, 5, 5], + data: [ + {pos: [0, 0, 0], state: "minecraft:polished_andesite"}, + {pos: [0, 0, 1], state: "minecraft:polished_andesite"}, + {pos: [0, 0, 2], state: "minecraft:polished_andesite"}, + {pos: [0, 0, 3], state: "minecraft:polished_andesite"}, + {pos: [0, 0, 4], state: "minecraft:polished_andesite"}, + {pos: [1, 0, 0], state: "minecraft:polished_andesite"}, + {pos: [1, 0, 1], state: "minecraft:polished_andesite"}, + {pos: [1, 0, 2], state: "minecraft:polished_andesite"}, + {pos: [1, 0, 3], state: "minecraft:polished_andesite"}, + {pos: [1, 0, 4], state: "minecraft:polished_andesite"}, + {pos: [2, 0, 0], state: "minecraft:polished_andesite"}, + {pos: [2, 0, 1], state: "minecraft:polished_andesite"}, + {pos: [2, 0, 2], state: "minecraft:polished_andesite"}, + {pos: [2, 0, 3], state: "minecraft:polished_andesite"}, + {pos: [2, 0, 4], state: "minecraft:polished_andesite"}, + {pos: [3, 0, 0], state: "minecraft:polished_andesite"}, + {pos: [3, 0, 1], state: "minecraft:polished_andesite"}, + {pos: [3, 0, 2], state: "minecraft:polished_andesite"}, + {pos: [3, 0, 3], state: "minecraft:polished_andesite"}, + {pos: [3, 0, 4], state: "minecraft:polished_andesite"}, + {pos: [4, 0, 0], state: "minecraft:polished_andesite"}, + {pos: [4, 0, 1], state: "minecraft:polished_andesite"}, + {pos: [4, 0, 2], state: "minecraft:polished_andesite"}, + {pos: [4, 0, 3], state: "minecraft:polished_andesite"}, + {pos: [4, 0, 4], state: "minecraft:polished_andesite"}, + {pos: [0, 1, 0], state: "minecraft:air"}, + {pos: [0, 1, 1], state: "minecraft:air"}, + {pos: [0, 1, 2], state: "minecraft:air"}, + {pos: [0, 1, 3], state: "minecraft:air"}, + {pos: [0, 1, 4], state: "minecraft:air"}, + {pos: [1, 1, 0], state: "minecraft:air"}, + {pos: [1, 1, 1], state: "minecraft:air"}, + {pos: [1, 1, 2], state: "minecraft:air"}, + {pos: [1, 1, 3], state: "minecraft:air"}, + {pos: [1, 1, 4], state: "minecraft:air"}, + {pos: [2, 1, 0], state: "minecraft:air"}, + {pos: [2, 1, 1], state: "minecraft:air"}, + {pos: [2, 1, 2], state: "advancedperipherals:chat_box{orientation:west_up}", nbt: {ForgeCaps: {}, ForgeData: {CustomName: "[Chat Box]"}, Items: [], id: "advancedperipherals:chat_box", peripheralSettings: {cooldowns: {chatMessage: 1717353228235L}}}}, + {pos: [2, 1, 3], state: "computercraft:computer_advanced{facing:west,state:on}", nbt: {ComputerId: 0, ForgeCaps: {}, Label: "chatboxtest.chatbox_events", On: 1b, id: "computercraft:computer_advanced"}}, + {pos: [2, 1, 4], state: "minecraft:air"}, + {pos: [3, 1, 0], state: "minecraft:air"}, + {pos: [3, 1, 1], state: "minecraft:air"}, + {pos: [3, 1, 2], state: "minecraft:air"}, + {pos: [3, 1, 3], state: "minecraft:air"}, + {pos: [3, 1, 4], state: "minecraft:air"}, + {pos: [4, 1, 0], state: "minecraft:air"}, + {pos: [4, 1, 1], state: "minecraft:air"}, + {pos: [4, 1, 2], state: "minecraft:air"}, + {pos: [4, 1, 3], state: "minecraft:air"}, + {pos: [4, 1, 4], state: "minecraft:air"}, + {pos: [0, 2, 0], state: "minecraft:air"}, + {pos: [0, 2, 1], state: "minecraft:air"}, + {pos: [0, 2, 2], state: "minecraft:air"}, + {pos: [0, 2, 3], state: "minecraft:air"}, + {pos: [0, 2, 4], state: "minecraft:air"}, + {pos: [1, 2, 0], state: "minecraft:air"}, + {pos: [1, 2, 1], state: "minecraft:air"}, + {pos: [1, 2, 2], state: "minecraft:air"}, + {pos: [1, 2, 3], state: "minecraft:air"}, + {pos: [1, 2, 4], state: "minecraft:air"}, + {pos: [2, 2, 0], state: "minecraft:air"}, + {pos: [2, 2, 1], state: "minecraft:air"}, + {pos: [2, 2, 2], state: "minecraft:air"}, + {pos: [2, 2, 3], state: "minecraft:air"}, + {pos: [2, 2, 4], state: "minecraft:air"}, + {pos: [3, 2, 0], state: "minecraft:air"}, + {pos: [3, 2, 1], state: "minecraft:air"}, + {pos: [3, 2, 2], state: "minecraft:air"}, + {pos: [3, 2, 3], state: "minecraft:air"}, + {pos: [3, 2, 4], state: "minecraft:air"}, + {pos: [4, 2, 0], state: "minecraft:air"}, + {pos: [4, 2, 1], state: "minecraft:air"}, + {pos: [4, 2, 2], state: "minecraft:air"}, + {pos: [4, 2, 3], state: "minecraft:air"}, + {pos: [4, 2, 4], state: "minecraft:air"}, + {pos: [0, 3, 0], state: "minecraft:air"}, + {pos: [0, 3, 1], state: "minecraft:air"}, + {pos: [0, 3, 2], state: "minecraft:air"}, + {pos: [0, 3, 3], state: "minecraft:air"}, + {pos: [0, 3, 4], state: "minecraft:air"}, + {pos: [1, 3, 0], state: "minecraft:air"}, + {pos: [1, 3, 1], state: "minecraft:air"}, + {pos: [1, 3, 2], state: "minecraft:air"}, + {pos: [1, 3, 3], state: "minecraft:air"}, + {pos: [1, 3, 4], state: "minecraft:air"}, + {pos: [2, 3, 0], state: "minecraft:air"}, + {pos: [2, 3, 1], state: "minecraft:air"}, + {pos: [2, 3, 2], state: "minecraft:air"}, + {pos: [2, 3, 3], state: "minecraft:air"}, + {pos: [2, 3, 4], state: "minecraft:air"}, + {pos: [3, 3, 0], state: "minecraft:air"}, + {pos: [3, 3, 1], state: "minecraft:air"}, + {pos: [3, 3, 2], state: "minecraft:air"}, + {pos: [3, 3, 3], state: "minecraft:air"}, + {pos: [3, 3, 4], state: "minecraft:air"}, + {pos: [4, 3, 0], state: "minecraft:air"}, + {pos: [4, 3, 1], state: "minecraft:air"}, + {pos: [4, 3, 2], state: "minecraft:air"}, + {pos: [4, 3, 3], state: "minecraft:air"}, + {pos: [4, 3, 4], state: "minecraft:air"}, + {pos: [0, 4, 0], state: "minecraft:air"}, + {pos: [0, 4, 1], state: "minecraft:air"}, + {pos: [0, 4, 2], state: "minecraft:air"}, + {pos: [0, 4, 3], state: "minecraft:air"}, + {pos: [0, 4, 4], state: "minecraft:air"}, + {pos: [1, 4, 0], state: "minecraft:air"}, + {pos: [1, 4, 1], state: "minecraft:air"}, + {pos: [1, 4, 2], state: "minecraft:air"}, + {pos: [1, 4, 3], state: "minecraft:air"}, + {pos: [1, 4, 4], state: "minecraft:air"}, + {pos: [2, 4, 0], state: "minecraft:air"}, + {pos: [2, 4, 1], state: "minecraft:air"}, + {pos: [2, 4, 2], state: "minecraft:air"}, + {pos: [2, 4, 3], state: "minecraft:air"}, + {pos: [2, 4, 4], state: "minecraft:air"}, + {pos: [3, 4, 0], state: "minecraft:air"}, + {pos: [3, 4, 1], state: "minecraft:air"}, + {pos: [3, 4, 2], state: "minecraft:air"}, + {pos: [3, 4, 3], state: "minecraft:air"}, + {pos: [3, 4, 4], state: "minecraft:air"}, + {pos: [4, 4, 0], state: "minecraft:air"}, + {pos: [4, 4, 1], state: "minecraft:air"}, + {pos: [4, 4, 2], state: "minecraft:air"}, + {pos: [4, 4, 3], state: "minecraft:air"}, + {pos: [4, 4, 4], state: "minecraft:air"} + ], + entities: [], + palette: [ + "minecraft:polished_andesite", + "minecraft:air", + "computercraft:computer_advanced{facing:west,state:on}", + "advancedperipherals:chat_box{orientation:west_up}" + ] +} From 4904f853c3397c2746a3240715fceb64478f10a3 Mon Sep 17 00:00:00 2001 From: Dogboy21 Date: Sat, 29 Jun 2024 20:16:48 +0200 Subject: [PATCH 4/5] Fix runGameTestClient task also running common tests --- build.gradle | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 49a464dab..bae45dc20 100644 --- a/build.gradle +++ b/build.gradle @@ -184,6 +184,15 @@ minecraft { } } + // internal run config to automatically run the client-side gametests with the runGameTestClient task + runGameTestClientInternal { + parent runs.testClient + + lazyToken("minecraft_classpath", lazyTokens["minecraft_classpath"]) + + property 'advancedperipheralstest.tags', 'client' + } + gameTestServer { def oldClasspath = lazyTokens["minecraft_classpath"] lazyToken("minecraft_classpath") { @@ -669,6 +678,5 @@ publishing { tasks.register('runGameTestClient', ClientJavaExec, { task -> description "Runs client-side gametests with no mods" - setRunConfig(minecraft.runs["testClient"]) - tags("client") + setRunConfig(minecraft.runs.runGameTestClientInternal) }) From 83c79771b826e6cb092793b7b1340fb6a78c6859 Mon Sep 17 00:00:00 2001 From: Dogboy21 Date: Thu, 4 Jul 2024 22:17:13 +0200 Subject: [PATCH 5/5] Clean and fix runGameTestClient task --- build.gradle | 14 ++++---------- .../main/kotlin/cc/tweaked/gradle/MinecraftExec.kt | 7 ++++++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/build.gradle b/build.gradle index bae45dc20..e7ce82319 100644 --- a/build.gradle +++ b/build.gradle @@ -184,15 +184,6 @@ minecraft { } } - // internal run config to automatically run the client-side gametests with the runGameTestClient task - runGameTestClientInternal { - parent runs.testClient - - lazyToken("minecraft_classpath", lazyTokens["minecraft_classpath"]) - - property 'advancedperipheralstest.tags', 'client' - } - gameTestServer { def oldClasspath = lazyTokens["minecraft_classpath"] lazyToken("minecraft_classpath") { @@ -677,6 +668,9 @@ publishing { } tasks.register('runGameTestClient', ClientJavaExec, { task -> + task.outputs.upToDateWhen { false } + description "Runs client-side gametests with no mods" - setRunConfig(minecraft.runs.runGameTestClientInternal) + setRunConfig(minecraft.runs.testClient) + tags("client") }) diff --git a/buildSrc/src/main/kotlin/cc/tweaked/gradle/MinecraftExec.kt b/buildSrc/src/main/kotlin/cc/tweaked/gradle/MinecraftExec.kt index daf382ab0..4755f0274 100644 --- a/buildSrc/src/main/kotlin/cc/tweaked/gradle/MinecraftExec.kt +++ b/buildSrc/src/main/kotlin/cc/tweaked/gradle/MinecraftExec.kt @@ -14,6 +14,7 @@ import org.gradle.api.services.BuildServiceParameters import org.gradle.api.tasks.* import org.gradle.kotlin.dsl.getByName import org.gradle.language.base.plugins.LifecycleBasePlugin +import org.gradle.process.CommandLineArgumentProvider import java.io.File import java.nio.file.Files import java.util.concurrent.TimeUnit @@ -91,7 +92,11 @@ abstract class ClientJavaExec : JavaExec() { * Only run tests with the given tags. */ fun tags(vararg tags: String) { - systemProperty("advancedperipheralstest.tags", tags.joinToString(",")) + jvmArgumentProviders.add( + CommandLineArgumentProvider { + listOf("-Dadvancedperipheralstest.tags=${tags.joinToString(",")}") + } + ) } /**