-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/test/java/net/neoforged/moddevgradle/functional/GroovyScriptTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package net.neoforged.moddevgradle.functional; | ||
|
||
import org.gradle.testkit.runner.BuildResult; | ||
import org.gradle.testkit.runner.GradleRunner; | ||
import org.gradle.testkit.runner.TaskOutcome; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class GroovyScriptTest { | ||
@TempDir | ||
File testProjectDir; | ||
private File settingsFile; | ||
private File buildFile; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
settingsFile = new File(testProjectDir, "settings.gradle"); | ||
buildFile = new File(testProjectDir, "build.gradle"); | ||
} | ||
|
||
@Test | ||
public void testApplyInEmptyProject() throws IOException { | ||
writeFile(settingsFile, "rootProject.name = 'hello-world'"); | ||
String buildFileContent = """ | ||
plugins { | ||
id "net.neoforged.moddev" | ||
} | ||
"""; | ||
writeFile(buildFile, buildFileContent); | ||
|
||
BuildResult result = GradleRunner.create() | ||
.withPluginClasspath() | ||
.withProjectDir(testProjectDir) | ||
.withArguments("tasks", "--all") | ||
.build(); | ||
|
||
assertThat(result.getOutput()).contains("createMinecraftArtifacts"); | ||
assertEquals(TaskOutcome.SUCCESS, result.task(":tasks").getOutcome()); | ||
} | ||
|
||
private void writeFile(File destination, String content) throws IOException { | ||
BufferedWriter output = null; | ||
try { | ||
output = new BufferedWriter(new FileWriter(destination)); | ||
output.write(content); | ||
} finally { | ||
if (output != null) { | ||
output.close(); | ||
} | ||
} | ||
|
||
|
||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/test/java/net/neoforged/moddevgradle/functional/KotlinScriptTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package net.neoforged.moddevgradle.functional; | ||
|
||
import org.gradle.testkit.runner.BuildResult; | ||
import org.gradle.testkit.runner.GradleRunner; | ||
import org.gradle.testkit.runner.TaskOutcome; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class KotlinScriptTest { | ||
@TempDir | ||
File testProjectDir; | ||
private File settingsFile; | ||
private File buildFile; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
settingsFile = new File(testProjectDir, "settings.gradle.kts"); | ||
buildFile = new File(testProjectDir, "build.gradle.kts"); | ||
} | ||
|
||
@Test | ||
public void testApplyInEmptyProject() throws IOException { | ||
writeFile(settingsFile, """ | ||
rootProject.name = "hello-world"; | ||
"""); | ||
String buildFileContent = """ | ||
plugins { | ||
id("net.neoforged.moddev") | ||
} | ||
"""; | ||
writeFile(buildFile, buildFileContent); | ||
|
||
BuildResult result = GradleRunner.create() | ||
.withPluginClasspath() | ||
.withProjectDir(testProjectDir) | ||
.withArguments("tasks", "--all") | ||
.build(); | ||
|
||
assertThat(result.getOutput()).contains("createMinecraftArtifacts"); | ||
assertEquals(TaskOutcome.SUCCESS, result.task(":tasks").getOutcome()); | ||
} | ||
|
||
private void writeFile(File destination, String content) throws IOException { | ||
BufferedWriter output = null; | ||
try { | ||
output = new BufferedWriter(new FileWriter(destination)); | ||
output.write(content); | ||
} finally { | ||
if (output != null) { | ||
output.close(); | ||
} | ||
} | ||
|
||
|
||
} | ||
} |