Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Mc 1.18 integration tests #128

Open
wants to merge 12 commits into
base: MC_1.18
Choose a base branch
from
Open
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: 7 additions & 1 deletion .github/workflows/gradleBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ jobs:
with:
java-version: 17
- name: Build with Gradle
run: ./gradlew build
run: ./gradlew build -x test
- name: Run tests
run: |
./gradlew test
./gradlew agreeToMinecraftEula
./gradlew runIntegrationTests -PdisableNetworkingInIntegrationTest=true

- uses: actions/upload-artifact@v2
with:
name: Compiled jars
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/gradleBuildPR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ jobs:
with:
java-version: 17
- name: Build with Gradle
run: ./gradlew build
run: ./gradlew build -x test
- name: Run tests
run: |
./gradlew test
./gradlew agreeToMinecraftEula
./gradlew runIntegrationTests -PdisableNetworkingInIntegrationTest=true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ build
# other
eclipse
run
runIntegrationTests
classes

# Files from Forge MDK
Expand Down
2 changes: 2 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pipeline {
stage("Test") {
steps {
sh "./gradlew test"
sh "./gradlew agreeToMinecraftEula"
sh "./gradlew runIntegrationTests -PdisableNetworkingInIntegrationTest=true"
}
post {
success {
Expand Down
92 changes: 91 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@file:Suppress("INACCESSIBLE_TYPE", "UnstableApiUsage")

import io.github.opencubicchunks.gradle.GeneratePackageInfo
import net.fabricmc.loom.task.RemapJarTask
import org.gradle.internal.os.OperatingSystem
import java.util.*

Expand All @@ -23,11 +24,14 @@ plugins {
val minecraftVersion: String by project
val loaderVersion: String by project
val fabricVersion: String by project
val installerVersion: String by project
val lwjglVersion: String by project
val lwjglNatives: String by project
val modId: String by project
val debugArtifactTransforms: String by project

val disableNetworkingInIntegrationTest: String? by project

javaHeaders {
setAcceptedJars(".*CubicChunksCore.*")
setConfig(file("javaHeaders.json"))
Expand All @@ -46,6 +50,8 @@ generatePackageInfo.apply {
doFirst {
GeneratePackageInfo.generateFiles(project.sourceSets["main"])
GeneratePackageInfo.generateFiles(project.sourceSets["test"])
GeneratePackageInfo.generateFiles(project.sourceSets["debug"])
GeneratePackageInfo.generateFiles(project.sourceSets["integrationTest"])
}
}

Expand Down Expand Up @@ -114,6 +120,15 @@ mixinGen {
injectorsDefaultRequire = 1
configurationPlugin = "io.github.opencubicchunks.cubicchunks.mixin.TestMixinConfig"
}

config("integration_test") {
required = true
conformVisibility = true
injectorsDefaultRequire = 1
sourceSet = "integrationTest"
refmap = "integrationTest-CubicChunks-refmap.json"
packageName = "io.github.opencubicchunks.cubicchunks.test.mixin"
}
}

group = "io.github.opencubicchunks" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand All @@ -134,6 +149,9 @@ val debugRuntime: Configuration by configurations.creating {
val extraTests: Configuration by configurations.creating
val shade: Configuration by configurations.creating

val productionRuntimeServer: Configuration by configurations.creating
val productionRuntimeMods: Configuration by configurations.creating

sourceSets {
create("debug") {
compileClasspath += debugCompile
Expand All @@ -143,6 +161,14 @@ sourceSets {
runtimeClasspath += configurations.runtimeClasspath.get()
runtimeClasspath += sourceSets.main.get().output
}
create("integrationTest") {
compileClasspath += configurations.compileClasspath.get()
compileClasspath += configurations.testCompileClasspath.get()
compileClasspath += sourceSets.main.get().output
runtimeClasspath += configurations.runtimeClasspath.get()
runtimeClasspath += configurations.testRuntimeClasspath.get()
runtimeClasspath += sourceSets.main.get().output
}
}

repositories {
Expand All @@ -169,6 +195,7 @@ repositories {

loom {
createRemapConfigurations(sourceSets.test.get())
createRemapConfigurations(sourceSets["integrationTest"])

accessWidenerPath.set(file("src/main/resources/cubicchunks.accesswidener"))
// intermediaryUrl = { "http://localhost:9000/intermediary-20w49a-v2.jar" }
Expand Down Expand Up @@ -223,6 +250,12 @@ loom {
server()
vmArgs("-Xmx4G")
}
create(" ").apply {
server()
source(project.sourceSets["integrationTest"])
vmArgs("-Xmx4G", "-Dcubicchunks.test.freezeFailingWorlds=true")
runDir("runIntegrationTests")
}
}
runConfigs.configureEach {
isIdeConfigGenerated = true
Expand Down Expand Up @@ -309,7 +342,13 @@ dependencies {

testImplementation("org.hamcrest:hamcrest-junit:2.0.0.0")
testImplementation("org.hamcrest:hamcrest:2.2")
}

"modIntegrationTestImplementation"(fabricApi.module("fabric-gametest-api-v1", fabricVersion))

productionRuntimeServer("net.fabricmc:fabric-installer:${installerVersion}:server")
listOf("fabric-api-base", "fabric-command-api-v1", "fabric-networking-v0", "fabric-lifecycle-events-v1", "fabric-resource-loader-v0").forEach {
productionRuntimeMods(fabricApi.module(it, fabricVersion))
}}

val jar: Jar by tasks
jar.apply {
Expand All @@ -325,6 +364,57 @@ if (project.tasks.findByName("ideaSyncTask") != null) {
project.tasks.findByName("ideaSyncTask")!!.dependsOn("CubicChunksCore:assemble")
}

val integrationTestJar by tasks.creating(Jar::class) {
from(sourceSets["integrationTest"].output)
destinationDirectory.set(File(project.buildDir, "devlibs"))
archiveClassifier.set("testmod")
}

val remapIntegrationTestJar by tasks.creating(RemapJarTask::class) {
dependsOn(integrationTestJar)
input.set(integrationTestJar.archiveFile)
archiveClassifier.set("integrationTest")
addNestedDependencies.set(false)
}

val serverPropertiesJar by tasks.creating(Jar::class) {
val propsFile = file("build/tmp/install.properties")

doFirst {
propsFile.writeText("fabric-loader-version=${loaderVersion}\ngame-version=${minecraftVersion}")
}

archiveFileName.set("test-server-properties.jar")
destinationDirectory.set(file("build/tmp"))
from(propsFile)
}

val agreeToMinecraftEula: Task by tasks.creating {
mkdir("run")
file("run/eula.txt").writeText("eula=true")
}

val runIntegrationTests by tasks.creating(JavaExec::class) {
dependsOn(tasks["remapJar"], remapIntegrationTestJar, serverPropertiesJar)
classpath(productionRuntimeServer, serverPropertiesJar)
mainClass.set("net.fabricmc.installer.ServerLauncher")
workingDir(file("run"))

doFirst {
workingDir.mkdirs()

val mods = productionRuntimeMods.files.joinToString(separator = File.pathSeparator) { it.absolutePath }

jvmArgs(
"-Dfabric.addMods=${(tasks["remapJar"] as AbstractArchiveTask).archiveFile.get().asFile.absolutePath}${File.pathSeparator}${remapIntegrationTestJar.archiveFile.get()
.asFile.absolutePath}${File.pathSeparator}${mods}",
"-Dcubicchunks.test.disableNetwork=${disableNetworkingInIntegrationTest}"
)

args("nogui")
}
}

// unzipping subproject (CubicChunksCore) tests
val unzipTests by tasks.creating(Copy::class) {
outputs.upToDateWhen {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ public static class MixinConfig {

private Integer injectorsDefaultRequire;
private Boolean conformVisibility;
private String sourceSet;

public String getSourceSet() {
return sourceSet;
}

public void setSourceSet(String sourceSet) {
this.sourceSet = sourceSet;
}

public Boolean getRequired() {
return required;
Expand Down Expand Up @@ -171,9 +180,6 @@ public void setMixinPriority(Integer mixinPriority) {
}

void generateFiles(JavaPluginConvention convention) throws IOException {
SourceSet main = convention.getSourceSets().getByName("main");
Set<File> resourcesSet = main.getResources().getSrcDirs();
Path resources = resourcesSet.iterator().next().getCanonicalFile().toPath();
for (String name : configs.keySet()) {
MixinConfig config = new MixinConfig();
Action<MixinConfig> configure = configs.get(name);
Expand All @@ -191,6 +197,10 @@ void generateFiles(JavaPluginConvention convention) throws IOException {
}
configure.execute(config);

SourceSet main = convention.getSourceSets().getByName(config.sourceSet == null ? "main" : config.sourceSet);
Set<File> resourcesSet = main.getResources().getSrcDirs();
Path resources = resourcesSet.iterator().next().getCanonicalFile().toPath();

String fileName = String.format(filePattern, name);

try (JsonWriter writer = new JsonWriter(Files.newBufferedWriter(resources.resolve(fileName)))) {
Expand Down Expand Up @@ -236,7 +246,8 @@ void generateFiles(JavaPluginConvention convention) throws IOException {
}

private void writeMixins(JavaPluginConvention convention, String name, MixinConfig config, JsonWriter writer) throws IOException {
Set<Path> classes = getMixinClasses(config, convention.getSourceSets().getByName("main").getAllJava());
SourceSet main = convention.getSourceSets().getByName(config.sourceSet == null ? "main": config.sourceSet);
Set<Path> classes = getMixinClasses(config, main.getAllJava());

Set<Path> commonSet = new HashSet<>();
Set<Path> clientSet = new HashSet<>();
Expand Down Expand Up @@ -281,7 +292,7 @@ private void writeMixins(JavaPluginConvention convention, String name, MixinConf
}

private Set<Path> getMixinClasses(MixinConfig config, SourceDirectorySet allJava) throws IOException {
System.out.println("GetMixin Classes");
System.out.println("GetMixin Classes for " + config.packageName + " in " + allJava.getSrcDirs());
Set<Path> srcPaths = new HashSet<>();
for (File file : allJava.getSrcDirs()) {
Path toPath = file.getCanonicalFile().toPath();
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ modId=cubicchunks
minecraftVersion=1.18.2
yarnVersion=1.18.2+build.1
loaderVersion=0.14.19
installerVersion=0.11.1

# Dependencies
fabricVersion=0.67.1+1.18.2
Expand Down
4 changes: 4 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ pluginManagement {
}
}

plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.4.0'
}

include ':CubicChunksCore'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package io.github.opencubicchunks.cubicchunks.debug;

import javax.annotation.ParametersAreNonnullByDefault;

import io.github.opencubicchunks.cc_core.annotation.MethodsReturnNonnullByDefault;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.github.opencubicchunks.cubicchunks.test;

import java.util.Collection;
import java.util.HashSet;

import io.github.opencubicchunks.cubicchunks.test.tests.PlaceholderTests;

public class IntegrationTests {
public static final boolean DISABLE_NETWORK = System.getProperty("cubicchunks.test.disableNetwork", "false").equals("true");
public static final boolean FREEZE_FAILING_WORLDS = System.getProperty("cubicchunks.test.freezeFailingWorlds", "false").equals("true");

private static final Collection<LightingIntegrationTest> LIGHTING_TESTS = new HashSet<>();
static {
PlaceholderTests.register(LIGHTING_TESTS);
}

public static Collection<LightingIntegrationTest> getLightingTests() {
return LIGHTING_TESTS;
}

public enum TestState {
PASS,
FAIL,
NONE,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.opencubicchunks.cubicchunks.test;

public interface LevelTestRunner {
void startTestInLevel(LightingIntegrationTest test);

boolean testFinished();
IntegrationTests.TestState testState();

LightingIntegrationTest getTest();
}
Loading