1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-10-25 02:47:39 +00:00

Change how we put test libraries on the class path

- Mark our core test-fixtures jar as part of the "cctest", rather than
   a separate library. I'm fairly sure this was actually using the
   classpath version of CC rather than the legacyClasspath version!

 - Add a new "testMinecraftLibrary" configuration, instead of trying to
   infer it from the classpath. We have to jump through some hoops to
   avoid having multiple versions of a library on the classpath at once,
   but it's not too bad.

I'm working on a patch to bsl which might allow us to kill of
legacyClasspath instead. Please, anything is better than this.
This commit is contained in:
Jonathan Coates
2024-01-31 19:47:03 +00:00
parent 57b1a65db3
commit ebeaa757a9
2 changed files with 19 additions and 17 deletions

View File

@@ -50,13 +50,6 @@ tasks.test {
systemProperty("cct.test-files", layout.buildDirectory.dir("tmp/testFiles").getAbsolutePath()) systemProperty("cct.test-files", layout.buildDirectory.dir("tmp/testFiles").getAbsolutePath())
} }
tasks.testFixturesJar {
manifest {
// Ensure the test fixtures jar loads as a mod. Thanks FML >_>.
attributes("FMLModType" to "GAMELIBRARY")
}
}
val checkChangelog by tasks.registering(cc.tweaked.gradle.CheckChangelog::class) { val checkChangelog by tasks.registering(cc.tweaked.gradle.CheckChangelog::class) {
version.set(modVersion) version.set(modVersion)
whatsNew.set(file("src/main/resources/data/computercraft/lua/rom/help/whatsnew.md")) whatsNew.set(file("src/main/resources/data/computercraft/lua/rom/help/whatsnew.md"))

View File

@@ -63,18 +63,15 @@ minecraft {
fun RunConfig.configureForGameTest() { fun RunConfig.configureForGameTest() {
val old = lazyTokens["minecraft_classpath"] val old = lazyTokens["minecraft_classpath"]
lazyToken("minecraft_classpath") { lazyToken("minecraft_classpath") {
// We do some terrible hacks here to basically find all things not already on the runtime classpath // Add all files in testMinecraftLibrary to the classpath.
// and add them. /Except/ for our source sets, as those need to load inside the Minecraft classpath. val allFiles = mutableSetOf<String>()
val testMod = configurations["testModRuntimeClasspath"].resolve()
val implementation = configurations.runtimeClasspath.get().resolve()
val new = (testMod - implementation)
.asSequence()
.filter { it.isFile && !it.name.endsWith("-test-fixtures.jar") }
.map { it.absolutePath }
.joinToString(File.pathSeparator)
val oldVal = old?.get() val oldVal = old?.get()
if (oldVal.isNullOrEmpty()) new else oldVal + File.pathSeparator + new if (!oldVal.isNullOrEmpty()) allFiles.addAll(oldVal.split(File.pathSeparatorChar))
for (file in configurations["testMinecraftLibrary"].resolve()) allFiles.add(file.absolutePath)
allFiles.joinToString(File.pathSeparator)
} }
property("cctest.sources", project(":common").file("src/testMod/resources/data/cctest").absolutePath) property("cctest.sources", project(":common").file("src/testMod/resources/data/cctest").absolutePath)
@@ -84,6 +81,7 @@ minecraft {
mods.register("cctest") { mods.register("cctest") {
source(sourceSets["testMod"]) source(sourceSets["testMod"])
source(sourceSets["testFixtures"]) source(sourceSets["testFixtures"])
source(project(":core").sourceSets["testFixtures"])
} }
} }
@@ -113,6 +111,13 @@ mixin {
configurations { configurations {
minecraftLibrary { extendsFrom(minecraftEmbed.get()) } minecraftLibrary { extendsFrom(minecraftEmbed.get()) }
val testMinecraftLibrary by registering {
isCanBeResolved = true
isCanBeConsumed = false
// Prevent ending up with multiple versions of libraries on the classpath.
shouldResolveConsistentlyWith(minecraftLibrary.get())
}
} }
dependencies { dependencies {
@@ -161,6 +166,10 @@ dependencies {
testModImplementation(testFixtures(project(":core"))) testModImplementation(testFixtures(project(":core")))
testModImplementation(testFixtures(project(":forge"))) testModImplementation(testFixtures(project(":forge")))
// Ensure our test fixture dependencies are on the classpath
"testMinecraftLibrary"(libs.bundles.kotlin)
"testMinecraftLibrary"(libs.bundles.test)
testFixturesImplementation(testFixtures(project(":core"))) testFixturesImplementation(testFixtures(project(":core")))
} }