From 5df9cce37cf8a5df494fe1772802d21ba6c13147 Mon Sep 17 00:00:00 2001 From: Alex Vanyo Date: Fri, 8 Dec 2023 11:32:01 -0800 Subject: [PATCH] Add truth for better badging diff output Change-Id: Id3fab0107bc08adf44ddf07a30e0327e06897d47 --- build-logic/convention/build.gradle.kts | 1 + .../samples/apps/nowinandroid/Badging.kt | 20 +++++++------------ gradle/libs.versions.toml | 2 ++ 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/build-logic/convention/build.gradle.kts b/build-logic/convention/build.gradle.kts index ea57a7c8c..e11a1b42a 100644 --- a/build-logic/convention/build.gradle.kts +++ b/build-logic/convention/build.gradle.kts @@ -41,6 +41,7 @@ dependencies { compileOnly(libs.firebase.performance.gradlePlugin) compileOnly(libs.kotlin.gradlePlugin) compileOnly(libs.ksp.gradlePlugin) + implementation(libs.truth) } tasks { diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Badging.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Badging.kt index 2a776e429..c59d3ffb8 100644 --- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Badging.kt +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Badging.kt @@ -20,8 +20,8 @@ import com.android.build.api.artifact.SingleArtifact import com.android.build.api.variant.ApplicationAndroidComponentsExtension import com.android.build.gradle.BaseExtension import com.android.SdkConstants +import com.google.common.truth.Truth.assertWithMessage import org.gradle.api.DefaultTask -import org.gradle.api.GradleException import org.gradle.api.Project import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.RegularFileProperty @@ -40,7 +40,6 @@ import org.gradle.kotlin.dsl.register import org.gradle.language.base.plugins.LifecycleBasePlugin import org.gradle.process.ExecOperations import java.io.File -import java.nio.file.Files import javax.inject.Inject @CacheableTask @@ -98,17 +97,12 @@ abstract class CheckBadgingTask : DefaultTask() { @TaskAction fun taskAction() { - if ( - Files.mismatch( - goldenBadging.get().asFile.toPath(), - generatedBadging.get().asFile.toPath(), - ) != -1L - ) { - throw GradleException( - "Generated badging is different from golden badging! " + - "If this change is intended, run ./gradlew ${updateBadgingTaskName.get()}", - ) - } + assertWithMessage( + "Generated badging is different from golden badging! " + + "If this change is intended, run ./gradlew ${updateBadgingTaskName.get()}", + ) + .that(generatedBadging.get().asFile.readText()) + .isEqualTo(goldenBadging.get().asFile.readText()) } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index aa2a32e90..4f55e6290 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -57,6 +57,7 @@ robolectric = "4.11.1" roborazzi = "1.6.0" room = "2.6.0" secrets = "2.0.1" +truth = "1.1.5" turbine = "1.0.0" [libraries] @@ -140,6 +141,7 @@ roborazzi = { group = "io.github.takahirom.roborazzi", name = "roborazzi", versi room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" } room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" } room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" } +truth = { group = "com.google.truth", name = "truth", version.ref = "truth" } turbine = { group = "app.cash.turbine", name = "turbine", version.ref = "turbine" } # Dependencies of the included build-logic