mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-12 16:37:38 +00:00
test: add Forge server characterization
Run JUnit after FML server startup and gate the task on fresh XML because Forge can exit zero after a test-mod exception.
This commit is contained in:
1 parent
e33d3b2493
commit
4ae2a6d0fa
5 files changed
+278
-3
No files matched your search
@@ -0,0 +1,60 @@
|
||||
package codechicken.multipart.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.BitSet;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import codechicken.multipart.TileMultipart;
|
||||
import codechicken.multipart.asm.MultipartMixinFactory;
|
||||
import codechicken.multipart.scalatraits.TSlottedTile;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import scala.collection.immutable.Nil$;
|
||||
|
||||
class ForgeEnvironmentSmokeTest {
|
||||
|
||||
@Test
|
||||
void reachesServerStartedWithWorldAndMultipartModsLoaded() {
|
||||
assertTrue(ForgeMultipartFunctionalTestMod.preInitialized);
|
||||
assertTrue(ForgeMultipartFunctionalTestMod.initialized);
|
||||
assertTrue(ForgeMultipartFunctionalTestMod.postInitialized);
|
||||
assertTrue(ForgeMultipartFunctionalTestMod.serverAboutToStart);
|
||||
assertTrue(ForgeMultipartFunctionalTestMod.serverStarted);
|
||||
assertTrue(FMLCommonHandler.instance().getSide().isServer());
|
||||
assertTrue(Loader.isModLoaded("ForgeMultipart"));
|
||||
assertTrue(Loader.isModLoaded("ForgeMicroblock"));
|
||||
assertTrue(Loader.isModLoaded("McMultipart"));
|
||||
|
||||
MinecraftServer server = MinecraftServer.getServer();
|
||||
assertNotNull(server);
|
||||
assertNotNull(server.worldServers);
|
||||
assertTrue(server.worldServers.length > 0);
|
||||
assertNotNull(server.worldServers[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
void generatesAndCachesSlottedTileClass() {
|
||||
int traitId = MultipartMixinFactory.getId(TSlottedTile.class.getName().replace('.', '/'));
|
||||
assertFalse(traitId < 0);
|
||||
|
||||
BitSet traits = new BitSet();
|
||||
traits.set(traitId);
|
||||
Object first = MultipartMixinFactory.construct(traits, Nil$.MODULE$);
|
||||
Object second = MultipartMixinFactory.construct(traits, Nil$.MODULE$);
|
||||
|
||||
assertTrue(first instanceof TileMultipart);
|
||||
assertTrue(first instanceof TSlottedTile);
|
||||
assertNotSame(first, second);
|
||||
assertSame(first.getClass(), second.getClass());
|
||||
assertEquals(27, ((TSlottedTile) first).v_partMap().length);
|
||||
}
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
package codechicken.multipart.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.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.Mod;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStartedEvent;
|
||||
|
||||
@Mod(
|
||||
modid = "ForgeMultipartTests",
|
||||
name = "ForgeMultipart Functional Tests",
|
||||
version = "1.0",
|
||||
dependencies = "required-after:ForgeMultipart",
|
||||
acceptableRemoteVersions = "*")
|
||||
public final class ForgeMultipartFunctionalTestMod {
|
||||
|
||||
static boolean preInitialized;
|
||||
static boolean initialized;
|
||||
static boolean postInitialized;
|
||||
static boolean serverAboutToStart;
|
||||
static boolean serverStarted;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
preInitialized = true;
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void init(FMLInitializationEvent event) {
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
postInitialized = true;
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void serverAboutToStart(FMLServerAboutToStartEvent event) {
|
||||
serverAboutToStart = true;
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void serverStarted(FMLServerStartedEvent event) {
|
||||
serverStarted = true;
|
||||
MinecraftServer server = MinecraftServer.getServer();
|
||||
server.addChatMessage(new ChatComponentText("Running ForgeMultipart functional tests..."));
|
||||
|
||||
TestExecutionSummary summary = runTests();
|
||||
if (summary.getTestsFoundCount() == 0) {
|
||||
throw new IllegalStateException("No ForgeMultipart functional tests were discovered");
|
||||
}
|
||||
if (summary.getTotalFailureCount() > 0) {
|
||||
throw new IllegalStateException("ForgeMultipart functional tests failed; check junit-out and the server log");
|
||||
}
|
||||
|
||||
server.addChatMessage(new ChatComponentText("ForgeMultipart functional tests passed"));
|
||||
server.initiateShutdown();
|
||||
}
|
||||
|
||||
private static TestExecutionSummary runTests() {
|
||||
System.setProperty("junit.platform.reporting.open.xml.enabled", "false");
|
||||
Path reportDirectory = FileSystems.getDefault().getPath("./junit-out/").toAbsolutePath();
|
||||
File reportDirectoryFile = reportDirectory.toFile();
|
||||
reportDirectoryFile.mkdirs();
|
||||
File[] oldReports = reportDirectoryFile.listFiles((directory, name) -> name.endsWith(".xml"));
|
||||
if (oldReports != null) {
|
||||
for (File oldReport : oldReports) {
|
||||
oldReport.delete();
|
||||
}
|
||||
}
|
||||
|
||||
LauncherDiscoveryRequest discovery = LauncherDiscoveryRequestBuilder.request()
|
||||
.selectors(DiscoverySelectors.selectPackage("codechicken.multipart.test"))
|
||||
.build();
|
||||
SummaryGeneratingListener summaryListener = new SummaryGeneratingListener();
|
||||
PrintWriter stderr = new PrintWriter(System.err, true);
|
||||
LegacyXmlReportGeneratingListener xmlListener = new LegacyXmlReportGeneratingListener(reportDirectory, stderr);
|
||||
|
||||
try (LauncherSession session = LauncherFactory.openSession()) {
|
||||
Launcher launcher = session.getLauncher();
|
||||
TestPlan plan = launcher.discover(discovery);
|
||||
launcher.registerTestExecutionListeners(summaryListener, xmlListener);
|
||||
launcher.execute(plan);
|
||||
}
|
||||
|
||||
TestExecutionSummary summary = summaryListener.getSummary();
|
||||
summary.printFailuresTo(stderr, 32);
|
||||
summary.printTo(stderr);
|
||||
stderr.flush();
|
||||
return summary;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user