2023-03-15 21:52:13 +00:00
|
|
|
// SPDX-FileCopyrightText: 2022 The CC: Tweaked Developers
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2022-11-09 23:58:56 +00:00
|
|
|
import cc.tweaked.gradle.clientClasses
|
|
|
|
import cc.tweaked.gradle.commonClasses
|
|
|
|
|
2022-10-29 17:17:02 +00:00
|
|
|
/**
|
|
|
|
* Sets up the configurations for writing game tests.
|
|
|
|
*
|
|
|
|
* See notes in [cc.tweaked.gradle.MinecraftConfigurations] for the general design behind these cursed ideas.
|
|
|
|
*/
|
|
|
|
|
|
|
|
plugins {
|
|
|
|
id("cc-tweaked.kotlin-convention")
|
|
|
|
id("cc-tweaked.java-convention")
|
|
|
|
}
|
|
|
|
|
2022-11-09 23:58:56 +00:00
|
|
|
val main = sourceSets["main"]
|
|
|
|
val client = sourceSets["client"]
|
2022-10-29 17:17:02 +00:00
|
|
|
|
2022-11-09 23:58:56 +00:00
|
|
|
// Both testMod and testFixtures inherit from the main and client classpath, just so we have access to Minecraft classes.
|
2022-10-29 17:17:02 +00:00
|
|
|
val testMod by sourceSets.creating {
|
2022-11-09 23:58:56 +00:00
|
|
|
compileClasspath += main.compileClasspath + client.compileClasspath
|
|
|
|
runtimeClasspath += main.runtimeClasspath + client.runtimeClasspath
|
2022-10-29 17:17:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
configurations {
|
|
|
|
named(testMod.compileClasspathConfigurationName) {
|
|
|
|
shouldResolveConsistentlyWith(compileClasspath.get())
|
|
|
|
}
|
|
|
|
|
|
|
|
named(testMod.runtimeClasspathConfigurationName) {
|
|
|
|
shouldResolveConsistentlyWith(runtimeClasspath.get())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Like the main test configurations, we're safe to depend on source set outputs.
|
|
|
|
dependencies {
|
|
|
|
add(testMod.implementationConfigurationName, main.output)
|
2022-11-09 23:58:56 +00:00
|
|
|
add(testMod.implementationConfigurationName, client.output)
|
2022-10-29 17:17:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Similar to java-test-fixtures, but tries to avoid putting the obfuscated jar on the classpath.
|
|
|
|
|
|
|
|
val testFixtures by sourceSets.creating {
|
2022-11-09 23:58:56 +00:00
|
|
|
compileClasspath += main.compileClasspath + client.compileClasspath
|
2022-10-29 17:17:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
java.registerFeature("testFixtures") {
|
|
|
|
usingSourceSet(testFixtures)
|
|
|
|
disablePublication()
|
|
|
|
}
|
|
|
|
|
|
|
|
dependencies {
|
2022-11-09 23:58:56 +00:00
|
|
|
val libs = project.extensions.getByType<VersionCatalogsExtension>().named("libs")
|
|
|
|
add(testFixtures.apiConfigurationName, libs.findBundle("test").get())
|
|
|
|
// Consumers of this project already have the common and client classes on the classpath, so it's fine for these
|
|
|
|
// to be compile-only.
|
|
|
|
add(testFixtures.compileOnlyApiConfigurationName, commonClasses(project))
|
|
|
|
add(testFixtures.compileOnlyApiConfigurationName, clientClasses(project))
|
|
|
|
|
2022-10-29 17:17:02 +00:00
|
|
|
testImplementation(testFixtures(project))
|
|
|
|
}
|