Add ModCheckTest to test runtime mod validations and entry point superclass checks. Include Gradle verification metadata for dependency integrity.

This commit is contained in:
Overlord committed 2026-10-03 09:59:47 +02:00
1 parent 18ff32b5ce
commit 6761f2d9ea
29 files changed
+1306 -72

No files matched your search

@@ -32,7 +32,8 @@ public abstract class DownloadGame extends DefaultTask
static final String JAR = "java/projectzomboid.jar";
private static final String APP_ID = "380870";
private static final String IMAGE = "docker.io/steamcmd/steamcmd:latest";
// The same image as the Dockerfile's server stage.
private static final String IMAGE = "docker.io/steamcmd/steamcmd:debian-13@sha256:b0b49ef3101c304ed6e3fbc3ea930b2940d7c489563a1ebac524ad5bb46d336d";
private static final int MAX_ATTEMPTS = 3;
@Internal
@@ -102,7 +102,7 @@ public abstract class GenerateModDescriptor extends DefaultTask
if (!dependencies.isEmpty())
{
toml.append("\n[dependencies]\n");
dependencies.forEach((id, version) -> toml.append(id).append(" = ").append(GenerateModDescriptor.string(version)).append('\n'));
dependencies.forEach((id, version) -> toml.append(GenerateModDescriptor.string(id)).append(" = ").append(GenerateModDescriptor.string(version)).append('\n'));
}
return toml.toString();
@@ -110,6 +110,18 @@ public abstract class GenerateModDescriptor extends DefaultTask
private static String list(List<String> values) { return values.stream().map(GenerateModDescriptor::string).collect(Collectors.joining(", ", "[", "]")); }
/** A TOML basic string. */
private static String string(String value) { return "\"" + value.replace("\\", "\\\\").replace("\"", "\\\"") + "\""; }
/** A TOML basic string, also used for keys: backslashes, quotes, and control characters are escaped. */
private static String string(String value)
{
StringBuilder escaped = new StringBuilder("\"");
for (char c : value.toCharArray())
{
if (c == '\\' || c == '"') escaped.append('\\').append(c);
else if (c < 0x20 || c == 0x7F) escaped.append(String.format("\\u%04X", (int) c));
else escaped.append(c);
}
return escaped.append('"').toString();
}
}
@@ -177,7 +177,7 @@ class ZomboidForgeModPluginTest
String toml = new String(jar.getInputStream(jar.getEntry("META-INF/zomboidforge/mod.toml")).readAllBytes(), StandardCharsets.UTF_8);
assertTrue(toml.contains("game = [\"42.21\"]"), toml);
assertTrue(toml.contains("[dependencies]\neconomy = \"2.0\""), toml);
assertTrue(toml.contains("[dependencies]\n\"economy\" = \"2.0\""), toml);
}
}
@@ -207,6 +207,22 @@ class ZomboidForgeModPluginTest
assertTrue(result.getOutput().contains("is written by hand; the ZomboidForge plugin generates mod.toml from zomboidForge { }."), result.getOutput());
}
@Test
void writesAnyTextAsValidToml() throws IOException
{
this.modProject("""
name = "Shop\\tMod \\"one\\""
dependsOn("eco.nomy", "2.0")
""", "");
BuildResult result = this.runner("build").buildAndFail();
assertTrue(result.getOutput().contains("'dependencies' contains 'eco.nomy', which is not a valid mod id."), result.getOutput());
String toml = Files.readString(this.project.resolve("build/generated/zomboidforge/descriptor/META-INF/zomboidforge/mod.toml"));
assertTrue(toml.contains("name = \"Shop\\u0009Mod \\\"one\\\"\""), toml);
}
@Test
void failsWhenTheEntryPointIsMissing() throws IOException
{