Skip to content

Commit

Permalink
Rework tests to actually work, update buildscript and dependencies (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
LexManos authored Jan 14, 2025
1 parent 71013f2 commit 298ff2f
Show file tree
Hide file tree
Showing 43 changed files with 667 additions and 387 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
#gradle
**/build
**/.gradle
/coremods-test/logs/
26 changes: 8 additions & 18 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import net.minecraftforge.gradleutils.PomUtils

plugins {
id 'net.minecraftforge.licenser' version '1.0.1'
id 'idea'
id 'eclipse'
id 'java-library'
id 'maven-publish'
id 'net.minecraftforge.gradleutils' version '[2.1.3,2.3.0)'
alias libs.plugins.license
//alias libs.plugins.versions
alias libs.plugins.gradleutils
}

group 'net.minecraftforge'
group = 'net.minecraftforge'
version = gradleutils.tagOffsetVersion
println "Version: $version"

Expand All @@ -25,7 +26,7 @@ repositories {
}

changelog {
fromTag "1.0.0"
from '1.0.0'
}

license {
Expand All @@ -34,25 +35,14 @@ license {
}

dependencies {
// TODO: Cleanup tests
testImplementation('org.junit.jupiter:junit-jupiter-api:5.7.+')
testImplementation('org.powermock:powermock-core:2.0.+')
testImplementation('org.hamcrest:hamcrest-core:2.2')
testImplementation('org.apache.logging.log4j:log4j-core:2.19.0')
testImplementation(libs.modlauncher)
testImplementation(libs.forgespi)
testImplementation(libs.unsafe)
testCompileOnly('org.jetbrains:annotations:21.0.1')
testRuntimeOnly('org.junit.jupiter:junit-jupiter-engine:5.7.+')
testRuntimeOnly(project(':coremods-test-jar'))

compileOnly(libs.modlauncher)
compileOnly(libs.securemodules)
compileOnly(libs.log4j.api)
api(libs.bundles.asm)
compileOnly(libs.nulls)
compileOnly(libs.forgespi)

api(libs.bundles.asm)
implementation(libs.nashorn)
compileOnly(libs.nulls)
}

tasks.named('jar', Jar) {
Expand Down
5 changes: 3 additions & 2 deletions coremods-test-jar/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
plugins {
id 'net.minecraftforge.licenser' version '1.0.1'
id 'eclipse'
id 'java-library'
id 'net.minecraftforge.gradleutils' version '[2.1.3,2.3.0)'
alias libs.plugins.license
//alias libs.plugins.versions
alias libs.plugins.gradleutils
}

repositories {
Expand Down
8 changes: 8 additions & 0 deletions coremods-test-jar/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright (c) Forge Development LLC
* SPDX-License-Identifier: LGPL-2.1-only
*/

open module net.minecraftforge.coremod.testjar {
exports net.minecraftforge.coremod.testjar;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) Forge Development LLC
* SPDX-License-Identifier: LGPL-2.1-only
*/

package net.minecraftforge.coremod.testjar;

import java.util.ArrayList;
import java.util.List;

public class Counter {
private final List<Integer> counts = new ArrayList<>();

public Counter() {
push();
}

public int[] getCounts() {
return counts.stream().mapToInt(Integer::intValue).toArray();
}

public void push() {
counts.add(0);
}

public void increment() {
counts.set(counts.size() - 1, counts.get(counts.size() - 1) + 1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) Forge Development LLC
* SPDX-License-Identifier: LGPL-2.1-only
*/

package net.minecraftforge.coremod.testjar;

public class TestClass {
public static boolean False() {
return false;
}

public static int[] testCounter() {
var counts = new Counter();
counts.push();
return counts.getCounts();
}

public static String testString() {
return "raw";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright (c) Forge Development LLC
* SPDX-License-Identifier: LGPL-2.1-only
*/

package net.minecraftforge.coremod.testjar;

// Marker class to let the arms length find the test resources
public class TestMarker {
}

This file was deleted.

This file was deleted.

This file was deleted.

52 changes: 32 additions & 20 deletions coremods-test/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
plugins {
id 'net.minecraftforge.licenser' version '1.0.1'
id 'eclipse'
id 'java-library'
id 'org.gradlex.extra-java-module-info' version '1.9'
id 'net.minecraftforge.gradleutils' version '[2.1.3,2.3.0)'
alias libs.plugins.license
alias libs.plugins.modules
//alias libs.plugins.versions
alias libs.plugins.gradleutils
}

repositories {
Expand All @@ -23,17 +24,25 @@ license {

test {
useJUnitPlatform()
reports.html.destination = rootProject.file("build/reports/")
reports.junitXml.destination = rootProject.file("build/test-results/")
reports.html.outputLocation = rootProject.file("build/reports/")
reports.junitXml.outputLocation = rootProject.file("build/test-results/")
}

test {
exclude '**/*'
//exclude '**/*'
useJUnitPlatform()
}

compileTestJava {
exclude '**/*'
//exclude '**/*'
}

sourceSets {
test {
resources {
srcDir 'src/test/javascript/'
}
}
}

dependencies {
Expand All @@ -42,6 +51,7 @@ dependencies {
testImplementation(libs.junit.api)
testImplementation(libs.log4j.api)
testImplementation(libs.modlauncher)
testImplementation(libs.securemodules)
testImplementation(libs.forgespi)
testImplementation(libs.unsafe)
testRuntimeOnly(libs.bundles.junit.runtime)
Expand All @@ -66,28 +76,30 @@ if (project.hasProperty('javaVendor') && project.hasProperty('javaVersion')) {
}

dependencies {
groovyScript 'org.apache.ivy:ivy:2.4.0'
groovyScript 'org.codehaus.groovy:groovy-all:3.0.19'
groovyScript libs.ivy
groovyScript libs.groovy
}

tasks.register('collectTests', JavaExec) {
classpath = configurations.groovyScript
main = 'groovy.ui.GroovyMain'
mainClass = 'groovy.ui.GroovyMain'
args '.github/workflows/aggregate-junit-tests.groovy'
workingDir rootProject.projectDir
}

VALID_VMS.each { javaVendor, javaVersions ->
javaVersions.each { javaVersion ->
def task = tasks.register("test${javaVendor}${javaVersion}", Test) {
((Map<String, List<Integer>>) VALID_VMS).forEach { javaVendor, javaVersions ->
for (Integer javaVersion in javaVersions) {
var task = tasks.register("test${javaVendor}${javaVersion}", Test) {
testClassesDirs = testing.suites.test.sources.output.classesDirs
classpath = testing.suites.test.sources.runtimeClasspath
useJUnitPlatform()
javaLauncher.set(javaToolchains.launcherFor {
it.vendor.set(JvmVendorSpec."${javaVendor.toUpperCase(Locale.ROOT)}" as JvmVendorSpec)
it.languageVersion.set(JavaLanguageVersion.of(javaVersion))
it.implementation.set(JvmImplementation.VENDOR_SPECIFIC)
})
reports.html.destination = rootProject.file("build/test_artifacts/test-reports-${javaVendor}-${javaVersion}/")
reports.junitXml.destination = rootProject.file("build/test_artifacts/test-results-${javaVendor}-${javaVersion}/")
javaLauncher = javaToolchains.launcherFor {
vendor = JvmVendorSpec."${javaVendor.toUpperCase(Locale.ROOT)}" as JvmVendorSpec
languageVersion = JavaLanguageVersion.of(javaVersion)
implementation = JvmImplementation.VENDOR_SPECIFIC
}
reports.html.outputLocation = rootProject.file("build/test_artifacts/test-reports-${javaVendor}-${javaVersion}/")
reports.junitXml.outputLocation = rootProject.file("build/test_artifacts/test-results-${javaVendor}-${javaVersion}/")
}
test.dependsOn(task)
collectTests.mustRunAfter(task)
Expand Down
6 changes: 4 additions & 2 deletions coremods-test/src/test/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
* Copyright (c) Forge Development LLC
* SPDX-License-Identifier: LGPL-2.1-only
*/
module net.minecraftforge.coremods.test {
open module net.minecraftforge.coremods.test {
requires cpw.mods.modlauncher;
requires net.minecraftforge.forgespi;
requires net.minecraftforge.coremod;
requires org.junit.jupiter.api;
requires org.apache.logging.log4j;
requires org.objectweb.asm.tree;
requires org.jetbrains.annotations;
requires static org.jetbrains.annotations;
requires net.minecraftforge.unsafe;
requires static net.minecraftforge.coremod.testjar;
requires cpw.mods.securejarhandler;

provides cpw.mods.modlauncher.api.ITransformationService
with net.minecraftforge.coremod.test.TestTransformerService;
Expand Down

This file was deleted.

Loading

0 comments on commit 298ff2f

Please sign in to comment.