Skip to content

Commit

Permalink
Add an API for implicit selfies.
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Dec 19, 2023
1 parent 2567554 commit b05af47
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ object Selfie {
fun <T> expectSelfie(actual: T, snapshotter: Snapshotter<T>) =
DiskSelfie(snapshotter.snapshot(actual))

@JvmStatic fun expectSelfie(actual: Any) = expectSelfie(actual, Router.snapshotImplicit(actual))

class StringSelfie(private val actual: String) : DiskSelfie(Snapshot.of(actual)) {
fun toBe(expected: String): String = TODO()
fun toBe_TODO(): String = TODO()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@
*/
package com.diffplug.selfie.junit5

import com.diffplug.selfie.Snapshotter
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths

interface SelfieSettingsAPI {
/** API function which allows user to specify a custom snapshotter. */
fun implictSnapshotterFor(underTest: Any): Snapshotter<*> =
throw AssertionError("Implicit snapshots have not been setup, see TODO.")

/**
* Defaults to `__snapshot__`, null means that snapshots are stored at the same folder location as
* the test that created them.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ internal object Router {
ExpectedActual(cm.clazz.read(cm.method, suffix), actual)
}
}
fun snapshotImplicit(actual: Any): Snapshotter<Any> {
val cm = classAndMethod()
return cm.clazz.parent.settings.implictSnapshotterFor(actual) as Snapshotter<Any>
}
fun keep(subOrKeepAll: String?) {
val cm = classAndMethod()
if (subOrKeepAll == null) {
Expand Down

0 comments on commit b05af47

Please sign in to comment.