-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump trainingwheels and port the tests to the builder pattern.
- Loading branch information
Showing
3 changed files
with
52 additions
and
87 deletions.
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
129 changes: 47 additions & 82 deletions
129
userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/FunctionalTests.groovy
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 |
---|---|---|
@@ -1,143 +1,108 @@ | ||
package net.neoforged.gradle.userdev | ||
|
||
import net.neoforged.trainingwheels.gradle.functional.SimpleTestSpecification | ||
import net.neoforged.trainingwheels.gradle.functional.BuilderBasedTestSpecification | ||
import net.neoforged.trainingwheels.gradle.functional.builder.Runtime | ||
import org.gradle.testkit.runner.TaskOutcome | ||
import spock.lang.Ignore | ||
|
||
class FunctionalTests extends SimpleTestSpecification { | ||
class FunctionalTests extends BuilderBasedTestSpecification { | ||
|
||
protected File codeFile | ||
private static final String NEOFORGE_VERSION = "20.2.43-beta" | ||
|
||
@Override | ||
def setup() { | ||
codeFile = new File(testProjectDir, 'src/main/java/net/minecraftforge/gradle/userdev/FunctionalTests.java') | ||
codeFile.getParentFile().mkdirs() | ||
protected void configurePluginUnderTest() { | ||
pluginUnderTest = "net.neoforged.gradle.userdev" | ||
injectIntoAllProject = true | ||
} | ||
|
||
def "a mod with userdev as dependency can run the patch task for that dependency"() { | ||
def "a mod with userdev: as dependency can run the recompile task for that dependency"() { | ||
given: | ||
settingsFile.text = """ | ||
plugins { | ||
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.4.0' | ||
} | ||
${settingsFile.text} | ||
rootProject.name = 'test-project' | ||
""" | ||
buildFile << """ | ||
plugins { | ||
id 'net.neoforged.gradle.userdev' | ||
} | ||
def project = create "test-project", { | ||
it.build(""" | ||
java { | ||
toolchain { | ||
languageVersion = JavaLanguageVersion.of(17) | ||
} | ||
} | ||
dependencies { | ||
implementation 'net.neoforged:neoforge:+' | ||
implementation 'net.neoforged:neoforge:${NEOFORGE_VERSION}' | ||
} | ||
""" | ||
""") | ||
it.withToolchains() | ||
} | ||
|
||
when: | ||
def result = gradleRunner() | ||
.withArguments('--stacktrace', 'neoFormRecompile') | ||
.build() | ||
def run = project.run { it.log(Runtime.LogLevel.INFO).tasks(':neoFormRecompile') } | ||
|
||
then: | ||
result.output.contains('BUILD SUCCESSFUL') | ||
run.task(':neoFormRecompile').outcome == TaskOutcome.SUCCESS | ||
} | ||
|
||
def "a mod with userdev as dependency and official mappings can compile through gradle"() { | ||
given: | ||
settingsFile.text = """ | ||
plugins { | ||
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.4.0' | ||
} | ||
${settingsFile.text} | ||
rootProject.name = 'test-project' | ||
""" | ||
buildFile << """ | ||
plugins { | ||
id 'net.neoforged.gradle.userdev' | ||
} | ||
def project = create "test-project", { | ||
it.build(""" | ||
java { | ||
toolchain { | ||
languageVersion = JavaLanguageVersion.of(17) | ||
} | ||
} | ||
dependencies { | ||
implementation 'net.neoforged:neoforge:+' | ||
implementation 'net.neoforged:neoforge:${NEOFORGE_VERSION}' | ||
} | ||
""" | ||
codeFile << """ | ||
package net.neoforged.gradle.mcp; | ||
import net.minecraft.client.Minecraft; | ||
public class FunctionalTests { | ||
public static void main(String[] args) { | ||
System.out.println(Minecraft.getInstance().getClass().toString()); | ||
""") | ||
it.withToolchains() | ||
|
||
it.file("src/main/java/net/minecraftforge/gradle/userdev/FunctionalTests.java", """ | ||
package net.neoforged.gradle.mcp; | ||
import net.minecraft.client.Minecraft; | ||
public class FunctionalTests { | ||
public static void main(String[] args) { | ||
System.out.println(Minecraft.getInstance().getClass().toString()); | ||
} | ||
} | ||
} | ||
""" | ||
""") | ||
} | ||
|
||
when: | ||
def result = runTask('build') | ||
def run = project.run { it.tasks('build') } | ||
|
||
then: | ||
result.output.contains('BUILD SUCCESSFUL') | ||
run.output.output.contains('BUILD SUCCESSFUL') | ||
} | ||
|
||
def "the userdev runtime by default supports the build cache"() { | ||
given: | ||
settingsFile.text = """ | ||
plugins { | ||
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.4.0' | ||
} | ||
${settingsFile.text} | ||
rootProject.name = 'test-project' | ||
""" | ||
buildFile << """ | ||
plugins { | ||
id 'net.neoforged.gradle.userdev' | ||
} | ||
def project = create "test-project", { | ||
it.build(""" | ||
java { | ||
toolchain { | ||
languageVersion = JavaLanguageVersion.of(17) | ||
} | ||
} | ||
dependencies { | ||
implementation 'net.neoforged:neoforge:+' | ||
implementation 'net.neoforged:neoforge:${NEOFORGE_VERSION}' | ||
} | ||
""" | ||
codeFile << """ | ||
package net.neoforged.gradle.mcp; | ||
import net.minecraft.client.Minecraft; | ||
public class FunctionalTests { | ||
public static void main(String[] args) { | ||
System.out.println(Minecraft.getInstance().getClass().toString()); | ||
} | ||
} | ||
""" | ||
""") | ||
it.withToolchains() | ||
it.enableLocalBuildCache() | ||
} | ||
|
||
when: | ||
def result = runTask('--build-cache', 'build') | ||
def run = project.run { it.arguments("--build-cache").tasks('build') } | ||
|
||
then: | ||
result.task(":neoFormRecompile").outcome == TaskOutcome.SUCCESS | ||
run.task(":neoFormRecompile").outcome == TaskOutcome.SUCCESS | ||
|
||
when: | ||
new File(testProjectDir, 'build').deleteDir() | ||
result = runTask('--build-cache', 'build') | ||
new File(project.projectDir, 'build').deleteDir() | ||
run = project.run { it.arguments("--build-cache").tasks('build') } | ||
|
||
then: | ||
result.task(":neoFormRecompile").outcome == TaskOutcome.FROM_CACHE | ||
run.task(":neoFormRecompile").outcome == TaskOutcome.FROM_CACHE | ||
} | ||
} |