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

Re-enable functional tests #38

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
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,141 +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

@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 << """
rootProject.name = 'test-project'
plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.4.0'
}
"""
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 << """
rootProject.name = 'test-project'
plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.4.0'
}
"""
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.contains('BUILD SUCCESSFUL')
}

def "the userdev runtime by default supports the build cache"() {
given:
settingsFile << """
rootProject.name = 'test-project'
plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.4.0'
}
"""
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
}
}