Skip to content

Commit 1d4c796

Browse files
authored
Clean up and fix integration tests (#348)
* Rename SimpleNeoForgeTest to NeoForge1202Test * Split ArchitecturyFabricAdditionsTest into two classes * Fix integration tests from subdirs being ignored The architectury and neoforge packages are now run as single tests like noRemap and the unit tests; the runtime should be short enough for that. * Fix spotless exclusion * Fix ForgeRunConfigTest reporting false errors * Remove unused constant for undetermined main class * Fix code style
1 parent cb5df57 commit 1d4c796

9 files changed

Lines changed: 95 additions & 42 deletions

File tree

build.gradle

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ spotless {
236236
targetExclude(
237237
// These files use a @MAPPINGS@ token which is not valid Groovy
238238
'**/projects/forge/simple/build.gradle',
239-
'**/projects/neoforge/simple/build.gradle'
239+
'**/projects/neoforge/1202/build.gradle'
240240
)
241241
}
242242

@@ -489,6 +489,12 @@ abstract class WriteActionsTestMatrix extends DefaultTask {
489489
def run() {
490490
def testMatrix = []
491491

492+
// Arch: read tests from subdirs
493+
// Subdirectories combined into one test run each
494+
def mergedSubdirs = ['architectury', 'neoforge']
495+
// Subdirectories where individual tests are added to the matrix (= longer tests)
496+
def directSubdirs = ['forge']
497+
492498
integrationTestDirectory.get().asFile.eachFile {
493499
if (it.name.endsWith("Test.groovy")) {
494500
if (it.name.endsWith("ReproducibleBuildTest.groovy")) {
@@ -510,6 +516,15 @@ abstract class WriteActionsTestMatrix extends DefaultTask {
510516
testMatrix.add("net.fabricmc.loom.test.integration.${className}")
511517
} else if (it.name.endsWith("noRemap")) {
512518
testMatrix.add("net.fabricmc.loom.test.integration.noRemap.*")
519+
} else if (it.isDirectory()) {
520+
if (mergedSubdirs.contains(it.name)) {
521+
testMatrix.add("net.fabricmc.loom.test.integration.${it.name}.*")
522+
} else if (directSubdirs.contains(it.name)) {
523+
it.eachFile { child ->
524+
def className = child.name.replace(".groovy", "")
525+
testMatrix.add("net.fabricmc.loom.test.integration.${it.name}.${className}")
526+
}
527+
}
513528
}
514529
}
515530

src/main/java/net/fabricmc/loom/util/Constants.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ public static final class Manifest {
221221
}
222222

223223
public static final class Forge {
224-
public static final String UNDETERMINED_MAIN_CLASS = "[Forge] Main class has not been determined yet!";
225224
public static final String ACCESS_TRANSFORMER_PATH = "META-INF/accesstransformer.cfg";
226225
public static final String MIXIN_CONFIGS_MANIFEST_KEY = "MixinConfigs";
227226

src/test/groovy/net/fabricmc/loom/test/integration/architectury/ArchitecturyFabricAdditionsTest.groovy renamed to src/test/groovy/net/fabricmc/loom/test/integration/architectury/AccessWidenerInjectionTest.groovy

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* This file is part of fabric-loom, licensed under the MIT License (MIT).
33
*
4-
* Copyright (c) 2023-2026 FabricMC
4+
* Copyright (c) 2026 FabricMC
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -33,7 +33,7 @@ import net.fabricmc.loom.test.util.GradleProjectTestTrait
3333
import static net.fabricmc.loom.test.LoomTestConstants.STANDARD_TEST_VERSIONS
3434
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
3535

36-
class ArchitecturyFabricAdditionsTest extends Specification implements GradleProjectTestTrait {
36+
class AccessWidenerInjectionTest extends Specification implements GradleProjectTestTrait {
3737
private static final String INJECTED_AW_FILE_NAME = 'hello_world.accesswidener'
3838
private static final String INJECTED_AW_CONTENTS_REMAP = """\
3939
accessWidener v1 named
@@ -46,31 +46,6 @@ class ArchitecturyFabricAdditionsTest extends Specification implements GradlePro
4646
"""
4747
.stripIndent()
4848

49-
@Unroll
50-
def "build with crane (gradle #version)"() {
51-
setup:
52-
def gradle = gradleProject(project: 'minimalBase', version: version)
53-
gradle.buildGradle << """
54-
dependencies {
55-
minecraft 'com.mojang:minecraft:1.17.1'
56-
mappings loom.layered {
57-
officialMojangMappings()
58-
crane 'dev.architectury:crane:1.17.1+build.15'
59-
}
60-
modImplementation 'net.fabricmc:fabric-loader:0.14.19'
61-
}
62-
"""
63-
64-
when:
65-
def result = gradle.run(task: 'build')
66-
67-
then:
68-
result.task(':build').outcome == SUCCESS
69-
70-
where:
71-
version << STANDARD_TEST_VERSIONS
72-
}
73-
7449
@Unroll
7550
def "inject access widener (old api, remap, gradle #version)"() {
7651
setup:
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* This file is part of fabric-loom, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) 2023 FabricMC
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package net.fabricmc.loom.test.integration.architectury
26+
27+
import spock.lang.Specification
28+
import spock.lang.Unroll
29+
30+
import net.fabricmc.loom.test.util.GradleProjectTestTrait
31+
32+
import static net.fabricmc.loom.test.LoomTestConstants.STANDARD_TEST_VERSIONS
33+
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
34+
35+
class CraneTest extends Specification implements GradleProjectTestTrait {
36+
@Unroll
37+
def "build with crane (gradle #version)"() {
38+
setup:
39+
def gradle = gradleProject(project: 'minimalBase', version: version)
40+
gradle.buildGradle << """
41+
dependencies {
42+
minecraft 'com.mojang:minecraft:1.17.1'
43+
mappings loom.layered {
44+
officialMojangMappings()
45+
crane 'dev.architectury:crane:1.17.1+build.15'
46+
}
47+
modImplementation 'net.fabricmc:fabric-loader:0.14.19'
48+
}
49+
"""
50+
51+
when:
52+
def result = gradle.run(task: 'build')
53+
54+
then:
55+
result.task(':build').outcome == SUCCESS
56+
57+
where:
58+
version << STANDARD_TEST_VERSIONS
59+
}
60+
}

src/test/groovy/net/fabricmc/loom/test/integration/forge/ForgeRunConfigTest.groovy

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
package net.fabricmc.loom.test.integration.forge
2626

27+
import java.util.stream.Collectors
28+
2729
import spock.lang.Specification
2830
import spock.lang.Unroll
2931

@@ -44,24 +46,26 @@ class ForgeRunConfigTest extends Specification implements GradleProjectTestTrait
4446
.replace('@PACKAGE@', 'net.minecraftforge:forge')
4547
.replace('@JAVA_VERSION@', javaVersion)
4648
gradle.buildGradle << """
47-
tasks.register('verifyRunConfigs') {
48-
doLast {
49-
loom.runs.each {
50-
def expected = '$mainClass'
51-
def found = it.mainClass.get()
52-
if (expected != found) {
53-
throw new AssertionError("\$it.name: found main class \$found, expected \$expected")
54-
}
55-
}
49+
afterEvaluate {
50+
loom.runs.each {
51+
def finalised = net.fabricmc.loom.configuration.ide.DefaultRunConfigurationSettings.finialise(it, project)
52+
def mainClass = finalised.mainClass.get()
53+
file('main_classes.txt') << "\$it.name\\t\$mainClass\\n"
5654
}
5755
}
5856
""".stripIndent()
5957

6058
when:
61-
def result = gradle.run(task: "verifyRunConfigs", configurationCache: false)
59+
def result = gradle.run(task: "build")
60+
def mainClasses = new File(gradle.projectDir, 'main_classes.txt')
61+
.readLines()
62+
.stream()
63+
.map { it.split('\t') }
64+
.collect(Collectors.toMap({ it[0] }) { it[1] })
6265

6366
then:
64-
result.task(":verifyRunConfigs").outcome == SUCCESS
67+
result.task(":build").outcome == SUCCESS
68+
mainClasses == [client: mainClass, server: mainClass]
6569

6670
where:
6771
mcVersion | forgeVersion | javaVersion | mainClass

src/test/groovy/net/fabricmc/loom/test/integration/neoforge/SimpleNeoForgeTest.groovy renamed to src/test/groovy/net/fabricmc/loom/test/integration/neoforge/NeoForge1202Test.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ import net.fabricmc.loom.test.util.GradleProjectTestTrait
3232
import static net.fabricmc.loom.test.LoomTestConstants.DEFAULT_GRADLE
3333
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
3434

35-
class SimpleNeoForgeTest extends Specification implements GradleProjectTestTrait {
35+
class NeoForge1202Test extends Specification implements GradleProjectTestTrait {
3636
@Unroll
3737
def "build #mcVersion #neoforgeVersion #mappings"() {
3838
setup:
39-
def gradle = gradleProject(project: "neoforge/simple", version: DEFAULT_GRADLE)
39+
def gradle = gradleProject(project: "neoforge/1202", version: DEFAULT_GRADLE)
4040
gradle.buildGradle.text = gradle.buildGradle.text.replace('@MCVERSION@', mcVersion)
4141
.replace('@NEOFORGEVERSION@', neoforgeVersion)
4242
.replace('@MAPPINGS@', mappings)

src/test/resources/projects/neoforge/simple/build.gradle renamed to src/test/resources/projects/neoforge/1202/build.gradle

File renamed without changes.

src/test/resources/projects/neoforge/simple/gradle.properties renamed to src/test/resources/projects/neoforge/1202/gradle.properties

File renamed without changes.

src/test/resources/projects/neoforge/simple/settings.gradle renamed to src/test/resources/projects/neoforge/1202/settings.gradle

File renamed without changes.

0 commit comments

Comments
 (0)