diff --git a/src/main/java/net/fabricmc/loom/api/fabricapi/GameTestSettings.java b/src/main/java/net/fabricmc/loom/api/fabricapi/GameTestSettings.java index 40082b5d8..5675484ab 100644 --- a/src/main/java/net/fabricmc/loom/api/fabricapi/GameTestSettings.java +++ b/src/main/java/net/fabricmc/loom/api/fabricapi/GameTestSettings.java @@ -40,11 +40,6 @@ public interface GameTestSettings { */ Property getCreateSourceSet(); - /** - * Contains a boolean indicating whether a run configuration should be created for the tests. - */ - Property getCreateRunConfigurations(); - /** * Contains a string property representing the mod ID associated with the tests. * @@ -70,9 +65,18 @@ public interface GameTestSettings { /** * Contains a boolean property indicating whether the eula has been accepted. By enabling this you agree to the Minecraft EULA located at https://aka.ms/MinecraftEULA. * - *

This only works when {@link #getCreateRunConfigurations()} is enabled. + *

This only works when {@link #getEnableClientGameTests()} is enabled. * *

Default: false */ Property getEula(); + + /** + * Contains a boolean property indicating whether the run directories should be cleared before running the tests. + * + *

This only works when {@link #getEnableClientGameTests()} is enabled. + * + *

Default: true + */ + Property getClearRunDirectory(); } diff --git a/src/main/java/net/fabricmc/loom/configuration/fabricapi/FabricApiTesting.java b/src/main/java/net/fabricmc/loom/configuration/fabricapi/FabricApiTesting.java index 9411a388f..c3585db33 100644 --- a/src/main/java/net/fabricmc/loom/configuration/fabricapi/FabricApiTesting.java +++ b/src/main/java/net/fabricmc/loom/configuration/fabricapi/FabricApiTesting.java @@ -34,6 +34,7 @@ import org.gradle.api.Action; import org.gradle.api.Project; import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.tasks.Delete; import org.gradle.api.tasks.OutputFile; import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.TaskContainer; @@ -42,6 +43,8 @@ import net.fabricmc.loom.api.fabricapi.GameTestSettings; import net.fabricmc.loom.configuration.ide.RunConfigSettings; import net.fabricmc.loom.task.AbstractLoomTask; +import net.fabricmc.loom.task.LoomTasks; +import net.fabricmc.loom.util.Constants; public abstract class FabricApiTesting extends FabricApiAbstractSourceSet { @Inject @@ -62,10 +65,10 @@ void configureTests(Action action) { GameTestSettings settings = getProject().getObjects().newInstance(GameTestSettings.class); settings.getCreateSourceSet().convention(false); - settings.getCreateRunConfigurations().convention(true); settings.getEnableGameTests().convention(true); settings.getEnableClientGameTests().convention(true); settings.getEula().convention(false); + settings.getClearRunDirectory().convention(true); action.execute(settings); @@ -73,30 +76,48 @@ void configureTests(Action action) { configureSourceSet(settings.getModId(), true); } - if (settings.getCreateRunConfigurations().get()) { - Consumer configureBase = run -> { - if (settings.getCreateSourceSet().get()) { - run.source(getSourceSetName()); - } - - run.runDir("build/gametest"); - }; + Consumer configureBase = run -> { + if (settings.getCreateSourceSet().get()) { + run.source(getSourceSetName()); + } + }; - extension.getRunConfigs().create("gameTest", run -> { + if (settings.getEnableGameTests().get()) { + RunConfigSettings gameTest = extension.getRunConfigs().create("gameTest", run -> { run.inherit(extension.getRunConfigs().getByName("server")); run.property("fabric-api.gametest"); + run.runDir("build/run/gameTest"); configureBase.accept(run); }); - RunConfigSettings runConfigSettings = extension.getRunConfigs().create("clientGameTest", run -> { + tasks.named("test", task -> task.dependsOn(LoomTasks.getRunConfigTaskName(gameTest))); + } + + if (settings.getEnableClientGameTests().get()) { + RunConfigSettings clientGameTest = extension.getRunConfigs().create("clientGameTest", run -> { run.inherit(extension.getRunConfigs().getByName("client")); run.property("fabric.client.gametest"); + run.runDir("build/run/clientGameTest"); configureBase.accept(run); }); + if (settings.getClearRunDirectory().get()) { + var deleteGameTestRunDir = tasks.register("deleteGameTestRunDir", Delete.class, task -> { + task.setGroup(Constants.TaskGroup.FABRIC); + task.delete(clientGameTest.getRunDir()); + }); + + tasks.named(LoomTasks.getRunConfigTaskName(clientGameTest), task -> task.dependsOn(deleteGameTestRunDir)); + } + if (settings.getEula().get()) { var acceptEula = tasks.register("acceptGameTestEula", AcceptEulaTask.class, task -> { - task.getEulaFile().set(getProject().file(runConfigSettings.getRunDir() + "/eula.txt")); + task.getEulaFile().set(getProject().file(clientGameTest.getRunDir() + "/eula.txt")); + + if (settings.getClearRunDirectory().get()) { + // Ensure that the eula is accepted after the run directory is cleared + task.dependsOn(tasks.named("deleteGameTestRunDir")); + } }); tasks.named("configureLaunch", task -> task.dependsOn(acceptEula)); diff --git a/src/main/java/net/fabricmc/loom/task/LoomTasks.java b/src/main/java/net/fabricmc/loom/task/LoomTasks.java index 44d1b5f64..27ddf5912 100644 --- a/src/main/java/net/fabricmc/loom/task/LoomTasks.java +++ b/src/main/java/net/fabricmc/loom/task/LoomTasks.java @@ -126,7 +126,7 @@ private void registerIDETasks() { }); } - private static String getRunConfigTaskName(RunConfigSettings config) { + public static String getRunConfigTaskName(RunConfigSettings config) { String configName = config.getName(); return "run" + configName.substring(0, 1).toUpperCase() + configName.substring(1); } diff --git a/src/test/groovy/net/fabricmc/loom/test/integration/DataGenerationTest.groovy b/src/test/groovy/net/fabricmc/loom/test/integration/DataGenerationTest.groovy index ce01529cc..9f80f5add 100644 --- a/src/test/groovy/net/fabricmc/loom/test/integration/DataGenerationTest.groovy +++ b/src/test/groovy/net/fabricmc/loom/test/integration/DataGenerationTest.groovy @@ -243,7 +243,7 @@ class DataGenerationTest extends Specification implements GradleProjectTestTrait ''' + DEPENDENCIES when: def result = gradle.run(task: "runClientGameTest") - def eula = new File(gradle.projectDir, "build/gametest/eula.txt") + def eula = new File(gradle.projectDir, "build/run/clientGameTest/eula.txt") then: result.task(":runClientGameTest").outcome == SUCCESS