Add simple integration tests for the plugin

dev/0.11
Mitchell Skaggs 2019-06-10 21:26:04 -05:00
parent 9e690f489f
commit 69df7ed774
No known key found for this signature in database
GPG Key ID: 4EB0FECB84AE8967
2 changed files with 158 additions and 5 deletions

View File

@ -4,6 +4,7 @@ plugins {
id 'java-gradle-plugin' id 'java-gradle-plugin'
id 'idea' id 'idea'
id 'eclipse' id 'eclipse'
id 'groovy'
} }
sourceCompatibility = 1.8 sourceCompatibility = 1.8
@ -54,6 +55,9 @@ dependencies {
// source code remapping // source code remapping
implementation ('org.cadixdev:mercury:0.1.0.fabric-SNAPSHOT') implementation ('org.cadixdev:mercury:0.1.0.fabric-SNAPSHOT')
// Testing
testImplementation(gradleTestKit())
testImplementation("org.spockframework:spock-core:1.3-groovy-2.5")
} }
jar { jar {
@ -78,10 +82,6 @@ license {
exclude '**/loom/util/DownloadUtil.java' exclude '**/loom/util/DownloadUtil.java'
} }
task wrapper(type: Wrapper) {
gradleVersion = '4.10.2'
}
gradlePlugin { gradlePlugin {
plugins { plugins {
register("fabricLoom") { register("fabricLoom") {

View File

@ -0,0 +1,153 @@
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 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 << """
rootProject.name = 'empty-build-functional-test'
"""
propsFile << """
org.gradle.caching=true
org.gradle.parallel=true
# 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
"""
buildFile << """
plugins {
id 'fabric-loom'
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 "net.fabricmc:yarn:\${project.yarn_mappings}"
modCompile "net.fabricmc:fabric-loader:\${project.loader_version}"
// Fabric API. This is technically optional, but you probably want it anyway.
modCompile "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
from(sourceSets.main.resources.srcDirs) {
include "fabric.mod.json"
expand "version": project.version
}
from(sourceSets.main.resources.srcDirs) {
exclude "fabric.mod.json"
}
}
// 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()
}
}
"""
when:
def result = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments('build')
.withPluginClasspath()
.build()
then:
//result.output.contains('Hello world!')
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.14.1' | '1.14.1+build.10' | '0.4.8+build.155' | '0.3.0+build.183'
'1.14.2' | '1.14.2+build.7' | '0.4.8+build.155' | '0.3.0+build.183'
}
}