diff --git a/src/test/kotlin/org/hiero/gradle/test/RustTasksTest.kt b/src/test/kotlin/org/hiero/gradle/test/RustTasksTest.kt index bc0b118..c750b24 100644 --- a/src/test/kotlin/org/hiero/gradle/test/RustTasksTest.kt +++ b/src/test/kotlin/org/hiero/gradle/test/RustTasksTest.kt @@ -9,21 +9,31 @@ import org.junit.jupiter.api.Test class RustTasksTest { - @Test - fun `installRustToolchains installs all toolchains defined in CargoToolchain`() { - val p = GradleProject().withMinimalStructure() - val rustToolchainsDir = p.file("product/module-a/build/rust-toolchains/rustup/toolchains") - p.moduleBuildFile("""plugins { id("org.hiero.gradle.feature.rust") }""") - p.toolchainVersionsFile( - """ + private val toolchainVersions = + """ jdk=17.0.12 rust=1.81.0 cargo-zigbuild=0.19.5 zig=0.13.0 xwin=0.6.5 """ - .trimIndent() - ) + .trimIndent() + + private val cargoToml = + """ + [package] + name = "test" + version = "0.0.1" + edition = "2021" + """ + .trimIndent() + + @Test + fun `installRustToolchains installs all toolchains defined in CargoToolchain`() { + val p = GradleProject().withMinimalStructure() + val rustToolchainsDir = p.file("product/module-a/build/rust-toolchains/rustup/toolchains") + p.moduleBuildFile("""plugins { id("org.hiero.gradle.feature.rust") }""") + p.toolchainVersionsFile(toolchainVersions) val result = p.run("installRustToolchains") @@ -39,4 +49,51 @@ class RustTasksTest { assertThat(result.task(":module-a:installRustToolchains")?.outcome) .isEqualTo(TaskOutcome.SUCCESS) } + + @Test + fun `rust build results are taken FROM-CACHE and then installRustToolchains can be skipped`() { + val push = GradleProject().withMinimalStructure() + val pull = GradleProject().withMinimalStructure() + push.settingsFile.appendText( + """buildCache.local.directory = File(${push.file("build-cache").absolutePath})""" + ) + pull.settingsFile.appendText( + """buildCache.local.directory = File(${push.file("build-cache").absolutePath})""" + ) + push.moduleBuildFile("""plugins { id("org.hiero.gradle.feature.rust") }""") + pull.moduleBuildFile("""plugins { id("org.hiero.gradle.feature.rust") }""") + push.toolchainVersionsFile(toolchainVersions) + pull.toolchainVersionsFile(toolchainVersions) + push.file("product/module-a/src/main/rust/main.rs", "fn main() {}") + pull.file("product/module-a/src/main/rust/main.rs", "fn main() {}") + push.file("product/module-a/Cargo.toml", cargoToml) + pull.file("product/module-a/Cargo.toml", cargoToml) + + val pushResult = push.run("assemble --build-cache") + val pullResult = pull.run("assemble --build-cache -PskipInstallRustToolchains") + + assertThat(pushResult.task(":module-a:installRustToolchains")?.outcome) + .isEqualTo(TaskOutcome.SUCCESS) + assertThat(pullResult.task(":module-a:installRustToolchains")).isNull() + assertThat(pushResult.task(":module-a:cargoBuildAarch64Darwin")?.outcome) + .isEqualTo(TaskOutcome.SUCCESS) + assertThat(pullResult.task(":module-a:cargoBuildAarch64Darwin")?.outcome) + .isEqualTo(TaskOutcome.FROM_CACHE) + assertThat(pushResult.task(":module-a:cargoBuildAarch64Linux")?.outcome) + .isEqualTo(TaskOutcome.SUCCESS) + assertThat(pullResult.task(":module-a:cargoBuildAarch64Linux")?.outcome) + .isEqualTo(TaskOutcome.FROM_CACHE) + assertThat(pushResult.task(":module-a:cargoBuildX86Darwin")?.outcome) + .isEqualTo(TaskOutcome.SUCCESS) + assertThat(pullResult.task(":module-a:cargoBuildX86Darwin")?.outcome) + .isEqualTo(TaskOutcome.FROM_CACHE) + assertThat(pushResult.task(":module-a:cargoBuildX86Linux")?.outcome) + .isEqualTo(TaskOutcome.SUCCESS) + assertThat(pullResult.task(":module-a:cargoBuildX86Linux")?.outcome) + .isEqualTo(TaskOutcome.FROM_CACHE) + assertThat(pushResult.task(":module-a:cargoBuildX86Windows")?.outcome) + .isEqualTo(TaskOutcome.SUCCESS) + assertThat(pullResult.task(":module-a:cargoBuildX86Windows")?.outcome) + .isEqualTo(TaskOutcome.FROM_CACHE) + } } diff --git a/src/test/kotlin/org/hiero/gradle/test/fixtures/GradleProject.kt b/src/test/kotlin/org/hiero/gradle/test/fixtures/GradleProject.kt index 07f46da..d0fede9 100644 --- a/src/test/kotlin/org/hiero/gradle/test/fixtures/GradleProject.kt +++ b/src/test/kotlin/org/hiero/gradle/test/fixtures/GradleProject.kt @@ -114,6 +114,8 @@ class GradleProject { fun help(): BuildResult = runner(listOf("help")).build() + fun assemble(): BuildResult = runner(listOf("assemble")).build() + fun build(): BuildResult = runner(listOf("build")).build() fun qualityCheck(): BuildResult = runner(listOf("qualityCheck")).build()