Skip to content

Commit 76586d3

Browse files
committed
Fix run setups by actually injecting a proper mod.
1 parent 4447ee0 commit 76586d3

13 files changed

Lines changed: 72 additions & 140 deletions

File tree

.github/workflows/test-prs.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ jobs:
8686

8787
- name: Build
8888
run: ./gradlew --info -s -x assemble -Ptraining-wheels.gradle-version=${{ env.GRADLE_VERSION }}
89-
9089
test:
9190
name: "${{ matrix.test.displayName }} (${{ matrix.os }})"
9291
runs-on: "${{ matrix.os }}-latest"
@@ -176,7 +175,6 @@ jobs:
176175
name: test-results-${{ steps.format-artifact-name-windows.outputs.artifact-name }}
177176
path: junit.xml
178177
retention-days: 1
179-
180178
process-test-data:
181179
name: Process Test Data
182180
runs-on: ubuntu-latest
@@ -193,10 +191,11 @@ jobs:
193191
path: downloaded_artifacts
194192

195193
- name: Publish Test Report
196-
uses: mikepenz/action-junit-report@v4
194+
uses: mikepenz/action-junit-report@v6
197195
if: always() # always run even if the previous step fails
198196
with:
199197
report_paths: '**/*.xml'
198+
update_check: 'true'
200199

201200
- name: Merge Test Reports
202201
if: always()

userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/AdvancedFmlTests.groovy

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -148,28 +148,7 @@ class AdvancedFmlTests extends BuilderBasedTestSpecification {
148148
}
149149
""")
150150

151-
it.file("src/main/resources/META-INF/neoforge.mods.toml", """
152-
license="MIT"
153-
[[mods]]
154-
modId="neogradle_test"
155-
version="1.0"
156-
displayName="NeoGradle Test"
157-
description='''Test Mod for NeoGradle'''
158-
""".stripMargin())
159-
160-
it.file("src/main/java/net/neoforged/gradle/userdev/FunctionalTests.java", """
161-
package net.neoforged.gradle.userdev;
162-
163-
import net.minecraft.client.Minecraft;
164-
import net.neoforged.fml.common.Mod;
165-
166-
@Mod("neogradle_test")
167-
public class FunctionalTests {
168-
public FunctionalTests() {
169-
System.out.println(Minecraft.class.toString());
170-
}
171-
}
172-
""".stripMargin())
151+
it.withMod()
173152
it.withToolchains()
174153
it.withGlobalCacheDirectory(tempDir)
175154
it.property("neogradle.subsystems.decompiler.enabled", "false")
@@ -182,7 +161,7 @@ class AdvancedFmlTests extends BuilderBasedTestSpecification {
182161
}
183162

184163
then:
185-
run.output.contains("class net.minecraft.client.Minecraft")
164+
run.checkModLoading()
186165
run.task(":neoFormDecompile") == null
187166
}
188167

userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/MultiProjectTests.groovy

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,7 @@ class MultiProjectTests extends BuilderBasedTestSpecification {
7474
}
7575
}
7676
""")
77-
it.file("src/main/java/net/neoforged/gradle/main/ApiTests.java", """
78-
package net.neoforged.gradle.main;
79-
80-
import net.minecraft.client.Minecraft;
81-
import net.neoforged.gradle.apitest.FunctionalTests;
82-
83-
public class ApiTests {
84-
public static void main(String[] args) {
85-
System.out.println(Minecraft.getInstance().getClass().toString());
86-
FunctionalTests.main(args);
87-
}
88-
}
89-
""")
77+
it.withMod()
9078
it.withToolchains()
9179
it.withGlobalCacheDirectory(tempDir)
9280
it.plugin(this.pluginUnderTest)
@@ -95,13 +83,10 @@ class MultiProjectTests extends BuilderBasedTestSpecification {
9583
when:
9684
def run = rootProject.run {
9785
it.tasks(':main:runClientData')
98-
//We are expecting this test to fail, since there is a mod without any files included so it is fine.
99-
it.shouldFail()
10086
}
10187

10288
then:
103-
run.output.contains("Error during pre-loading phase: ERROR: File null is not a valid mod file") ||
104-
run.output.contains("net.neoforged.fml.ModLoadingException: Loading errors encountered:")
89+
run.checkModLoading()
10590
}
10691

10792
def "multiple projects with neoforge dependencies from version catalogs should be able to build"() {
@@ -193,7 +178,6 @@ class MultiProjectTests extends BuilderBasedTestSpecification {
193178
def run = rootProject.run {
194179
it.tasks(':main:build')
195180
it.stacktrace()
196-
it.debug()
197181
}
198182

199183
then:
@@ -265,19 +249,7 @@ class MultiProjectTests extends BuilderBasedTestSpecification {
265249
}
266250
}
267251
""")
268-
it.file("src/main/java/net/neoforged/gradle/main/ApiTests.java", """
269-
package net.neoforged.gradle.main;
270-
271-
import net.minecraft.client.Minecraft;
272-
import net.neoforged.gradle.apitest.FunctionalTests;
273-
274-
public class ApiTests {
275-
public static void main(String[] args) {
276-
System.out.println(Minecraft.getInstance().getClass().toString());
277-
FunctionalTests.main(args);
278-
}
279-
}
280-
""")
252+
it.withMod()
281253
it.withToolchains()
282254
it.withGlobalCacheDirectory(tempDir)
283255
it.plugin(this.pluginUnderTest)
@@ -286,13 +258,10 @@ class MultiProjectTests extends BuilderBasedTestSpecification {
286258
when:
287259
def run = rootProject.run {
288260
it.tasks(':main:runClientData')
289-
//We are expecting this test to fail, since there is a mod without any files included so it is fine.
290-
it.shouldFail()
291261
}
292262

293263
then:
294-
run.output.contains("Error during pre-loading phase: ERROR: File null is not a valid mod file") ||
295-
run.output.contains("net.neoforged.fml.ModLoadingException: Loading errors encountered:")
264+
run.checkModLoading()
296265
}
297266

298267
def "multiple projects with neoforge dependencies should run using the central cache"() {

userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/RunTests.groovy

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,19 @@ class RunTests extends BuilderBasedTestSpecification {
4040
implementation(libs.neoforge)
4141
}
4242
""")
43+
it.withMod()
4344
it.withToolchains()
4445
it.withGlobalCacheDirectory(tempDir)
4546
})
4647

4748
when:
4849
def run = project.run {
4950
it.tasks(':runClientData')
50-
//We are expecting this test to fail, since there is a mod without any files included so it is fine.
51-
it.shouldFail()
5251
it.stacktrace()
5352
}
5453

5554
then:
56-
true
57-
run.output.contains("is not a valid mod file")
55+
run.checkModLoading()
5856
}
5957

6058
def "configuring of the configurations after the dependencies block should work"() {
@@ -92,19 +90,18 @@ class RunTests extends BuilderBasedTestSpecification {
9290
modRunImplementation.extendsFrom implementation
9391
}
9492
""")
93+
it.withMod()
9594
it.withToolchains()
9695
it.withGlobalCacheDirectory(tempDir)
9796
})
9897

9998
when:
10099
def run = project.run {
101100
it.tasks(':runClientData')
102-
//We are expecting this test to fail, since there is a mod without any files included so it is fine.
103-
it.shouldFail()
104101
}
105102

106103
then:
107-
run.output.contains("is not a valid mod file")
104+
run.checkModLoading()
108105
}
109106

110107
def "runs can be declared before the dependencies block"() {
@@ -131,6 +128,7 @@ class RunTests extends BuilderBasedTestSpecification {
131128
implementation 'net.neoforged:neoforge:+'
132129
}
133130
""")
131+
it.withMod()
134132
it.withToolchains()
135133
it.withGlobalCacheDirectory(tempDir)
136134
})
@@ -173,6 +171,7 @@ class RunTests extends BuilderBasedTestSpecification {
173171
}
174172
}
175173
""")
174+
it.withMod()
176175
it.withToolchains()
177176
it.withGlobalCacheDirectory(tempDir)
178177
})
@@ -225,6 +224,7 @@ class RunTests extends BuilderBasedTestSpecification {
225224
}
226225
}
227226
""")
227+
it.withMod()
228228
it.withToolchains()
229229
it.withGlobalCacheDirectory(tempDir)
230230
})
@@ -277,6 +277,7 @@ class RunTests extends BuilderBasedTestSpecification {
277277
}
278278
}
279279
""")
280+
it.withMod()
280281
it.withToolchains()
281282
it.withGlobalCacheDirectory(tempDir)
282283
})
@@ -285,16 +286,14 @@ class RunTests extends BuilderBasedTestSpecification {
285286
def run = project.run {
286287
it.tasks(':runClientData')
287288
it.stacktrace()
288-
it.shouldFail()
289-
it.debug()
290289
}
291290

292291
then:
293292
run.output.contains("You are using a version of NeoForge which does not need run specific dependencies")
294293
run.output.contains("NeoGradle detected a problem with your project: Run.getDependencies().runtime() in run: client")
295-
run.output.contains("is not a valid mod file")
296294
!run.output.contains("NeoGradle detected a problem with your project: Run.getDependencies().runtime() in run: server")
297295
run.task(":writeMinecraftClasspathClient") == null
296+
run.checkModLoading()
298297
}
299298

300299
def "userdev supports custom run dependencies from configuration"() {
@@ -338,7 +337,6 @@ class RunTests extends BuilderBasedTestSpecification {
338337
def run = project.run {
339338
it.tasks(':writeMinecraftClasspathClient')
340339
it.stacktrace()
341-
342340
}
343341

344342
then:
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package net.neoforged.gradle.userdev.extensions
2+
3+
import net.neoforged.trainingwheels.gradle.functional.builder.Runtime.Builder
4+
import net.neoforged.trainingwheels.gradle.functional.builder.Runtime.RunResult;
5+
6+
class TestExtensions {
7+
8+
/**
9+
* Registers a test mod to the project run builder.
10+
*
11+
* @param self The run builder
12+
* @return The run builder, with the test mod added.
13+
*/
14+
static Builder withMod(
15+
Builder self
16+
) {
17+
self.file("src/main/resources/META-INF/neoforge.mods.toml", """
18+
license="MIT"
19+
[[mods]]
20+
modId="neogradle_test"
21+
version="1.0"
22+
displayName="NeoGradle Test"
23+
description='''Test Mod for NeoGradle'''
24+
""".stripMargin())
25+
26+
self.file("src/main/java/net/neoforged/gradle/userdev/EntryPoint.java", """
27+
package net.neoforged.gradle.userdev;
28+
29+
import net.minecraft.client.Minecraft;
30+
import net.neoforged.fml.common.Mod;
31+
import org.slf4j.Logger;
32+
import com.mojang.logging.LogUtils;
33+
34+
@Mod("neogradle_test")
35+
public class EntryPoint {
36+
37+
// Directly reference a slf4j logger
38+
public static final Logger LOGGER = LogUtils.getLogger();
39+
40+
public EntryPoint() {
41+
LOGGER.info("NeoGradle Test Mod has been loaded successfully!");
42+
}
43+
}
44+
""".stripMargin())
45+
46+
return self
47+
}
48+
49+
static boolean checkModLoading(RunResult self) {
50+
return self.output.contains("NeoGradle Test Mod has been loaded successfully!")
51+
}
52+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
moduleName=Builder Test extension.
2+
moduleVersion=1.0.0
3+
extensionClasses=net.neoforged.gradle.userdev.extensions.TestExtensions

userdev/tests/running_compile_in_ci/build.gradle

Lines changed: 0 additions & 19 deletions
This file was deleted.

userdev/tests/running_compile_in_ci/gradle.properties

Lines changed: 0 additions & 4 deletions
This file was deleted.

userdev/tests/running_compile_in_ci/settings.gradle

Lines changed: 0 additions & 6 deletions
This file was deleted.

userdev/tests/running_compile_in_ci/src/main/java/net/neoforged/gradle/userdev/FunctionalTests.java

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)