A pack that loads none of the built-in modules is told once, with the jar to copy and where

This commit is contained in:
piexel committed 2026-10-10 14:25:56 +02:00
1 parent 9147acca0c
commit ee2a0425e2
6 files changed
+202 -1

No files matched your search

@@ -66,6 +66,17 @@ public class BuiltInModulesJarTest {
}
}
@Test
public void theIdsIrisLooksForAreTheOnesTheJarProvides() throws IOException {
Path pack = BuiltInPack.newPackFolder(folder);
BuiltInModulesJar.writeInto(pack);
try (LoadedPack loaded = loadWithStandIns(pack)) {
List<String> provided = loaded.packModules().stream().map(module -> module.info().id().toString()).toList();
assertEquals(provided, IrisModuleHost.JAR_MODULE_IDS);
}
}
@Test
public void theJarsModulesGenerateWhatTheirCompiledInCopiesGenerate() throws IOException {
Path pack = BuiltInPack.newPackFolder(folder);
@@ -0,0 +1,69 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.core.modules;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.host.DiscoveredModule;
import com.volmit.stage.StageGraph;
import org.junit.Test;
import java.io.File;
import java.util.List;
import java.util.Optional;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class MissingBuiltInModulesTest {
private static final File PACK = new File("packs", "overworld");
@Test
public void aPackWithNoModulesIsToldWhichJarToCopyWhere() {
String warning = MissingBuiltInModules.warning(PACK, List.of()).orElseThrow();
assertTrue(warning, warning.startsWith("Pack overworld loads without the built-in modules (iris-builtins.jar)"));
assertTrue(warning, warning.contains("Copy iris-builtins.jar into " + new File(PACK, "modules").getPath() + " to fix it."));
}
@Test
public void aPackWithOnlyOtherModulesIsToldToo() {
assertTrue(MissingBuiltInModules.warning(PACK, List.of(module("pack:ruins"))).isPresent());
}
@Test
public void anyOfTheJarsModulesCountsAsHavingTheJar() {
for (String id : IrisModuleHost.JAR_MODULE_IDS) {
assertEquals(id, Optional.empty(), MissingBuiltInModules.warning(PACK, List.of(module("pack:ruins"), module(id))));
}
}
private static DiscoveredModule module(String id) {
return DiscoveredModule.builtIn(new IrisModule() {
@Override
public ModuleInfo info() {
return ModuleInfo.of(id, "Stand-in " + id, "test");
}
@Override
public void install(StageGraph graph) {
}
});
}
}
@@ -18,16 +18,22 @@
package art.arcane.iris.core.modules;
import art.arcane.iris.spi.IrisPlatforms;
import com.google.gson.Gson;
import org.junit.Assume;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
@@ -60,4 +66,57 @@ public class PackModuleSetTest {
assertTrue(first.getMessage(), first.getMessage().startsWith("Pack broken cannot load its modules: "));
modules.close();
}
@Test
public void aPackWithoutTheBuiltInsJarIsToldHowToGetThem() throws IOException {
File pack = folder.newFolder("without-builtins");
String warnings = warningsWhile(() -> new PackModuleSet(pack, Gson::new).pack());
assertTrue(warnings, warnings.contains("[Iris/WARN] Pack without-builtins loads without the built-in modules (iris-builtins.jar)"));
assertTrue(warnings, warnings.contains("Copy iris-builtins.jar into " + new File(pack, "modules").getPath()));
}
@Test
public void aPackIsToldOnceHoweverOftenItLoadsAndAWorldCopyOfItIsToldToo() throws IOException {
File pack = folder.newFolder("original");
File worldCopy = folder.newFolder("world", "iris", "pack");
String warnings = warningsWhile(() -> {
new PackModuleSet(pack, Gson::new).pack();
new PackModuleSet(pack, Gson::new).pack();
new PackModuleSet(worldCopy, Gson::new).pack();
});
assertEquals(warnings, 1, occurrences(warnings, "Pack original loads without"));
assertEquals(warnings, 1, occurrences(warnings, "Pack pack loads without"));
}
@Test
public void aPackWithTheBuiltInsJarIsNotWarned() throws IOException {
File pack = folder.newFolder("with-builtins");
BuiltInModulesJar.writeInto(pack.toPath());
String warnings = warningsWhile(() -> assertFalse(new PackModuleSet(pack, Gson::new).pack().packModules().isEmpty()));
assertFalse(warnings, warnings.contains("built-in modules"));
}
/** What Iris's log said at WARN while {@code load} ran: with no platform bound it goes to the error stream. */
private static String warningsWhile(Runnable load) {
Assume.assumeFalse("a platform is bound, so the log does not go to the error stream", IrisPlatforms.isBound());
PrintStream original = System.err;
ByteArrayOutputStream captured = new ByteArrayOutputStream();
System.setErr(new PrintStream(captured, true, StandardCharsets.UTF_8));
try {
load.run();
} finally {
System.setErr(original);
}
return captured.toString(StandardCharsets.UTF_8);
}
private static int occurrences(String text, String fragment) {
return text.split(java.util.regex.Pattern.quote(fragment), -1).length - 1;
}
}