Skip to content

Commit

Permalink
Bump trainingwheels and port the tests to the builder pattern.
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Nov 9, 2023
1 parent 18f127d commit 0d4fb2b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 87 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ subprojects.forEach { subProject ->
subProject.dependencies.testImplementation "org.mockito:mockito-junit-jupiter:${project.mockito_version}"
subProject.dependencies.testImplementation "org.mockito:mockito-core:${project.mockito_version}"
subProject.dependencies.testImplementation "org.mockito:mockito-inline:${project.mockito_version}"
subProject.dependencies.testImplementation "net.neoforged:TrainingWheels-Base:${project.trainingwheels_version}"
subProject.dependencies.testImplementation "net.neoforged:TrainingWheels-Gradle-Base:${project.trainingwheels_version}"
subProject.dependencies.testImplementation "net.neoforged:TrainingWheels-Gradle-Functional:${project.trainingwheels_version}"
subProject.dependencies.testImplementation "net.neoforged.trainingwheels:trainingwheels-base:${project.trainingwheels_version}"
subProject.dependencies.testImplementation "net.neoforged.trainingwheels:trainingwheels-gradle-base:${project.trainingwheels_version}"
subProject.dependencies.testImplementation "net.neoforged.trainingwheels:trainingwheels-gradle-functional:${project.trainingwheels_version}"

//Exclude duplicates.
subProject.tasks.withType(Jar).configureEach { jarTask ->
Expand Down Expand Up @@ -136,7 +136,7 @@ subprojects.forEach { subProject ->
evalSubProject.dependencies.functionalTestImplementation("org.spockframework:spock-core:${project.spock_version}-groovy-${project.groovy_version}") { spec ->
spec.exclude group: 'org.codehaus.groovy'
}
evalSubProject.dependencies.functionalTestImplementation "net.neoforged:TrainingWheels-Gradle-Functional:${project.trainingwheels_version}"
evalSubProject.dependencies.functionalTestImplementation "net.neoforged.trainingwheels:trainingwheels-gradle-functional:${project.trainingwheels_version}"

//Configure the plugin metadata, so we can publish it.
evalSubProject.gradlePlugin.plugins { NamedDomainObjectContainer<PluginDeclaration> plugins ->
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ spock_version=2.1
spock_groovy_version=3.0
mockito_version=4.11.0
jimfs_version=1.2
trainingwheels_version=1.0.32
trainingwheels_version=1.0.38
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
}
}

0 comments on commit 0d4fb2b

Please sign in to comment.