forked from CleanroomMC/ModularUI
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detach Mui from GuiScreenWrapper (CleanroomMC#64)
* detach GuiScreenWrapper * fix mouse input * slightly scuffed gui overlays * fix text widget for unusual scales * lots of small stuff * setup tests & own matrix and vector impl * dont use deprecated field * move overlay test to own class * test button overlapping * allow creating custom gui wrappers from UIFactory * helpers & javadoc for ui factories (cherry picked from commit 47cf883)
- Loading branch information
Showing
73 changed files
with
3,291 additions
and
672 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
test { | ||
useJUnitPlatform() | ||
testLogging { | ||
events "passed", "skipped", "failed" | ||
} | ||
} | ||
|
||
SourceSet functionalTestSet = null | ||
|
||
sourceSets { | ||
functionalTestSet = create("functionalTest") { | ||
java { | ||
srcDir("src/functionalTest/java") | ||
compileClasspath += sourceSets.patchedMc.output + sourceSets.main.output | ||
} | ||
} | ||
} | ||
|
||
configurations { configs -> | ||
// Keep all dependencies from the main mod in the functional test mod | ||
named(functionalTestSet.compileClasspathConfigurationName).configure {it.extendsFrom(named("compileClasspath").get())} | ||
named(functionalTestSet.runtimeClasspathConfigurationName).configure {it.extendsFrom(named("runtimeClasspath").get())} | ||
named(functionalTestSet.annotationProcessorConfigurationName).configure {it.extendsFrom(named("annotationProcessor").get())} | ||
} | ||
|
||
tasks.register(functionalTestSet.jarTaskName, Jar) { | ||
from(functionalTestSet.output) | ||
archiveClassifier.set("functionalTests") | ||
// we don't care about the version number here, keep it stable to avoid polluting the tmp directory | ||
archiveVersion.set("1.0") | ||
destinationDirectory.set(new File(buildDir, "tmp")) | ||
} | ||
tasks.named("assemble").configure { | ||
dependsOn(functionalTestSet.jarTaskName) | ||
} | ||
|
||
// Run tests in the default runServer/runClient configurations | ||
tasks.named("runServer", JavaExec).configure { | ||
dependsOn(functionalTestSet.jarTaskName) | ||
classpath(configurations.named(functionalTestSet.runtimeClasspathConfigurationName), tasks.named(functionalTestSet.jarTaskName)) | ||
} | ||
|
||
tasks.named("runClient", JavaExec).configure { | ||
dependsOn(functionalTestSet.jarTaskName) | ||
classpath(configurations.named(functionalTestSet.runtimeClasspathConfigurationName), tasks.named(functionalTestSet.jarTaskName)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/functionalTest/java/com/cleanroommc/modularui/test/MUITestMod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.cleanroommc.modularui.test; | ||
|
||
import java.io.File; | ||
import java.io.PrintWriter; | ||
import java.nio.file.FileSystems; | ||
import java.nio.file.Path; | ||
|
||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.util.ChatComponentText; | ||
|
||
import org.apache.commons.io.output.CloseShieldOutputStream; | ||
import org.junit.platform.engine.discovery.DiscoverySelectors; | ||
import org.junit.platform.launcher.Launcher; | ||
import org.junit.platform.launcher.LauncherDiscoveryRequest; | ||
import org.junit.platform.launcher.LauncherSession; | ||
import org.junit.platform.launcher.TestPlan; | ||
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder; | ||
import org.junit.platform.launcher.core.LauncherFactory; | ||
import org.junit.platform.launcher.listeners.SummaryGeneratingListener; | ||
import org.junit.platform.launcher.listeners.TestExecutionSummary; | ||
import org.junit.platform.reporting.legacy.xml.LegacyXmlReportGeneratingListener; | ||
|
||
import cpw.mods.fml.common.FMLCommonHandler; | ||
import cpw.mods.fml.common.Mod; | ||
import cpw.mods.fml.common.event.FMLServerStartedEvent; | ||
|
||
@Mod(modid = "mui-tests", name = "MUI Dev Tests", version = "1.0", dependencies = "required-after:modularui2") | ||
public class MUITestMod { | ||
|
||
@Mod.EventHandler | ||
public void onServerStarted(FMLServerStartedEvent event) { | ||
MinecraftServer.getServer() | ||
.addChatMessage(new ChatComponentText("Running MUI unit tests...")); | ||
runTests(); | ||
MinecraftServer.getServer() | ||
.addChatMessage(new ChatComponentText("Running MUI unit tests finished")); | ||
} | ||
|
||
private void runTests() { | ||
// https://junit.org/junit5/docs/current/user-guide/#launcher-api | ||
System.setProperty("junit.platform.reporting.open.xml.enabled", "false"); | ||
final Path testsXmlOutDir = FileSystems.getDefault() | ||
.getPath("./junit-out/") | ||
.toAbsolutePath(); | ||
final File testsXmlOutDirFile = testsXmlOutDir.toFile(); | ||
testsXmlOutDirFile.mkdirs(); | ||
{ | ||
File[] fileList = testsXmlOutDirFile.listFiles(); | ||
if (fileList != null) { | ||
for (File child : fileList) { | ||
if (child.isFile() && child.getName() | ||
.endsWith(".xml")) { | ||
child.delete(); | ||
} | ||
} | ||
} | ||
} | ||
final LauncherDiscoveryRequest discovery = LauncherDiscoveryRequestBuilder.request() | ||
.selectors(DiscoverySelectors.selectPackage("com.cleanroommc.modularui.test")) | ||
.build(); | ||
final SummaryGeneratingListener summaryGenerator = new SummaryGeneratingListener(); | ||
final TestExecutionSummary summary; | ||
try (PrintWriter stderrWriter = new PrintWriter(new CloseShieldOutputStream(System.err), true)) { | ||
final LegacyXmlReportGeneratingListener xmlGenerator = new LegacyXmlReportGeneratingListener( | ||
testsXmlOutDir, | ||
stderrWriter); | ||
try (LauncherSession session = LauncherFactory.openSession()) { | ||
final Launcher launcher = session.getLauncher(); | ||
final TestPlan plan = launcher.discover(discovery); | ||
launcher.registerTestExecutionListeners(summaryGenerator, xmlGenerator); | ||
launcher.execute(plan); | ||
} | ||
summary = summaryGenerator.getSummary(); | ||
|
||
summary.printFailuresTo(stderrWriter, 32); | ||
summary.printTo(stderrWriter); | ||
stderrWriter.flush(); | ||
} | ||
// Throw an exception if running via `runServer` | ||
if (summary.getTotalFailureCount() > 0 && FMLCommonHandler.instance() | ||
.getSide() | ||
.isServer()) { | ||
throw new RuntimeException("Some of the unit tests failed to execute, check the log for details"); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/functionalTest/java/com/cleanroommc/modularui/test/SizerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.cleanroommc.modularui.test; | ||
|
||
import com.cleanroommc.modularui.overlay.ScreenWrapper; | ||
import com.cleanroommc.modularui.screen.ModularPanel; | ||
import com.cleanroommc.modularui.screen.ModularScreen; | ||
import com.cleanroommc.modularui.screen.NEISettingsImpl; | ||
import com.cleanroommc.modularui.widget.sizer.Area; | ||
import com.cleanroommc.modularui.widgets.ButtonWidget; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class SizerTest { | ||
|
||
static final int W = 800, H = 450; | ||
|
||
@Test | ||
void test() { | ||
ModularPanel panel = panel().child(new ButtonWidget<>().center()); | ||
testPanel(panel); | ||
assertArea(panel.getArea(), W / 2 - 176 / 2, H / 2 - 166 / 2, 176, 166); | ||
} | ||
|
||
ModularPanel panel(int w, int h) { | ||
return ModularPanel.defaultPanel("main", w, h); | ||
} | ||
|
||
ModularPanel panel() { | ||
return ModularPanel.defaultPanel("main"); | ||
} | ||
|
||
void assertArea(Area area, int x, int y, int w, int h) { | ||
Area.SHARED.set(x, y, w, h); | ||
assertEquals(Area.SHARED, area); | ||
} | ||
|
||
ModularScreen testPanel(ModularPanel panel) { | ||
ModularScreen screen = new ModularScreen(panel); | ||
screen.getContext().setNEISettings(new NEISettingsImpl()); | ||
ScreenWrapper wrapper = new ScreenWrapper(null, screen); | ||
screen.construct(wrapper); | ||
screen.onResize(W, H); | ||
return screen; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[ | ||
{ | ||
"modid":"MUI-tests", | ||
"name":"MUI Dev Tests", | ||
"description":"MUI Tests to run in the development environment", | ||
"version":"1.0", | ||
"mcversion":"1.7.10", | ||
"url":"https://github.com/GTNewHorizons/ModularUI2", | ||
"updateUrl":"", | ||
"authorList":[], | ||
"credits":"", | ||
"logoFile":"", | ||
"screenshots":[] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.