Skip to content

Commit

Permalink
Add a test for multiple entrypoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed May 24, 2024
1 parent 383a46e commit 50bfdeb
Showing 1 changed file with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@

public class FMLJavaModLanguageProviderTest extends LauncherTest {
// Allows us to capture events received by mods loaded in the game layer
public static List<FMLClientSetupEvent> EVENTS = new ArrayList<>();
public static final List<FMLClientSetupEvent> EVENTS = new ArrayList<>();
public static final List<String> MESSAGES = new ArrayList<>();

@AfterEach
void tearDown() {
EVENTS.clear();
MESSAGES.clear();
}

/**
Expand Down Expand Up @@ -107,6 +109,40 @@ public EntryPoint(net.neoforged.bus.api.IEventBus modEventBus) {
assertThat(EVENTS).hasSize(1);
}

@Test
void testMultipleEntrypoints() throws Exception {
installation.setupProductionClient();

var testJar = installation.writeModJar("test.jar", SimulatedInstallation.createModsToml("testmod", "1.0"));
try (var compiler = RuntimeCompiler.create(testJar)) {
compiler.builder()
.addClass("testmod.EntryPoint", """
@net.neoforged.fml.common.Mod("testmod")
public class EntryPoint {
public EntryPoint() {
net.neoforged.fml.javafmlmod.FMLJavaModLanguageProviderTest.MESSAGES.add("common");
}
}
""")
.addClass("testmod.ClientEntryPoint", """
@net.neoforged.fml.common.Mod(value = "testmod", dist = net.neoforged.api.distmarker.Dist.CLIENT)
public class ClientEntryPoint {
public ClientEntryPoint() {
net.neoforged.fml.javafmlmod.FMLJavaModLanguageProviderTest.MESSAGES.add("client");
}
}
""")
.compile();
}

var result = launch("forgeclient");
loadMods(result);

ModLoader.dispatchParallelEvent("test", Runnable::run, Runnable::run, () -> {}, FMLClientSetupEvent::new);

assertThat(MESSAGES).isEqualTo(List.of("common", "client"));
}

@Test
void testErrorDuringEventDispatch() throws Exception {
installation.setupProductionClient();
Expand Down

0 comments on commit 50bfdeb

Please sign in to comment.