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

[API-10] Improve unit tests #3873

Open
wants to merge 19 commits into
base: api-10
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 64 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
`maven-publish`
`java-library`
eclipse
id("net.smoofyuniverse.jacoco-offline") version "1.0.0"
id("org.spongepowered.gradle.vanilla")
id("com.github.johnrengelman.shadow")
id("org.spongepowered.gradle.sponge.dev") apply false // for version json generation
Expand All @@ -15,6 +16,7 @@ plugins {
}

val commonProject = project
val vanillaProject = project(":SpongeVanilla")
val apiVersion: String by project
val minecraftVersion: String by project
val recommendedVersion: String by project
Expand All @@ -27,6 +29,7 @@ val apiPluginSpiVersion: String by project
val asmVersion: String by project
val log4jVersion: String by project
val modlauncherVersion: String by project
val java9hacksVersion: String by project
val mixinVersion: String by project
val junitVersion: String by project
val mockitoVersion: String by project
Expand All @@ -46,6 +49,9 @@ val commonManifest = java.manifest {
System.getenv()["GIT_BRANCH"]?.apply { attributes("Git-Branch" to this) }
}

val superclassConfigs = spongeImpl.getNamedConfigurations("superClassChanges")
val mixinConfigs = spongeImpl.mixinConfigurations

tasks {
jar {
manifest.from(commonManifest)
Expand Down Expand Up @@ -73,6 +79,33 @@ tasks {

test {
useJUnitPlatform()

if (JavaVersion.current().isJava11Compatible) {
jvmArgs(
"--add-exports=java.base/sun.security.util=ALL-UNNAMED",
"--add-opens=java.base/java.util.jar=ALL-UNNAMED"
)
}

jvmArgs("-javaagent:${mlpatcherConfig.get().resolvedConfiguration.files.firstOrNull()}")
maxHeapSize = "1G"

val launcherArgs = mixinConfigs.map { "--mixin.config $it" } + superclassConfigs.map { "--superclass_change.config $it" }
systemProperty("sponge.test.launcherArguments", launcherArgs.joinToString(" "))

extensions.configure(net.smoofyuniverse.testing.jacoco.plugins.JacocoTaskExtension::class) {
offline.set(true)
}
finalizedBy(jacocoTestReport)
}

jacocoTestOfflineInstrumentation {
sourceSets(applaunch.get(), launch.get())
}

jacocoTestReport {
sourceSets(applaunch.get(), launch.get())
dependsOn(test)
}

check {
Expand Down Expand Up @@ -102,6 +135,8 @@ val mixinsConfig by configurations.register("mixins") {
extendsFrom(launchConfig)
}

val mlpatcherConfig = configurations.register("mlpatcher")

// create the sourcesets
val main by sourceSets

Expand Down Expand Up @@ -145,6 +180,22 @@ val mixins by sourceSets.registering {
}
}

val test by sourceSets.named("test") {
spongeImpl.applyNamedDependencyOnOutput(project, mixins.get(), this, project, this.implementationConfigurationName)
configurations.named(implementationConfigurationName) {
extendsFrom(mlpatcherConfig.get())
extendsFrom(applaunchConfig)
extendsFrom(launchConfig)
}
}
vanillaProject.afterEvaluate {
val vanillaAppLaunchBase = vanillaProject.sourceSets.named("applaunch-base")
val vanillaLaunch = vanillaProject.sourceSets.named("launch")

spongeImpl.applyNamedDependencyOnOutput(vanillaProject, vanillaAppLaunchBase.get(), test, commonProject, test.implementationConfigurationName)
spongeImpl.applyNamedDependencyOnOutput(vanillaProject, vanillaLaunch.get(), test, commonProject, test.implementationConfigurationName)
}

dependencies {
// api
api("org.spongepowered:spongeapi:$apiVersion")
Expand Down Expand Up @@ -203,13 +254,26 @@ dependencies {
add(mixins.get().implementationConfigurationName, "org.spongepowered:spongeapi:$apiVersion")

// Tests
mlpatcherConfig.name(project(":modlauncher-patcher"))

testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion")
testImplementation("org.junit.jupiter:junit-jupiter-params:$junitVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitVersion")

testImplementation("org.mockito:mockito-core:$mockitoVersion")
testImplementation("org.mockito:mockito-junit-jupiter:$mockitoVersion")
testImplementation("org.mockito:mockito-inline:$mockitoVersion")

testImplementation("org.spongepowered:modlauncher-injector-junit:1.0.0")
testImplementation("cpw.mods:modlauncher:$modlauncherVersion") {
exclude(group = "org.apache.logging.log4j")
exclude(group = "net.sf.jopt-simple") // uses a newer version than MC
}
testRuntimeOnly("cpw.mods:grossjava9hacks:$java9hacksVersion") {
exclude(group = "org.apache.logging.log4j")
}
testRuntimeOnly(project(":modlauncher-transformers"))
testRuntimeOnly("org.apache.logging.log4j:log4j-slf4j-impl:$log4jVersion")
}

val organization: String by project
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ log4jVersion=2.19.0
forgeAutoRenamingToolVersion=0.1.24
mixinVersion=0.8.5
modlauncherVersion=8.1.3
java9hacksVersion=1.3.3
guavaVersion=31.1-jre
junitVersion=5.9.1
mockitoVersion=4.8.0
Expand Down
3 changes: 2 additions & 1 deletion modlauncher-transformers/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ val asmVersion: String by project
val checkerVersion: String by project
val log4jVersion: String by project
val modlauncherVersion: String by project
val java9hacksVersion: String by project

dependencies {
// AccessWidener transformer
Expand All @@ -40,7 +41,7 @@ dependencies {

compileOnly("net.sf.jopt-simple:jopt-simple:5.0.4")
compileOnly("org.ow2.asm:asm-commons:$asmVersion")
compileOnly("cpw.mods:grossjava9hacks:1.3.3") {
compileOnly("cpw.mods:grossjava9hacks:$java9hacksVersion") {
exclude(group="org.apache.logging.log4j")
}
// Configurate dependencies, also to be provided by the platform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public final class ShouldFire {
public static boolean INTERACT_ITEM_EVENT_PRIMARY = false;

public static boolean SPAWN_ENTITY_EVENT = false;
public static boolean SPAWN_ENTITY_EVENT_PRE = false;
public static boolean SPAWN_ENTITY_EVENT_CUSTOM = false;

public static boolean CHANGE_BLOCK_EVENT = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public ListenerChecker(Class<?> clazz) {
ListenerChecker.LOGGER.error("Error setting field {} to true", field.getName(), e);
}
}
} else {
} else if (!field.isSynthetic()) {
throw new IllegalStateException(String.format("ShouldFire field %s must be public and static!", field));
}
}
Expand Down
80 changes: 0 additions & 80 deletions src/test/invalid/common/data/manipulator/DataTestUtil.java

This file was deleted.