Skip to content

Commit cbdc1e7

Browse files
committed
Add device attribtues to golden file names
1 parent 3472f80 commit cbdc1e7

10 files changed

+34
-2
lines changed

integration/compose/build.gradle

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,28 @@ dependencies {
6666
}
6767

6868
apply from: "${rootProject.projectDir}/scripts/upload.gradle"
69+
70+
task cleanGoldensOnDevice(type: Exec) {
71+
commandLine = ['adb', 'shell', 'rm -rf /storage/emulated/0/DCIM/compose_goldens']
72+
}
73+
74+
task pullGoldens(type: Exec) {
75+
commandLine = [
76+
'bash',
77+
'-c',
78+
'adb shell \'find /storage/emulated/0/DCIM/compose_goldens -iname "*.png"\' ' +
79+
'| tr -d "\015" ' +
80+
'| while read line; do adb pull "$line" src/androidTest/assets/; done'
81+
]
82+
83+
}
84+
85+
afterEvaluate {
86+
task rebuildGoldens(type: Exec) {
87+
ignoreExitValue = true
88+
dependsOn(
89+
cleanGoldensOnDevice,
90+
tasks.getByName("connectedDebugAndroidTest").finalizedBy(pullGoldens)
91+
)
92+
}
93+
}
Loading

integration/compose/src/androidTest/java/com/bumptech/glide/test/goldens.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.bumptech.glide.test
33
import android.content.Context
44
import android.graphics.Bitmap
55
import android.graphics.BitmapFactory
6+
import android.os.Build
67
import android.os.Environment
78
import androidx.compose.runtime.Composable
89
import androidx.compose.ui.graphics.ImageBitmap
@@ -19,6 +20,7 @@ import java.lang.IllegalStateException
1920

2021
const val GENERATED_FILES_DIR = "compose_goldens"
2122
const val EXTENSION = "png"
23+
const val SEPARATOR = "_"
2224

2325
@Composable
2426
fun Int.pxToDp() = with(LocalDensity.current) { toDp() }
@@ -68,13 +70,18 @@ private fun readExistingGolden(testName: String): Bitmap? {
6870
}
6971
}
7072

71-
private fun testFileName(testName: String) = "$testName.$EXTENSION"
72-
73+
private fun testFileName(testName: String) = "$testName$SEPARATOR${getDeviceString()}.$EXTENSION"
7374
private fun getTestFilesDir(): File {
7475
val dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
7576
return File(dir, GENERATED_FILES_DIR)
7677
}
7778

79+
private fun getDeviceString() =
80+
"${ApplicationProvider.getApplicationContext<Context>()
81+
.resources
82+
.displayMetrics
83+
.density}$SEPARATOR${Build.VERSION.SDK_INT}"
84+
7885
private fun writeBitmap(bitmap: Bitmap, testName: String): String {
7986
val testFilesDir = getTestFilesDir()
8087
require(!(!testFilesDir.exists() && !testFilesDir.mkdirs())) { "Failed to make directory: $testFilesDir" }

0 commit comments

Comments
 (0)