Skip to content

Commit

Permalink
Remove SelfieBound for taking selfies on weird threads and coroutin…
Browse files Browse the repository at this point in the history
…es. (#213)
  • Loading branch information
nedtwigg authored Feb 11, 2024
2 parents 28d277d + dce933f commit 952a4eb
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions jvm/selfie-lib/src/commonMain/kotlin/com/diffplug/selfie/Selfie.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,6 @@ import kotlin.io.encoding.ExperimentalEncodingApi
import kotlin.jvm.JvmOverloads
import kotlin.jvm.JvmStatic

/**
* Used for creating snapshots which are independent of the thread or coroutine on which the test
* started. See the [threading details](http://localhost:3000/jvm/kotest#threading-details) for more
* info.
*/
class SelfieBound internal constructor(private val disk: DiskStorage) {
fun <T> expectSelfie(actual: T, camera: Camera<T>) = expectSelfie(camera.snapshot(actual))
fun expectSelfie(actual: String) = expectSelfie(Snapshot.of(actual))
fun expectSelfie(actual: ByteArray) = expectSelfie(Snapshot.of(actual))
fun expectSelfie(actual: Snapshot) = Selfie.DiskSelfie(actual, disk)
fun preserveSelfiesOnDisk(vararg subsToKeep: String) {
if (subsToKeep.isEmpty()) {
disk.keep(null)
} else {
subsToKeep.forEach { disk.keep(it) }
}
}
}

/** Static methods for creating snapshots. */
object Selfie {
internal val system: SnapshotSystem = initSnapshotSystem()
Expand All @@ -69,15 +50,14 @@ object Selfie {
*/
@JvmStatic
fun preserveSelfiesOnDisk(vararg subsToKeep: String) {
bind().preserveSelfiesOnDisk(*subsToKeep)
val disk = system.diskThreadLocal()
if (subsToKeep.isEmpty()) {
disk.keep(null)
} else {
subsToKeep.forEach { disk.keep(it) }
}
}

/**
* Used to bind to the currently executing test so that you can create disk selfies in other
* threads and coroutines if you want.
*/
@JvmStatic fun bind() = SelfieBound(system.diskThreadLocal())

class DiskSelfie internal constructor(actual: Snapshot, val disk: DiskStorage) :
LiteralStringSelfie(actual) {
@JvmOverloads
Expand Down

0 comments on commit 952a4eb

Please sign in to comment.