aboutsummaryrefslogtreecommitdiff
path: root/src/test/groovy/net/fabricmc/loom
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2021-04-04 19:30:51 +0800
committershedaniel <daniel@shedaniel.me>2021-04-04 19:30:51 +0800
commitad1754a932ef0c6b2134f5d717f6e55f692d85ee (patch)
treee46d6f443b4b68698d494dc5de4aec71a0f74bd2 /src/test/groovy/net/fabricmc/loom
parent8bf5870c7f2d2cae6efe79ea46230e633db1e9c3 (diff)
parent98731532d57d31e3084ef932cce2435d872772c2 (diff)
downloadarchitectury-loom-ad1754a932ef0c6b2134f5d717f6e55f692d85ee.tar.gz
architectury-loom-ad1754a932ef0c6b2134f5d717f6e55f692d85ee.tar.bz2
architectury-loom-ad1754a932ef0c6b2134f5d717f6e55f692d85ee.zip
Merge remote-tracking branch 'FabricMC/dev/0.7' into dev/0.7-forge
# Conflicts: # .github/workflows/test-push.yml # build.gradle # src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java # src/main/java/net/fabricmc/loom/configuration/ide/RunConfig.java # src/main/java/net/fabricmc/loom/configuration/providers/MinecraftProvider.java # src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingsProvider.java # src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftMappedProvider.java # src/main/java/net/fabricmc/loom/configuration/providers/minecraft/assets/MinecraftAssetsProvider.java # src/main/java/net/fabricmc/loom/decompilers/fernflower/AbstractFernFlowerDecompiler.java # src/main/java/net/fabricmc/loom/decompilers/fernflower/ForkingJavaExec.java # src/main/java/net/fabricmc/loom/task/RemapJarTask.java # src/main/java/net/fabricmc/loom/util/GroovyXmlUtil.java # src/main/java/net/fabricmc/loom/util/HashedDownloadUtil.java # src/test/groovy/net/fabricmc/loom/BuildUtils.groovy
Diffstat (limited to 'src/test/groovy/net/fabricmc/loom')
-rw-r--r--src/test/groovy/net/fabricmc/loom/BuildUtils.groovy211
-rw-r--r--src/test/groovy/net/fabricmc/loom/EmptyBuildFunctionalTest.groovy51
-rw-r--r--src/test/groovy/net/fabricmc/loom/EmptyBuildMojangFunctionalTest.groovy50
-rw-r--r--src/test/groovy/net/fabricmc/loom/MixinBuildFunctionalTest.groovy69
-rw-r--r--src/test/groovy/net/fabricmc/loom/SimpleBuildFunctionalTest.groovy62
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/intergration/AccessWidenerTest.groovy56
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/intergration/DecompileTest.groovy54
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/intergration/KotlinTest.groovy50
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/intergration/LegacyProjectTest.groovy47
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/intergration/MavenProjectTest.groovy98
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/intergration/MojangMappingsProjectTest.groovy50
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/intergration/MultiProjectTest.groovy61
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/intergration/ReproducibleBuildTest.groovy64
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/intergration/RunConfigTest.groovy54
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/intergration/SimpleProjectTest.groovy63
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/intergration/UnpickTest.groovy62
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/unit/GroovyXmlUtilTest.groovy74
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/util/ArchiveAssertionsTrait.groovy46
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/util/MockMavenServerTrait.groovy91
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/util/ProjectTestTrait.groovy123
20 files changed, 993 insertions, 443 deletions
diff --git a/src/test/groovy/net/fabricmc/loom/BuildUtils.groovy b/src/test/groovy/net/fabricmc/loom/BuildUtils.groovy
deleted file mode 100644
index e7ac743e..00000000
--- a/src/test/groovy/net/fabricmc/loom/BuildUtils.groovy
+++ /dev/null
@@ -1,211 +0,0 @@
-package net.fabricmc.loom
-
-import net.fabricmc.loom.util.Constants
-
-/**
- * Created by Mitchell Skaggs on 6/12/2019.
- */
-static String genBuildFile(String mappingsDep = "\"net.fabricmc:yarn:\${project.yarn_mappings}\"", String pluginId = Constants.PLUGIN_ID) {
- """
-plugins {
- id '${pluginId}'
- id 'maven-publish'
-}
-sourceCompatibility = JavaVersion.VERSION_1_8
-targetCompatibility = JavaVersion.VERSION_1_8
-
-archivesBaseName = project.archives_base_name
-version = project.mod_version
-group = project.maven_group
-
-
-minecraft {
-}
-
-dependencies {
- //to change the versions see the gradle.properties file
- minecraft "com.mojang:minecraft:\${project.minecraft_version}"
- mappings ${mappingsDep}
- modImplementation "net.fabricmc:fabric-loader:\${project.loader_version}"
-
- // Fabric API. This is technically optional, but you probably want it anyway.
- modImplementation "net.fabricmc.fabric-api:fabric-api:\${project.fabric_version}"
-
- // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
- // You may need to force-disable transitiveness on them.
-}
-
-processResources {
- inputs.property "version", project.version
-
- filesMatching("fabric.mod.json") {
- expand "version": project.version
- }
-}
-
-// ensure that the encoding is set to UTF-8, no matter what the system default is
-// this fixes some edge cases with special characters not displaying correctly
-// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
-tasks.withType(JavaCompile) {
- options.encoding = "UTF-8"
-}
-
-// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
-// if it is present.
-// If you remove this task, sources will not be generated.
-task sourcesJar(type: Jar, dependsOn: classes) {
- classifier = "sources"
- from sourceSets.main.allSource
-}
-
-jar {
- from "LICENSE"
-}
-
-// configure the maven publication
-publishing {
- publications {
- mavenJava(MavenPublication) {
- // add all the jars that should be included when publishing to maven
- artifact(jar) {
- builtBy remapJar
- }
- artifact(sourcesJar) {
- builtBy remapSourcesJar
- }
- }
- }
-
- // select the repositories you want to publish to
- repositories {
- // uncomment to publish to the local maven
- // mavenLocal()
- }
-}
-"""
-}
-
-static String genPropsFile(String mcVersion, String yarnVersion, String loaderVersion, String fabricVersion, boolean caching = true, boolean parallel = true) {
- """
-org.gradle.caching=$caching
-org.gradle.parallel=$parallel
-
-# Fabric Properties
-# check these on https://fabricmc.net/use
-minecraft_version=$mcVersion
-yarn_mappings=$yarnVersion
-loader_version=$loaderVersion
-
-# Mod Properties
-mod_version = 1.0.0
-maven_group = net.fabricmc
-archives_base_name = fabric-example-mod
-
-# Dependencies
-# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric
-fabric_version=$fabricVersion
-"""
-}
-
-static String genSettingsFile(String name) {
- """
-rootProject.name = '$name'
-"""
-}
-
-static String genModJsonFile() {
- """
-{
- "schemaVersion": 1,
- "id": "modid",
- "version": "\${version}",
-
- "name": "Example Mod",
- "description": "This is an example description! Tell everyone what your mod is about!",
- "authors": [
- "Me!"
- ],
- "contact": {
- "homepage": "https://fabricmc.net/",
- "sources": "https://github.com/FabricMC/fabric-example-mod"
- },
-
- "license": "CC0-1.0",
-
- "environment": "*",
- "entrypoints": {
- "main": [
- "net.fabricmc.example.ExampleMod"
- ]
- },
- "mixins": [
- "modid.mixins.json"
- ],
-
- "depends": {
- "fabricloader": ">=0.4.0",
- "fabric": "*"
- },
- "suggests": {
- "flamingo": "*"
- }
-}
-"""
-}
-
-static String genModJavaFile() {
- """
-package net.fabricmc.example;
-
-import net.fabricmc.api.ModInitializer;
-
-public class ExampleMod implements ModInitializer {
- @Override
- public void onInitialize() {
- // This code runs as soon as Minecraft is in a mod-load-ready state.
- // However, some things (like resources) may still be uninitialized.
- // Proceed with mild caution.
-
- System.out.println("Hello Fabric world!");
- }
-}
-"""
-}
-
-static String genModMixinsJsonFile() {
- """
-{
- "required": true,
- "package": "net.fabricmc.example.mixin",
- "compatibilityLevel": "JAVA_8",
- "mixins": [
- ],
- "client": [
- "ExampleMixin"
- ],
- "injectors": {
- "defaultRequire": 1
- }
-}
-"""
-}
-
-static String genModMixinsJavaFile() {
- """
-package net.fabricmc.example.mixin;
-
-import net.minecraft.client.MinecraftClient;
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
-
-@Mixin(MinecraftClient.class)
-public class ExampleMixin {
- @Inject(at = @At("HEAD"), method = "init()V")
- private void init(CallbackInfo info) {
- System.out.println("This line is printed by an example mod mixin!");
- }
-}
-"""
-}
diff --git a/src/test/groovy/net/fabricmc/loom/EmptyBuildFunctionalTest.groovy b/src/test/groovy/net/fabricmc/loom/EmptyBuildFunctionalTest.groovy
deleted file mode 100644
index 996ab656..00000000
--- a/src/test/groovy/net/fabricmc/loom/EmptyBuildFunctionalTest.groovy
+++ /dev/null
@@ -1,51 +0,0 @@
-package net.fabricmc.loom
-
-import org.gradle.testkit.runner.GradleRunner
-import org.junit.Rule
-import org.junit.rules.TemporaryFolder
-import spock.lang.Specification
-import spock.lang.Unroll
-
-import static net.fabricmc.loom.BuildUtils.*
-import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
-
-/**
- * Created by Mitchell Skaggs on 6/10/2019.
- */
-class EmptyBuildFunctionalTest extends Specification {
- @Rule
- TemporaryFolder testProjectDir = new TemporaryFolder()
- File settingsFile
- File buildFile
- File propsFile
-
- def setup() {
- settingsFile = testProjectDir.newFile('settings.gradle')
- buildFile = testProjectDir.newFile('build.gradle')
- propsFile = testProjectDir.newFile('gradle.properties')
- }
-
- @Unroll
- def "empty build succeeds using Minecraft #mcVersion"() {
- given:
- settingsFile << genSettingsFile("empty-build-functional-test")
- propsFile << genPropsFile(mcVersion, yarnVersion, loaderVersion, fabricVersion)
- buildFile << genBuildFile()
-
- when:
- def result = GradleRunner.create()
- .withProjectDir(testProjectDir.root)
- .withArguments('build',"--stacktrace", "--warning-mode", System.getenv().TEST_WARNING_MODE ?: 'all')
- .withPluginClasspath()
- .forwardOutput()
- .build()
-
- then:
- result.task(":build").outcome == SUCCESS
-
- where:
- mcVersion | yarnVersion | loaderVersion | fabricVersion
- '1.14' | '1.14+build.21' | '0.4.8+build.155' | '0.3.0+build.183'
- '1.16.2' | '1.16.2+build.26:v2' | '0.9.2+build.206' | '0.19.0+build.398-1.16'
- }
-}
diff --git a/src/test/groovy/net/fabricmc/loom/EmptyBuildMojangFunctionalTest.groovy b/src/test/groovy/net/fabricmc/loom/EmptyBuildMojangFunctionalTest.groovy
deleted file mode 100644
index d360ba6f..00000000
--- a/src/test/groovy/net/fabricmc/loom/EmptyBuildMojangFunctionalTest.groovy
+++ /dev/null
@@ -1,50 +0,0 @@
-package net.fabricmc.loom
-
-import org.gradle.testkit.runner.GradleRunner
-import org.junit.Rule
-import org.junit.rules.TemporaryFolder
-import spock.lang.Specification
-import spock.lang.Unroll
-
-import static net.fabricmc.loom.BuildUtils.*
-import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
-
-/**
- * Created by Mitchell Skaggs on 6/10/2019.
- */
-class EmptyBuildMojangFunctionalTest extends Specification {
- @Rule
- TemporaryFolder testProjectDir = new TemporaryFolder()
- File settingsFile
- File buildFile
- File propsFile
-
- def setup() {
- settingsFile = testProjectDir.newFile('settings.gradle')
- buildFile = testProjectDir.newFile('build.gradle')
- propsFile = testProjectDir.newFile('gradle.properties')
- }
-
- @Unroll
- def "empty build succeeds using Minecraft #mcVersion"() {
- given:
- settingsFile << genSettingsFile("empty-build-functional-test")
- propsFile << genPropsFile(mcVersion, "nope", loaderVersion, fabricVersion)
- buildFile << genBuildFile("minecraft.officialMojangMappings()")
-
- when:
- def result = GradleRunner.create()
- .withProjectDir(testProjectDir.root)
- .withArguments('build',"--stacktrace", "--warning-mode", System.getenv().TEST_WARNING_MODE ?: 'all')
- .withPluginClasspath()
- .forwardOutput()
- .build()
-
- then:
- result.task(":build").outcome == SUCCESS
-
- where:
- mcVersion | loaderVersion | fabricVersion
- '1.16.2' | '0.9.2+build.206' | '0.19.0+build.398-1.16'
- }
-}
diff --git a/src/test/groovy/net/fabricmc/loom/MixinBuildFunctionalTest.groovy b/src/test/groovy/net/fabricmc/loom/MixinBuildFunctionalTest.groovy
deleted file mode 100644
index b40a2ba7..00000000
--- a/src/test/groovy/net/fabricmc/loom/MixinBuildFunctionalTest.groovy
+++ /dev/null
@@ -1,69 +0,0 @@
-package net.fabricmc.loom
-
-import org.gradle.testkit.runner.GradleRunner
-import org.junit.Rule
-import org.junit.rules.TemporaryFolder
-import spock.lang.Ignore
-import spock.lang.Specification
-import spock.lang.Unroll
-
-import static net.fabricmc.loom.BuildUtils.*
-import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
-
-/**
- * Created by Mitchell Skaggs on 6/10/2019.
- */
-class MixinBuildFunctionalTest extends Specification {
- @Rule
- TemporaryFolder testProjectDir = new TemporaryFolder()
- File settingsFile
- File buildFile
- File propsFile
- File modJsonFile
- File modJavaFile
- File modMixinsJsonFile
- File modMixinsJavaFile
-
- def setup() {
- settingsFile = testProjectDir.newFile('settings.gradle')
- buildFile = testProjectDir.newFile('build.gradle')
- propsFile = testProjectDir.newFile('gradle.properties')
-
- testProjectDir.newFolder("src", "main", "resources")
- modJsonFile = testProjectDir.newFile('src/main/resources/fabric.mod.json')
- modMixinsJsonFile = testProjectDir.newFile('src/main/resources/modid.mixins.json')
-
- testProjectDir.newFolder("src", "main", "java", "net", "fabricmc", "example")
- modJavaFile = testProjectDir.newFile("src/main/java/net/fabricmc/example/ExampleMod.java")
-
- testProjectDir.newFolder("src", "main", "java", "net", "fabricmc", "example", "mixin")
- modMixinsJavaFile = testProjectDir.newFile("src/main/java/net/fabricmc/example/mixin/ExampleMixin.java")
- }
-
- @Unroll
- def "mixin build succeeds using Minecraft #mcVersion"() {
- given:
- settingsFile << genSettingsFile("mixin-build-functional-test")
- propsFile << genPropsFile(mcVersion, yarnVersion, loaderVersion, fabricVersion)
- buildFile << genBuildFile()
- modJsonFile << genModJsonFile()
- modJavaFile << genModJavaFile()
- modMixinsJsonFile << genModMixinsJsonFile()
- modMixinsJavaFile << genModMixinsJavaFile()
-
- when:
- def result = GradleRunner.create()
- .withProjectDir(testProjectDir.root)
- .withArguments('build','--stacktrace', "--warning-mode", System.getenv().TEST_WARNING_MODE ?: 'all')
- .withPluginClasspath()
- .forwardOutput()
- .build()
-
- then:
- result.task(":build").outcome == SUCCESS
-
- where:
- mcVersion | yarnVersion | loaderVersion | fabricVersion
- '1.14' | '1.14+build.21' | '0.4.8+build.155' | '0.3.0+build.184'
- }
-}
diff --git a/src/test/groovy/net/fabricmc/loom/SimpleBuildFunctionalTest.groovy b/src/test/groovy/net/fabricmc/loom/SimpleBuildFunctionalTest.groovy
deleted file mode 100644
index 756a3faa..00000000
--- a/src/test/groovy/net/fabricmc/loom/SimpleBuildFunctionalTest.groovy
+++ /dev/null
@@ -1,62 +0,0 @@
-package net.fabricmc.loom
-
-import org.gradle.testkit.runner.GradleRunner
-import org.junit.Rule
-import org.junit.rules.TemporaryFolder
-import spock.lang.Specification
-import spock.lang.Unroll
-
-import static net.fabricmc.loom.BuildUtils.*
-import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
-
-/**
- * Created by Mitchell Skaggs on 6/10/2019.
- */
-class SimpleBuildFunctionalTest extends Specification {
- @Rule
- TemporaryFolder testProjectDir = new TemporaryFolder()
- File settingsFile
- File buildFile
- File propsFile
- File modJsonFile
- File modExampleFile
-
- def setup() {
- settingsFile = testProjectDir.newFile('settings.gradle')
- buildFile = testProjectDir.newFile('build.gradle')
- propsFile = testProjectDir.newFile('gradle.properties')
-
- testProjectDir.newFolder("src", "main", "resources")
- modJsonFile = testProjectDir.newFile('src/main/resources/fabric.mod.json')
-
- testProjectDir.newFolder("src", "main", "java", "net", "fabricmc", "example")
- modExampleFile = testProjectDir.newFile("src/main/java/net/fabricmc/example/ExampleMod.java")
- }
-
- @Unroll
- def "simple build succeeds using Minecraft #mcVersion"() {
- given:
- settingsFile << genSettingsFile("simple-build-functional-test")
- propsFile << genPropsFile(mcVersion, yarnVersion, loaderVersion, fabricVersion)
- buildFile << genBuildFile()
- modJsonFile << genModJsonFile()
- modExampleFile << genModJavaFile()
-
- when:
- def result = GradleRunner.create()
- .withProjectDir(testProjectDir.root)
- .withArguments('build',"--stacktrace", "--warning-mode", System.getenv().TEST_WARNING_MODE ?: 'all')
- .withPluginClasspath()
- .forwardOutput()
- .withDebug(true)
- .build()
-
- then:
- result.task(":build").outcome == SUCCESS
-
- where:
- mcVersion | yarnVersion | loaderVersion | fabricVersion
- '19w45a' | '19w45a+build.2:v2' | '0.6.2+build.166' | '0.4.9+build.258-1.15'
- '1.14' | '1.14+build.21' | '0.4.8+build.155' | '0.3.0+build.184'
- }
-}
diff --git a/src/test/groovy/net/fabricmc/loom/test/intergration/AccessWidenerTest.groovy b/src/test/groovy/net/fabricmc/loom/test/intergration/AccessWidenerTest.groovy
new file mode 100644
index 00000000..0cde47a5
--- /dev/null
+++ b/src/test/groovy/net/fabricmc/loom/test/intergration/AccessWidenerTest.groovy
@@ -0,0 +1,56 @@
+/*
+ * This file is part of fabric-loom, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2016, 2017, 2018 FabricMC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.fabricmc.loom.test.intergration
+
+import net.fabricmc.loom.test.util.ArchiveAssertionsTrait
+import net.fabricmc.loom.test.util.ProjectTestTrait
+import spock.lang.Specification
+import spock.lang.Unroll
+
+import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
+
+class AccessWidenerTest extends Specification implements ProjectTestTrait, ArchiveAssertionsTrait {
+ @Override
+ String name() {
+ "accesswidener"
+ }
+
+ @Unroll
+ def "accesswidener (gradle #gradle)"() {
+ when:
+ def result = create("build", gradle)
+ then:
+ result.task(":build").outcome == SUCCESS
+ getArchiveEntry("fabric-example-mod-1.0.0.jar", "modid.accesswidener") == expected().replaceAll('\r', '')
+ where:
+ gradle | _
+ DEFAULT_GRADLE | _
+ PRE_RELEASE_GRADLE | _
+ }
+
+ String expected() {
+ new File("src/test/resources/accesswidener/expected.accesswidener").text
+ }
+}
diff --git a/src/test/groovy/net/fabricmc/loom/test/intergration/DecompileTest.groovy b/src/test/groovy/net/fabricmc/loom/test/intergration/DecompileTest.groovy
new file mode 100644
index 00000000..4e4c182a
--- /dev/null
+++ b/src/test/groovy/net/fabricmc/loom/test/intergration/DecompileTest.groovy
@@ -0,0 +1,54 @@
+/*
+ * This file is part of fabric-loom, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2016, 2017, 2018 FabricMC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.fabricmc.loom.test.intergration
+
+import net.fabricmc.loom.test.util.ProjectTestTrait
+import spock.lang.Specification
+import spock.lang.Unroll
+
+import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
+
+class DecompileTest extends Specification implements ProjectTestTrait {
+ @Override
+ String name() {
+ "decompile"
+ }
+
+ @Unroll
+ def "#decompiler gradle #gradle"() {
+ when:
+ def result = create(task, gradle)
+
+ then:
+ result.task(":${task}").outcome == SUCCESS
+
+ where:
+ decompiler | task | gradle
+ 'fernflower' | "genSources" | DEFAULT_GRADLE
+ 'fernflower' | "genSources" | LEGACY_GRADLE
+ 'fernflower' | "genSources" | PRE_RELEASE_GRADLE
+ 'cfr' | "genSourcesWithExperimentalCfr" | DEFAULT_GRADLE
+ }
+}
diff --git a/src/test/groovy/net/fabricmc/loom/test/intergration/KotlinTest.groovy b/src/test/groovy/net/fabricmc/loom/test/intergration/KotlinTest.groovy
new file mode 100644
index 00000000..a2d2ec03
--- /dev/null
+++ b/src/test/groovy/net/fabricmc/loom/test/intergration/KotlinTest.groovy
@@ -0,0 +1,50 @@
+/*
+ * This file is part of fabric-loom, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2016, 2017, 2018 FabricMC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.fabricmc.loom.test.intergration
+
+import net.fabricmc.loom.test.util.ProjectTestTrait
+import spock.lang.Specification
+import spock.lang.Unroll
+
+import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
+
+class KotlinTest extends Specification implements ProjectTestTrait {
+ @Override
+ String name() {
+ "kotlin"
+ }
+
+ @Unroll
+ def "kotlin build (gradle #gradle)"() {
+ when:
+ def result = create("build", gradle)
+ then:
+ result.task(":build").outcome == SUCCESS
+ where:
+ gradle | _
+ DEFAULT_GRADLE | _
+ PRE_RELEASE_GRADLE | _
+ }
+}
diff --git a/src/test/groovy/net/fabricmc/loom/test/intergration/LegacyProjectTest.groovy b/src/test/groovy/net/fabricmc/loom/test/intergration/LegacyProjectTest.groovy
new file mode 100644
index 00000000..6187f02e
--- /dev/null
+++ b/src/test/groovy/net/fabricmc/loom/test/intergration/LegacyProjectTest.groovy
@@ -0,0 +1,47 @@
+/*
+ * This file is part of fabric-loom, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2016, 2017, 2018 FabricMC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.fabricmc.loom.test.intergration
+
+import net.fabricmc.loom.test.util.ProjectTestTrait
+import spock.lang.Specification
+import spock.lang.Unroll
+
+import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
+
+// This test uses gradle 4.9 and 1.14.4 v1 mappings
+class LegacyProjectTest extends Specification implements ProjectTestTrait {
+ @Override
+ String name() {
+ "legacy"
+ }
+
+ @Unroll
+ def "build"() {
+ when:
+ def result = create("build", LEGACY_GRADLE)
+ then:
+ result.task(":build").outcome == SUCCESS
+ }
+}
diff --git a/src/test/groovy/net/fabricmc/loom/test/intergration/MavenProjectTest.groovy b/src/test/groovy/net/fabricmc/loom/test/intergration/MavenProjectTest.groovy
new file mode 100644
index 00000000..6358b7e4
--- /dev/null
+++ b/src/test/groovy/net/fabricmc/loom/test/intergration/MavenProjectTest.groovy
@@ -0,0 +1,98 @@
+/*
+ * This file is part of fabric-loom, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2016, 2017, 2018 FabricMC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.fabricmc.loom.test.intergration
+
+import net.fabricmc.loom.test.util.ArchiveAssertionsTrait
+import net.fabricmc.loom.test.util.MockMavenServerTrait
+import spock.lang.Specification
+import spock.lang.Stepwise
+import spock.lang.Unroll
+import spock.util.environment.RestoreSystemProperties
+
+import static java.lang.System.setProperty
+import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
+
+/**
+ * This tests publishing a range of versions and then tries to resolve and build against them
+ */
+@Stepwise
+class MavenProjectTest extends Specification implements MockMavenServerTrait, ArchiveAssertionsTrait {
+ @RestoreSystemProperties
+ @Unroll
+ def "publish lib #version #gradle"() {
+ given:
+ setProperty('loom.test.version', version)
+ library = true
+ when:
+ def result = create("publish", gradle)
+ then:
+ result.task(":publish").outcome == SUCCESS
+ hasArchiveEntry("fabric-example-lib-${version}.jar", "net/fabricmc/example/ExampleLib.class")
+ where:
+ version | gradle
+ '1.0.0' | DEFAULT_GRADLE
+ '1.0.0' | PRE_RELEASE_GRADLE
+ '1.1.0' | DEFAULT_GRADLE
+ '1.1.1' | DEFAULT_GRADLE
+ '1.2.0+meta' | DEFAULT_GRADLE
+ '2.0.0-SNAPSHOT' | DEFAULT_GRADLE
+ '2.0.0-SNAPSHOT' | DEFAULT_GRADLE // Publish this twice to give ourselves a bit of a challenge
+ 'master-SNAPSHOT' | DEFAULT_GRADLE
+ }
+
+ @RestoreSystemProperties
+ @Unroll
+ def "resolve #version #gradle"() {
+ given:
+ setProperty('loom.test.resolve', "com.example:fabric-example-lib:${version}")
+ library = false
+ when:
+ def result = create("build", gradle)
+ then:
+ result.task(":build").outcome == SUCCESS
+ hasArchiveEntry("fabric-example-mod-1.0.0.jar", "net/fabricmc/examplemod/ExampleMod.class")
+ where:
+ version | gradle
+ '1.0.0' | DEFAULT_GRADLE
+ '1.0.0' | PRE_RELEASE_GRADLE
+ '1.1.+' | DEFAULT_GRADLE
+ '1.2.0+meta' | DEFAULT_GRADLE
+ '2.0.0-SNAPSHOT' | DEFAULT_GRADLE
+ 'master-SNAPSHOT' | DEFAULT_GRADLE
+ '1.0.0:classifier' | DEFAULT_GRADLE
+ '1.1.+:classifier' | DEFAULT_GRADLE
+ '1.2.0+meta:classifier' | DEFAULT_GRADLE
+ '2.0.0-SNAPSHOT:classifier' | DEFAULT_GRADLE
+ 'master-SNAPSHOT:classifier' | DEFAULT_GRADLE
+ }
+
+ // Set to true when to build and publish the mavenLibrary
+ private boolean library = false
+
+ @Override
+ String name() {
+ library ? "mavenLibrary" : "maven"
+ }
+}
diff --git a/src/test/groovy/net/fabricmc/loom/test/intergration/MojangMappingsProjectTest.groovy b/src/test/groovy/net/fabricmc/loom/test/intergration/MojangMappingsProjectTest.groovy
new file mode 100644
index 00000000..a98fb851
--- /dev/null
+++ b/src/test/groovy/net/fabricmc/loom/test/intergration/MojangMappingsProjectTest.groovy
@@ -0,0 +1,50 @@
+/*
+ * This file is part of fabric-loom, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2016, 2017, 2018 FabricMC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.fabricmc.loom.test.intergration
+
+import net.fabricmc.loom.test.util.ProjectTestTrait
+import spock.lang.Specification
+import spock.lang.Unroll
+
+import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
+
+class MojangMappingsProjectTest extends Specification implements ProjectTestTrait {
+ @Override
+ String name() {
+ "mojangMappings"
+ }
+
+ @Unroll
+ def "build (gradle #gradle)"() {
+ when:
+ def result = create("build", gradle)
+ then:
+ result.task(":build").outcome == SUCCESS
+ where:
+ gradle | _
+ DEFAULT_GRADLE | _
+ PRE_RELEASE_GRADLE | _
+ }
+}
diff --git a/src/test/groovy/net/fabricmc/loom/test/intergration/MultiProjectTest.groovy b/src/test/groovy/net/fabricmc/loom/test/intergration/MultiProjectTest.groovy
new file mode 100644
index 00000000..05317dcc
--- /dev/null
+++ b/src/test/groovy/net/fabricmc/loom/test/intergration/MultiProjectTest.groovy
@@ -0,0 +1,61 @@
+/*
+ * This file is part of fabric-loom, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2016, 2017, 2018 FabricMC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.fabricmc.loom.test.intergration
+
+import net.fabricmc.loom.test.util.ArchiveAssertionsTrait
+import net.fabricmc.loom.test.util.ProjectTestTrait
+import spock.lang.Specification
+import spock.lang.Unroll
+
+import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
+
+class MultiProjectTest extends Specification implements ProjectTestTrait, ArchiveAssertionsTrait {
+ @Override
+ String name() {
+ "multiproject"
+ }
+
+ @Unroll
+ def "build (gradle #gradle)"() {
+ when:
+ def result = create("build", gradle)
+ then:
+ result.task(":build").outcome == SUCCESS
+ result.task(":core:build").outcome == SUCCESS
+ result.task(":example:build").outcome == SUCCESS
+
+ result.task(":remapAllJars").outcome == SUCCESS
+ result.task(":remapAllSources").outcome == SUCCESS
+
+ hasArchiveEntry("multiproject-1.0.0.jar", "META-INF/jars/example-1.0.0.jar")
+ hasArchiveEntry("multiproject-1.0.0.jar", "META-INF/jars/core-1.0.0.jar")
+ hasArchiveEntry("multiproject-1.0.0.jar", "META-INF/jars/fabric-api-base-0.2.1+9354966b7d.jar")
+
+ where:
+ gradle | _
+ DEFAULT_GRADLE | _
+ PRE_RELEASE_GRADLE | _
+ }
+}
diff --git a/src/test/groovy/net/fabricmc/loom/test/intergration/ReproducibleBuildTest.groovy b/src/test/groovy/net/fabricmc/loom/test/intergration/ReproducibleBuildTest.groovy
new file mode 100644
index 00000000..8bcac7b6
--- /dev/null
+++ b/src/test/groovy/net/fabricmc/loom/test/intergration/ReproducibleBuildTest.groovy
@@ -0,0 +1,64 @@
+/*
+ * This file is part of fabric-loom, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2016, 2017, 2018 FabricMC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.fabricmc.loom.test.intergration
+
+import com.google.common.hash.HashCode
+import com.google.common.hash.Hashing
+import com.google.common.io.Files
+import net.fabricmc.loom.test.util.ProjectTestTrait
+import spock.lang.Specification
+import spock.lang.Unroll
+
+import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
+
+class ReproducibleBuildTest extends Specification implements ProjectTestTrait {
+ @Override
+ String name() {
+ "reproducible"
+ }
+
+ @Unroll
+ def "build (gradle #gradle)"() {
+ when:
+ def result = create("build", gradle)
+ then:
+ result.task(":build").outcome == SUCCESS
+ getOutputHash("fabric-example-mod-1.0.0.jar") == modHash
+ getOutputHash("fabric-example-mod-1.0.0-sources.jar") in sourceHash // Done for different line endings.
+ where:
+ gradle | modHash | sourceHash
+ '6.8.3' | "6132ffb4117adb7e258f663110552952" | ["be31766e6cafbe4ae3bca9e35ba63169", "7348b0bd87d36d7ec6f3bca9c2b66062"]
+ '7.0-rc-1' | "6132ffb4117adb7e258f663110552952" | ["be31766e6cafbe4ae3bca9e35ba63169", "7348b0bd87d36d7ec6f3bca9c2b66062"]
+ }
+
+ String getOutputHash(String name) {
+ generateMD5(getOutputFile(name))
+ }
+
+ String generateMD5(File file) {
+ HashCode hash = Files.asByteSource(file).hash(Hashing.md5())
+ return hash.asBytes().encodeHex() as String
+ }
+}
diff --git a/src/test/groovy/net/fabricmc/loom/test/intergration/RunConfigTest.groovy b/src/test/groovy/net/fabricmc/loom/test/intergration/RunConfigTest.groovy
new file mode 100644
index 00000000..6ffb1130
--- /dev/null
+++ b/src/test/groovy/net/fabricmc/loom/test/intergration/RunConfigTest.groovy
@@ -0,0 +1,54 @@
+/*
+ * This file is part of fabric-loom, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2016, 2017, 2018 FabricMC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.fabricmc.loom.test.intergration
+
+import net.fabricmc.loom.test.util.ProjectTestTrait
+import spock.lang.Specification
+import spock.lang.Unroll
+
+import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
+
+// This test runs a mod that exits on mod init
+class RunConfigTest extends Specification implements ProjectTestTrait {
+ @Override
+ String name() {
+ "runconfigs"
+ }
+
+ @Unroll
+ def "#task"() {
+ when:
+ def result = create(task)
+ then:
+ result.task(":${task}").outcome == SUCCESS
+ where:
+ task | _
+ 'runClient' | _
+ 'runServer' | _
+ 'runTestmodClient' | _
+ 'runTestmodServer' | _
+ 'runAutoTestServer' | _
+ }
+}
diff --git a/src/test/groovy/net/fabricmc/loom/test/intergration/SimpleProjectTest.groovy b/src/test/groovy/net/fabricmc/loom/test/intergration/SimpleProjectTest.groovy
new file mode 100644
index 00000000..8be25043
--- /dev/null
+++ b/src/test/groovy/net/fabricmc/loom/test/intergration/SimpleProjectTest.groovy
@@ -0,0 +1,63 @@
+/*
+ * This file is part of fabric-loom, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2016, 2017, 2018 FabricMC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.fabricmc.loom.test.intergration
+
+import net.fabricmc.loom.test.util.ProjectTestTrait
+import spock.lang.Specification
+import spock.lang.Unroll
+
+import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
+
+class SimpleProjectTest extends Specification implements ProjectTestTrait {
+ @Override
+ String name() {
+ "simple"
+ }
+
+ @Unroll
+ def "build (gradle #gradle)"() {
+ when:
+ def result = create("build", gradle)
+ then:
+ result.task(":build").outcome == SUCCESS
+ where:
+ gradle | _
+ DEFAULT_GRADLE | _
+ PRE_RELEASE_GRADLE | _
+ }
+
+ @Unroll
+ def "#ide config generation"() {
+ when:
+ def result = create(ide)
+ then:
+ result.task(":${ide}").outcome == SUCCESS
+ where:
+ ide | _
+ 'idea' | _
+ 'eclipse' | _
+ 'vscode' | _
+ }
+}
diff --git a/src/test/groovy/net/fabricmc/loom/test/intergration/UnpickTest.groovy b/src/test/groovy/net/fabricmc/loom/test/intergration/UnpickTest.groovy
new file mode 100644
index 00000000..da1de2de
--- /dev/null
+++ b/src/test/groovy/net/fabricmc/loom/test/intergration/UnpickTest.groovy
@@ -0,0 +1,62 @@
+/*
+ * This file is part of fabric-loom, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2016, 2017, 2018 FabricMC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.fabricmc.loom.test.intergration
+
+import net.fabricmc.loom.test.util.ProjectTestTrait
+import org.zeroturnaround.zip.ZipUtil
+import spock.lang.Specification
+
+import java.nio.charset.StandardCharsets
+
+import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
+
+class UnpickTest extends Specification implements ProjectTestTrait {
+ static final String MAPPINGS = "21w13a-mapped-net.fabricmc.yarn-21w13a+build.30-v2"
+
+ @Override
+ String name() {
+ "unpick"
+ }
+
+ def "unpick decompile"() {
+ when:
+ def result = create("genSources")
+ then:
+ result.task(":genSources").outcome == SUCCESS
+ getClassSource("net/minecraft/block/CakeBlock.java").contains("Block.DEFAULT_SET_BLOCK_STATE_FLAG")
+ }
+
+ def "unpick build"() {
+ when:
+ def result = create("build")
+ then:
+ result.task(":build").outcome == SUCCESS
+ }
+
+ String getClassSource(String classname, String mappings = MAPPINGS) {
+ File sourcesJar = getGeneratedSources(mappings)
+ return new String(ZipUtil.unpackEntry(sourcesJar, classname), StandardCharsets.UTF_8)
+ }
+}
diff --git a/src/test/groovy/net/fabricmc/loom/test/unit/GroovyXmlUtilTest.groovy b/src/test/groovy/net/fabricmc/loom/test/unit/GroovyXmlUtilTest.groovy
new file mode 100644
index 00000000..4d6353a9
--- /dev/null
+++ b/src/test/groovy/net/fabricmc/loom/test/unit/GroovyXmlUtilTest.groovy
@@ -0,0 +1,74 @@
+/*
+ * This file is part of fabric-loom, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2016, 2017, 2018 FabricMC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.fabricmc.loom.test.unit
+
+import groovy.xml.QName
+import net.fabricmc.loom.util.GroovyXmlUtil
+import spock.lang.Specification
+
+class GroovyXmlUtilTest extends Specification {
+ def "getOrCreateNode finds existing node"() {
+ when:
+ def xmlTree = new XmlParser().parseText(text)
+ def existingNode = xmlTree[innerName]
+ def actualNode = GroovyXmlUtil.getOrCreateNode(xmlTree, innerName)
+
+ then:
+ existingNode.text() == actualNode.text()
+
+ where:
+ innerName | text
+ "bar" | "<foo><bar>inner content to ensure correct</bar></foo>"
+ "dependencies" | "<project xmlns=\"http://maven.apache.org/POM/4.0.0\"><dependencies>inner content to ensure correct</dependencies></project>"
+ }
+
+ def "getOrCreateNode creates a node if needed"() {
+ when:
+ def xmlTree = new XmlParser().parseText(text)
+ def actualNode = GroovyXmlUtil.getOrCreateNode(xmlTree, innerName)
+
+ then:
+ xmlTree[QName.valueOf(actualNode.name().toString())] != null
+
+ where:
+ innerName | text
+ "bar" | "<foo></foo>"
+ "dependencies" | "<project xmlns=\"http://maven.apache.org/POM/4.0.0\"></project>"
+ }
+
+ def "getNode finds existing node"() {
+ when:
+ def xmlTree = new XmlParser().parseText(text)
+ def actualNode = GroovyXmlUtil.getNode(xmlTree, innerName)
+
+ then:
+ actualNode.isPresent()
+
+ where:
+ innerName | text
+ "bar" | "<foo><bar>inner content to ensure correct</bar></foo>"
+ "dependencies" | "<project xmlns=\"http://maven.apache.org/POM/4.0.0\"><dependencies>inner content to ensure correct</dependencies></project>"
+ }
+}
diff --git a/src/test/groovy/net/fabricmc/loom/test/util/ArchiveAssertionsTrait.groovy b/src/test/groovy/net/fabricmc/loom/test/util/ArchiveAssertionsTrait.groovy
new file mode 100644
index 00000000..fa4492fc
--- /dev/null
+++ b/src/test/groovy/net/fabricmc/loom/test/util/ArchiveAssertionsTrait.groovy
@@ -0,0 +1,46 @@
+/*
+ * This file is part of fabric-loom, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2016, 2017, 2018 FabricMC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.fabricmc.loom.test.util
+
+import org.zeroturnaround.zip.ZipUtil
+
+trait ArchiveAssertionsTrait {
+ String getArchiveEntry(String name, String entry, String project = "") {
+ def file = getOutputFile(name, project)
+
+ def bytes = ZipUtil.unpackEntry(file, entry)
+
+ if (bytes == null) {
+ throw new FileNotFoundException("Could not find ${entry} in ${name}")
+ }
+
+ new String(bytes as byte[])
+ }
+
+ boolean hasArchiveEntry(String name, String entry, String project = "") {
+ def file = getOutputFile(name, project)
+ ZipUtil.unpackEntry(file, entry) != null
+ }
+} \ No newline at end of file
diff --git a/src/test/groovy/net/fabricmc/loom/test/util/MockMavenServerTrait.groovy b/src/test/groovy/net/fabricmc/loom/test/util/MockMavenServerTrait.groovy
new file mode 100644
index 00000000..604c1faa
--- /dev/null
+++ b/src/test/groovy/net/fabricmc/loom/test/util/MockMavenServerTrait.groovy
@@ -0,0 +1,91 @@
+/*
+ * This file is part of fabric-loom, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2016, 2017, 2018 FabricMC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.fabricmc.loom.test.util
+
+import io.javalin.Javalin
+import org.apache.commons.io.IOUtils
+
+trait MockMavenServerTrait extends ProjectTestTrait {
+ public final int mavenServerPort = 9876
+ public final File testMavenDir = File.createTempDir()
+ private Javalin server
+
+ @SuppressWarnings('unused')
+ def setupSpec() {
+ println "Maven server path: ${testMavenDir.absolutePath}"
+
+ server = Javalin.create { config ->
+ config.enableDevLogging()
+ }.start(mavenServerPort)
+
+ /**
+ * A very very basic maven server impl, DO NOT copy this and use in production as its not secure
+ */
+ server.get("*") { ctx ->
+ println "GET: " + ctx.path()
+ File file = getMavenPath(ctx.path())
+
+ if (!file.exists()) {
+ ctx.status(404)
+ return
+ }
+
+ ctx.result(file.bytes)
+ }
+
+ server.put("*") { ctx ->
+ println "PUT: " + ctx.path()
+ File file = getMavenPath(ctx.path())
+ file.parentFile.mkdirs()
+
+ file.withOutputStream {
+ IOUtils.copy(ctx.bodyAsInputStream(), it)
+ }
+ }
+ }
+
+ @SuppressWarnings('unused')
+ def setup() {
+ System.setProperty('loom.test.mavenPort', port())
+ }
+
+ @SuppressWarnings('unused')
+ def cleanupSpec() {
+ server.stop()
+ super.cleanupSpec()
+ }
+
+ File getMavenDirectory() {
+ new File(testMavenDir, "maven")
+ }
+
+ File getMavenPath(String path) {
+ new File(getMavenDirectory(), path)
+ }
+
+ String port() {
+ "${mavenServerPort}"
+ }
+} \ No newline at end of file
diff --git a/src/test/groovy/net/fabricmc/loom/test/util/ProjectTestTrait.groovy b/src/test/groovy/net/fabricmc/loom/test/util/ProjectTestTrait.groovy
new file mode 100644
index 00000000..619973e2
--- /dev/null
+++ b/src/test/groovy/net/fabricmc/loom/test/util/ProjectTestTrait.groovy
@@ -0,0 +1,123 @@
+/*
+ * This file is part of fabric-loom, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2016, 2017, 2018 FabricMC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.fabricmc.loom.test.util
+
+import org.gradle.testkit.runner.BuildResult
+import org.gradle.testkit.runner.GradleRunner
+
+trait ProjectTestTrait {
+ final static String LEGACY_GRADLE = "4.9"
+ final static String DEFAULT_GRADLE = "6.8.3"
+ final static String PRE_RELEASE_GRADLE = "7.0-rc-2"
+
+ static File gradleHome = File.createTempDir()
+ File testProjectDir = File.createTempDir()
+
+ abstract String name()
+
+ def copyInputFiles() {
+ println "Project directory: ${testProjectDir}"
+
+ def baseProjectDir = new File("src/test/resources/projects/" + name())
+
+ if (!baseProjectDir.exists()) {
+ throw new FileNotFoundException("Failed to find project directory at:" + baseProjectDir.absolutePath)
+ }
+
+ baseProjectDir.eachFileRecurse { file ->
+ if (file.isDirectory()) {
+ return
+ }
+
+ def path = file.path.replace(baseProjectDir.path, "")
+
+ File tempFile = new File(testProjectDir, path)
+
+ if (tempFile.exists()) {
+ tempFile.delete()
+ }
+
+ tempFile.parentFile.mkdirs()
+ tempFile << file.text
+ }
+
+ // Disable the CI checks to ensure nothing is skipped
+ System.setProperty("fabric.loom.ci", "false")
+ }
+
+ @SuppressWarnings('unused')
+ def cleanup() {
+ // Clean after each test
+ new File(testProjectDir, "build").deleteDir()
+ new File(testProjectDir, ".gradle").deleteDir()
+ }
+
+ @SuppressWarnings('unused')
+ def cleanupSpec() {
+ testProjectDir.deleteDir()
+ gradleHome.deleteDir()
+ }
+
+ BuildResult create(String task, String gradleVersion = DEFAULT_GRADLE) {
+ System.setProperty("fabric.loom.test", "true")
+ copyInputFiles()
+
+ GradleRunner.create()
+ .withProjectDir(testProjectDir)
+ .withArguments(task, "--stacktrace", "--warning-mode", warningMode(gradleVersion), "--gradle-user-home", gradleHomeDirectory(gradleVersion))
+ .withPluginClasspath()
+ .withGradleVersion(gradleVersion)
+ .forwardOutput()
+ .withDebug(true)
+ .build()
+ }
+
+ String warningMode(String gradleVersion) {
+ if (gradleVersion == LEGACY_GRADLE) {
+ return "all"
+ }
+
+ 'fail'
+ }
+
+ String gradleHomeDirectory(String gradleVersion) {
+ // Each gradle version gets its own dir to run on, to ensure that a full run is done.
+ new File(gradleHome, gradleVersion).absolutePath
+ }
+
+ File getOutputFile(String name, String project = "") {
+ def file = new File(testProjectDir, "${project}build/libs/${name}")
+
+ if (!file.exists()) {
+ throw new FileNotFoundException("Could not find ${name} at ${file.absolutePath}")
+ }
+
+ return file
+ }
+
+ File getGeneratedSources(String mappings, String gradleVersion = DEFAULT_GRADLE) {
+ return new File(gradleHomeDirectory(gradleVersion), "caches/fabric-loom/${mappings}/minecraft-${mappings}-sources.jar")
+ }
+} \ No newline at end of file