Skip to content

Commit 877d44f

Browse files
committed
Add test jar configuration and allow for mod tests from a compiled JAR
1 parent be99908 commit 877d44f

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

build.gradle

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ minecraft {
145145
environment 'MOD_MODULES', String.join(File.pathSeparator, "${mod_id}%%${project.name}.test")
146146
environment 'target', 'fmltestserver'
147147
environment 'targetModId', "${mod_id}"
148-
environment "TEST_RESOURCES", sourceSets.test.resources.srcDirs[0]
148+
environment "CC_TEST_RESOURCES", sourceSets.test.resources.srcDirs[0]
149149
arg '--keepAlive'
150150
forceExit = false
151151
mods {
@@ -168,7 +168,7 @@ minecraft {
168168
environment 'MOD_MODULES', String.join(File.pathSeparator, "${mod_id}%%${project.name}.test")
169169
environment 'target', 'fmltestserver'
170170
environment 'targetModId', "${mod_id}"
171-
environment "TEST_RESOURCES", sourceSets.test.resources.srcDirs[0]
171+
environment "CC_TEST_RESOURCES", sourceSets.test.resources.srcDirs[0]
172172
arg '--crashOnFailedTests'
173173
forceExit = false
174174
mods {
@@ -288,8 +288,16 @@ task apiJar(type: Jar) {
288288
classifier("api")
289289
}
290290

291+
task testJar(type: Jar) {
292+
from sourceSets.api.output
293+
from sourceSets.main.output
294+
from sourceSets.test.output
295+
destinationDirectory = file("$rootDir/build-out")
296+
classifier("tests")
297+
}
298+
291299
artifacts {
292-
archives jar, apiJar
300+
archives jar, apiJar, testJar
293301
}
294302

295303
publishing {
@@ -302,6 +310,7 @@ publishing {
302310
artifact(apiJar) {
303311
classifier = "api"
304312
}
313+
artifact(testJar)
305314
}
306315
}
307316

@@ -313,6 +322,7 @@ publishing {
313322
artifact(apiJar) {
314323
classifier = "api"
315324
}
325+
artifact(testJar)
316326
}
317327
}
318328
}

src/test/java/dev/compactmods/crafting/tests/ServerEventListener.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,26 @@ public static void onServerStarted(final FMLServerStartedEvent evt) {
2424

2525
// Add "test/resources" as a resource pack to the pack repository
2626
final ResourcePackList packs = server.getPackRepository();
27-
final FolderPackFinder testPack = new FolderPackFinder(new File(System.getenv("TEST_RESOURCES")), IPackNameDecorator.DEFAULT);
28-
packs.addPackFinder(testPack);
29-
packs.reload();
30-
31-
// add "file/resources" to selected pack list
32-
final ImmutableSet<String> toSelect = ImmutableSet.<String>builder()
33-
.addAll(packs.getSelectedIds())
34-
.add("file/test_data")
35-
.build();
36-
37-
packs.setSelected(toSelect);
38-
39-
try {
40-
server.reloadResources(packs.getSelectedIds()).get();
41-
} catch (InterruptedException | ExecutionException e) {
42-
CompactCrafting.LOGGER.error("Failed to reload test resource packs.", e);
27+
28+
final String cc_test_resources = System.getenv("CC_TEST_RESOURCES");
29+
if(cc_test_resources != null) {
30+
final FolderPackFinder testPack = new FolderPackFinder(new File(cc_test_resources), IPackNameDecorator.DEFAULT);
31+
packs.addPackFinder(testPack);
32+
packs.reload();
33+
34+
// add "file/resources" to selected pack list
35+
final ImmutableSet<String> toSelect = ImmutableSet.<String>builder()
36+
.addAll(packs.getSelectedIds())
37+
.add("file/test_data")
38+
.build();
39+
40+
packs.setSelected(toSelect);
41+
42+
try {
43+
server.reloadResources(packs.getSelectedIds()).get();
44+
} catch (InterruptedException | ExecutionException e) {
45+
CompactCrafting.LOGGER.error("Failed to reload test resource packs.", e);
46+
}
4347
}
4448
}
4549

0 commit comments

Comments
 (0)