Skip to content

Commit 298ff2f

Browse files
authored
Rework tests to actually work, update buildscript and dependencies (#71)
1 parent 71013f2 commit 298ff2f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+667
-387
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
#gradle
1818
**/build
1919
**/.gradle
20+
/coremods-test/logs/

build.gradle

+8-18
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import net.minecraftforge.gradleutils.PomUtils
22

33
plugins {
4-
id 'net.minecraftforge.licenser' version '1.0.1'
54
id 'idea'
65
id 'eclipse'
76
id 'java-library'
87
id 'maven-publish'
9-
id 'net.minecraftforge.gradleutils' version '[2.1.3,2.3.0)'
8+
alias libs.plugins.license
9+
//alias libs.plugins.versions
10+
alias libs.plugins.gradleutils
1011
}
1112

12-
group 'net.minecraftforge'
13+
group = 'net.minecraftforge'
1314
version = gradleutils.tagOffsetVersion
1415
println "Version: $version"
1516

@@ -25,7 +26,7 @@ repositories {
2526
}
2627

2728
changelog {
28-
fromTag "1.0.0"
29+
from '1.0.0'
2930
}
3031

3132
license {
@@ -34,25 +35,14 @@ license {
3435
}
3536

3637
dependencies {
37-
// TODO: Cleanup tests
38-
testImplementation('org.junit.jupiter:junit-jupiter-api:5.7.+')
39-
testImplementation('org.powermock:powermock-core:2.0.+')
40-
testImplementation('org.hamcrest:hamcrest-core:2.2')
41-
testImplementation('org.apache.logging.log4j:log4j-core:2.19.0')
42-
testImplementation(libs.modlauncher)
43-
testImplementation(libs.forgespi)
44-
testImplementation(libs.unsafe)
45-
testCompileOnly('org.jetbrains:annotations:21.0.1')
46-
testRuntimeOnly('org.junit.jupiter:junit-jupiter-engine:5.7.+')
47-
testRuntimeOnly(project(':coremods-test-jar'))
48-
4938
compileOnly(libs.modlauncher)
5039
compileOnly(libs.securemodules)
5140
compileOnly(libs.log4j.api)
52-
api(libs.bundles.asm)
41+
compileOnly(libs.nulls)
5342
compileOnly(libs.forgespi)
43+
44+
api(libs.bundles.asm)
5445
implementation(libs.nashorn)
55-
compileOnly(libs.nulls)
5646
}
5747

5848
tasks.named('jar', Jar) {

coremods-test-jar/build.gradle

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
plugins {
2-
id 'net.minecraftforge.licenser' version '1.0.1'
32
id 'eclipse'
43
id 'java-library'
5-
id 'net.minecraftforge.gradleutils' version '[2.1.3,2.3.0)'
4+
alias libs.plugins.license
5+
//alias libs.plugins.versions
6+
alias libs.plugins.gradleutils
67
}
78

89
repositories {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* Copyright (c) Forge Development LLC
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
6+
open module net.minecraftforge.coremod.testjar {
7+
exports net.minecraftforge.coremod.testjar;
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) Forge Development LLC
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
6+
package net.minecraftforge.coremod.testjar;
7+
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
11+
public class Counter {
12+
private final List<Integer> counts = new ArrayList<>();
13+
14+
public Counter() {
15+
push();
16+
}
17+
18+
public int[] getCounts() {
19+
return counts.stream().mapToInt(Integer::intValue).toArray();
20+
}
21+
22+
public void push() {
23+
counts.add(0);
24+
}
25+
26+
public void increment() {
27+
counts.set(counts.size() - 1, counts.get(counts.size() - 1) + 1);
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) Forge Development LLC
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
6+
package net.minecraftforge.coremod.testjar;
7+
8+
public class TestClass {
9+
public static boolean False() {
10+
return false;
11+
}
12+
13+
public static int[] testCounter() {
14+
var counts = new Counter();
15+
counts.push();
16+
return counts.getCounts();
17+
}
18+
19+
public static String testString() {
20+
return "raw";
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright (c) Forge Development LLC
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
6+
package net.minecraftforge.coremod.testjar;
7+
8+
// Marker class to let the arms length find the test resources
9+
public class TestMarker {
10+
}

coremods-test-jar/src/main/java/net/minecraftforge/coremods/testjar/RedirectClass.java

-31
This file was deleted.

coremods-test-jar/src/main/java/net/minecraftforge/coremods/testjar/TestClass.java

-35
This file was deleted.

coremods-test-jar/src/main/java/net/minecraftforge/coremods/testjar/TestTarget.java

-12
This file was deleted.

coremods-test/build.gradle

+32-20
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
plugins {
2-
id 'net.minecraftforge.licenser' version '1.0.1'
32
id 'eclipse'
43
id 'java-library'
5-
id 'org.gradlex.extra-java-module-info' version '1.9'
6-
id 'net.minecraftforge.gradleutils' version '[2.1.3,2.3.0)'
4+
alias libs.plugins.license
5+
alias libs.plugins.modules
6+
//alias libs.plugins.versions
7+
alias libs.plugins.gradleutils
78
}
89

910
repositories {
@@ -23,17 +24,25 @@ license {
2324

2425
test {
2526
useJUnitPlatform()
26-
reports.html.destination = rootProject.file("build/reports/")
27-
reports.junitXml.destination = rootProject.file("build/test-results/")
27+
reports.html.outputLocation = rootProject.file("build/reports/")
28+
reports.junitXml.outputLocation = rootProject.file("build/test-results/")
2829
}
2930

3031
test {
31-
exclude '**/*'
32+
//exclude '**/*'
3233
useJUnitPlatform()
3334
}
3435

3536
compileTestJava {
36-
exclude '**/*'
37+
//exclude '**/*'
38+
}
39+
40+
sourceSets {
41+
test {
42+
resources {
43+
srcDir 'src/test/javascript/'
44+
}
45+
}
3746
}
3847

3948
dependencies {
@@ -42,6 +51,7 @@ dependencies {
4251
testImplementation(libs.junit.api)
4352
testImplementation(libs.log4j.api)
4453
testImplementation(libs.modlauncher)
54+
testImplementation(libs.securemodules)
4555
testImplementation(libs.forgespi)
4656
testImplementation(libs.unsafe)
4757
testRuntimeOnly(libs.bundles.junit.runtime)
@@ -66,28 +76,30 @@ if (project.hasProperty('javaVendor') && project.hasProperty('javaVersion')) {
6676
}
6777

6878
dependencies {
69-
groovyScript 'org.apache.ivy:ivy:2.4.0'
70-
groovyScript 'org.codehaus.groovy:groovy-all:3.0.19'
79+
groovyScript libs.ivy
80+
groovyScript libs.groovy
7181
}
7282

7383
tasks.register('collectTests', JavaExec) {
7484
classpath = configurations.groovyScript
75-
main = 'groovy.ui.GroovyMain'
85+
mainClass = 'groovy.ui.GroovyMain'
7686
args '.github/workflows/aggregate-junit-tests.groovy'
7787
workingDir rootProject.projectDir
7888
}
7989

80-
VALID_VMS.each { javaVendor, javaVersions ->
81-
javaVersions.each { javaVersion ->
82-
def task = tasks.register("test${javaVendor}${javaVersion}", Test) {
90+
((Map<String, List<Integer>>) VALID_VMS).forEach { javaVendor, javaVersions ->
91+
for (Integer javaVersion in javaVersions) {
92+
var task = tasks.register("test${javaVendor}${javaVersion}", Test) {
93+
testClassesDirs = testing.suites.test.sources.output.classesDirs
94+
classpath = testing.suites.test.sources.runtimeClasspath
8395
useJUnitPlatform()
84-
javaLauncher.set(javaToolchains.launcherFor {
85-
it.vendor.set(JvmVendorSpec."${javaVendor.toUpperCase(Locale.ROOT)}" as JvmVendorSpec)
86-
it.languageVersion.set(JavaLanguageVersion.of(javaVersion))
87-
it.implementation.set(JvmImplementation.VENDOR_SPECIFIC)
88-
})
89-
reports.html.destination = rootProject.file("build/test_artifacts/test-reports-${javaVendor}-${javaVersion}/")
90-
reports.junitXml.destination = rootProject.file("build/test_artifacts/test-results-${javaVendor}-${javaVersion}/")
96+
javaLauncher = javaToolchains.launcherFor {
97+
vendor = JvmVendorSpec."${javaVendor.toUpperCase(Locale.ROOT)}" as JvmVendorSpec
98+
languageVersion = JavaLanguageVersion.of(javaVersion)
99+
implementation = JvmImplementation.VENDOR_SPECIFIC
100+
}
101+
reports.html.outputLocation = rootProject.file("build/test_artifacts/test-reports-${javaVendor}-${javaVersion}/")
102+
reports.junitXml.outputLocation = rootProject.file("build/test_artifacts/test-results-${javaVendor}-${javaVersion}/")
91103
}
92104
test.dependsOn(task)
93105
collectTests.mustRunAfter(task)

coremods-test/src/test/java/module-info.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
* Copyright (c) Forge Development LLC
33
* SPDX-License-Identifier: LGPL-2.1-only
44
*/
5-
module net.minecraftforge.coremods.test {
5+
open module net.minecraftforge.coremods.test {
66
requires cpw.mods.modlauncher;
77
requires net.minecraftforge.forgespi;
88
requires net.minecraftforge.coremod;
99
requires org.junit.jupiter.api;
1010
requires org.apache.logging.log4j;
1111
requires org.objectweb.asm.tree;
12-
requires org.jetbrains.annotations;
12+
requires static org.jetbrains.annotations;
1313
requires net.minecraftforge.unsafe;
14+
requires static net.minecraftforge.coremod.testjar;
15+
requires cpw.mods.securejarhandler;
1416

1517
provides cpw.mods.modlauncher.api.ITransformationService
1618
with net.minecraftforge.coremod.test.TestTransformerService;

coremods-test/src/test/java/net/minecraftforge/coremod/test/ArmsLengthHandler.java

-29
This file was deleted.

0 commit comments

Comments
 (0)