Add basic MultiProjectTest and a basic RunConfigTest
This should cover most of the main things now.
This commit is contained in:
parent
d1c4082761
commit
e9c7c21ede
20 changed files with 405 additions and 4 deletions
66
src/test/groovy/net/fabricmc/loom/MultiProjectTest.groovy
Normal file
66
src/test/groovy/net/fabricmc/loom/MultiProjectTest.groovy
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* 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
|
||||
|
||||
import net.fabricmc.loom.util.ArchiveAssertionsTrait
|
||||
import net.fabricmc.loom.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 | _
|
||||
'6.8.3' | _
|
||||
'7.0-milestone-2' | _
|
||||
}
|
||||
|
||||
@Override
|
||||
String warningMode(String gradleVersion) {
|
||||
"none" // TODO fix this!
|
||||
}
|
||||
}
|
54
src/test/groovy/net/fabricmc/loom/RunConfigTest.groovy
Normal file
54
src/test/groovy/net/fabricmc/loom/RunConfigTest.groovy
Normal file
|
@ -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
|
||||
|
||||
import net.fabricmc.loom.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' | _
|
||||
}
|
||||
}
|
|
@ -27,8 +27,8 @@ package net.fabricmc.loom.util
|
|||
import org.zeroturnaround.zip.ZipUtil
|
||||
|
||||
trait ArchiveAssertionsTrait extends ProjectTestTrait {
|
||||
String getArchiveEntry(String name, String entry) {
|
||||
def file = getOutputFile(name)
|
||||
String getArchiveEntry(String name, String entry, String project = "") {
|
||||
def file = getOutputFile(name, project)
|
||||
|
||||
def bytes = ZipUtil.unpackEntry(file, entry)
|
||||
|
||||
|
@ -38,4 +38,9 @@ trait ArchiveAssertionsTrait extends ProjectTestTrait {
|
|||
|
||||
new String(bytes as byte[])
|
||||
}
|
||||
|
||||
boolean hasArchiveEntry(String name, String entry, String project = "") {
|
||||
def file = getOutputFile(name, project)
|
||||
ZipUtil.unpackEntry(file, entry) != null
|
||||
}
|
||||
}
|
|
@ -96,8 +96,8 @@ trait ProjectTestTrait {
|
|||
new File(gradleHome, gradleVersion).absolutePath
|
||||
}
|
||||
|
||||
File getOutputFile(String name) {
|
||||
def file = new File(testProjectDir, "build/libs/" + name)
|
||||
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}")
|
||||
|
|
63
src/test/resources/projects/multiproject/build.gradle
Normal file
63
src/test/resources/projects/multiproject/build.gradle
Normal file
|
@ -0,0 +1,63 @@
|
|||
plugins {
|
||||
id "java"
|
||||
id "java-library"
|
||||
id 'fabric-loom' apply false
|
||||
}
|
||||
|
||||
allprojects {
|
||||
apply plugin: "fabric-loom"
|
||||
|
||||
version = "1.0.0"
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
def targetVersion = 8
|
||||
if (JavaVersion.current().isJava9Compatible()) {
|
||||
it.options.release = targetVersion
|
||||
} else {
|
||||
sourceCompatibility = JavaVersion.toVersion(targetVersion)
|
||||
targetCompatibility = JavaVersion.toVersion(targetVersion)
|
||||
}
|
||||
|
||||
it.options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// To change the versions see the gradle.properties file
|
||||
minecraft "com.mojang:minecraft:1.16.5"
|
||||
mappings "net.fabricmc:yarn:1.16.5+build.5:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:0.11.2"
|
||||
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:0.31.0+1.16"
|
||||
|
||||
}
|
||||
|
||||
configurations {
|
||||
dev
|
||||
}
|
||||
|
||||
jar {
|
||||
archiveClassifier.set "dev"
|
||||
}
|
||||
|
||||
loom {
|
||||
shareCaches = true
|
||||
}
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
afterEvaluate {
|
||||
subprojects.each {
|
||||
include project("${it.name}:")
|
||||
}
|
||||
}
|
||||
|
||||
include fabricApi.module("fabric-api-base", "0.31.0+1.16")
|
||||
}
|
||||
|
||||
archivesBaseName = "multiproject"
|
||||
version = "1.0.0"
|
|
@ -0,0 +1 @@
|
|||
archivesBaseName = "core"
|
|
@ -0,0 +1,14 @@
|
|||
package net.fabricmc.core;
|
||||
|
||||
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!");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"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.core.ExampleMod"
|
||||
]
|
||||
},
|
||||
|
||||
"depends": {
|
||||
"fabricloader": ">=0.7.4",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.16.x"
|
||||
},
|
||||
"suggests": {
|
||||
"another-mod": "*"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
archivesBaseName = "example"
|
||||
|
||||
dependencies {
|
||||
implementation project(path: ":core", configuration: "dev")
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
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!");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package net.fabricmc.example.mixin;
|
||||
|
||||
import net.minecraft.client.gui.screen.TitleScreen;
|
||||
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(TitleScreen.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!");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"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.7.4",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.16.x"
|
||||
},
|
||||
"suggests": {
|
||||
"another-mod": "*"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "net.fabricmc.example.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [
|
||||
],
|
||||
"client": [
|
||||
"ExampleMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
17
src/test/resources/projects/multiproject/gradle.properties
Normal file
17
src/test/resources/projects/multiproject/gradle.properties
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Done to increase the memory available to gradle.
|
||||
org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/use
|
||||
minecraft_version=1.16.5
|
||||
yarn_mappings=1.16.5+build.5
|
||||
loader_version=0.11.2
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.0.0
|
||||
maven_group = com.example
|
||||
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-api/fabric-api
|
||||
fabric_version=0.31.0+1.16
|
4
src/test/resources/projects/multiproject/settings.gradle
Normal file
4
src/test/resources/projects/multiproject/settings.gradle
Normal file
|
@ -0,0 +1,4 @@
|
|||
rootProject.name = "fabric-example-mod"
|
||||
|
||||
include 'core'
|
||||
include 'example'
|
33
src/test/resources/projects/runconfigs/build.gradle
Normal file
33
src/test/resources/projects/runconfigs/build.gradle
Normal file
|
@ -0,0 +1,33 @@
|
|||
plugins {
|
||||
id 'fabric-loom'
|
||||
}
|
||||
|
||||
loom {
|
||||
runs {
|
||||
testmodClient {
|
||||
client()
|
||||
ideConfigGenerated project.rootProject == project
|
||||
name = "Testmod Client"
|
||||
source sourceSets.main
|
||||
}
|
||||
testmodServer {
|
||||
server()
|
||||
ideConfigGenerated project.rootProject == project
|
||||
name = "Testmod Server"
|
||||
source sourceSets.main
|
||||
}
|
||||
autoTestServer {
|
||||
inherit testmodServer
|
||||
vmArg "-Dfabric.autoTest"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
archivesBaseName = "fabric-example-mod"
|
||||
version = "1.0.0"
|
||||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:1.16.5"
|
||||
mappings "net.fabricmc:yarn:1.16.5+build.5:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:0.11.2"
|
||||
}
|
1
src/test/resources/projects/runconfigs/gradle.properties
Normal file
1
src/test/resources/projects/runconfigs/gradle.properties
Normal file
|
@ -0,0 +1 @@
|
|||
org.gradle.jvmargs=-Xmx1G
|
2
src/test/resources/projects/runconfigs/settings.gradle
Normal file
2
src/test/resources/projects/runconfigs/settings.gradle
Normal file
|
@ -0,0 +1,2 @@
|
|||
rootProject.name = "fabric-example-mod"
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package net.fabricmc.example;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
|
||||
public class ExampleMod implements ModInitializer {
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
System.out.println("Hello Fabric world!");
|
||||
|
||||
// Quit now, we dont need to load the whole game to know the run configs are works
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "modid",
|
||||
"version": "1.0.0",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"net.fabricmc.example.ExampleMod"
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue