Skip to content

Commit

Permalink
Add device attribtues to golden file names
Browse files Browse the repository at this point in the history
  • Loading branch information
sjudd committed Sep 3, 2023
1 parent 3472f80 commit cbdc1e7
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 2 deletions.
25 changes: 25 additions & 0 deletions integration/compose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,28 @@ dependencies {
}

apply from: "${rootProject.projectDir}/scripts/upload.gradle"

task cleanGoldensOnDevice(type: Exec) {
commandLine = ['adb', 'shell', 'rm -rf /storage/emulated/0/DCIM/compose_goldens']
}

task pullGoldens(type: Exec) {
commandLine = [
'bash',
'-c',
'adb shell \'find /storage/emulated/0/DCIM/compose_goldens -iname "*.png"\' ' +
'| tr -d "\015" ' +
'| while read line; do adb pull "$line" src/androidTest/assets/; done'
]

}

afterEvaluate {
task rebuildGoldens(type: Exec) {
ignoreExitValue = true
dependsOn(
cleanGoldensOnDevice,
tasks.getByName("connectedDebugAndroidTest").finalizedBy(pullGoldens)
)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.bumptech.glide.test
import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.Build
import android.os.Environment
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.ImageBitmap
Expand All @@ -19,6 +20,7 @@ import java.lang.IllegalStateException

const val GENERATED_FILES_DIR = "compose_goldens"
const val EXTENSION = "png"
const val SEPARATOR = "_"

@Composable
fun Int.pxToDp() = with(LocalDensity.current) { toDp() }
Expand Down Expand Up @@ -68,13 +70,18 @@ private fun readExistingGolden(testName: String): Bitmap? {
}
}

private fun testFileName(testName: String) = "$testName.$EXTENSION"

private fun testFileName(testName: String) = "$testName$SEPARATOR${getDeviceString()}.$EXTENSION"
private fun getTestFilesDir(): File {
val dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
return File(dir, GENERATED_FILES_DIR)
}

private fun getDeviceString() =
"${ApplicationProvider.getApplicationContext<Context>()
.resources
.displayMetrics
.density}$SEPARATOR${Build.VERSION.SDK_INT}"

private fun writeBitmap(bitmap: Bitmap, testName: String): String {
val testFilesDir = getTestFilesDir()
require(!(!testFilesDir.exists() && !testFilesDir.mkdirs())) { "Failed to make directory: $testFilesDir" }
Expand Down

0 comments on commit cbdc1e7

Please sign in to comment.