Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to test and IDE runs #1252

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,14 @@ public interface GameTestSettings {
* <p>Default: true
*/
Property<Boolean> getClearRunDirectory();

/**
* Contains a string property representing the username to use for the client side game tests.
*
* <p>This only works when {@link #getEnableClientGameTests()} is enabled.
*
* <p>Default: Player0
*/
@Optional
Property<String> getUsername();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package net.fabricmc.loom.configuration.fabricapi;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -36,6 +37,7 @@
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.Delete;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.TaskContainer;

Expand All @@ -45,6 +47,7 @@
import net.fabricmc.loom.task.AbstractLoomTask;
import net.fabricmc.loom.task.LoomTasks;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.gradle.SourceSetHelper;

public abstract class FabricApiTesting extends FabricApiAbstractSourceSet {
@Inject
Expand All @@ -62,13 +65,15 @@ protected String getSourceSetName() {
void configureTests(Action<GameTestSettings> action) {
final LoomGradleExtension extension = LoomGradleExtension.get(getProject());
final TaskContainer tasks = getProject().getTasks();
final SourceSet mainSourceSet = SourceSetHelper.getMainSourceSet(getProject());

GameTestSettings settings = getProject().getObjects().newInstance(GameTestSettings.class);
settings.getCreateSourceSet().convention(false);
settings.getEnableGameTests().convention(true);
settings.getEnableClientGameTests().convention(true);
settings.getEula().convention(false);
settings.getClearRunDirectory().convention(true);
settings.getUsername().convention("Player0");

action.execute(settings);

Expand All @@ -94,10 +99,23 @@ void configureTests(Action<GameTestSettings> action) {
}

if (settings.getEnableClientGameTests().get()) {
// Not ideal as there may be multiple resources directories, if this isnt correct the mod will need to override this.
modmuss50 marked this conversation as resolved.
Show resolved Hide resolved
final File resourcesDir = mainSourceSet.getResources().getFiles().stream().findAny().orElse(null);

RunConfigSettings clientGameTest = extension.getRunConfigs().create("clientGameTest", run -> {
run.inherit(extension.getRunConfigs().getByName("client"));
run.property("fabric.client.gametest");

if (resourcesDir != null) {
run.property("fabric.client.gametest.testModResourcesPath", resourcesDir.getAbsolutePath());
}

run.runDir("build/run/clientGameTest");

if (settings.getUsername().isPresent()) {
run.programArgs("--username", settings.getUsername().get());
}

configureBase.accept(run);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ private List<IntelijRunConfig> getRunConfigs() throws IOException {
irc.getExcludedLibraryPaths().set(excludedLibraryPaths);
irc.getLaunchFile().set(runConfigFile);
configs.add(irc);

settings.makeRunDir();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need applying to the other IDE sync tasks?

Also, it doesn't have to be in this PR but it would be good to support pre-run Gradle tasks. I know it's not ideal to run a gradle task before an IDE run but I think it is the least bad of all the ways to clean the run directory for client gametests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this was something I removed/broke in #1166

I strongly oppose running Gradle before IDE runs, its not easy to in intelij and likely impossible in vscode/eclipse, and takes ages. We already clear the run dir before using one of the Gradle tasks, if your tests depend on that disable the IDE runs and solely rely on Gradle, it will be quicke, better supported and doesnt require any gross hacks to make it work.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As dissussed we will do something about this, likely with a new entrypoint but I will do it as its own thing.

}

return configs;
Expand Down
Loading