-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
273 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
plugins { | ||
id 'org.jetbrains.kotlin.jvm' | ||
} | ||
repositories { | ||
mavenCentral() | ||
} | ||
apply from: rootProject.file('gradle/spotless.gradle') | ||
apply plugin: 'java-library' | ||
dependencies { | ||
implementation project(':selfie-lib') | ||
// User supplied Junit5 version | ||
String JUNIT_API = '5.0.0' | ||
compileOnly "org.junit.jupiter:junit-jupiter-api:$JUNIT_API" | ||
compileOnly "org.junit.jupiter:junit-jupiter-engine:$JUNIT_API" | ||
|
||
testImplementation 'org.jetbrains.kotlin:kotlin-test-junit5:1.9.0' | ||
testImplementation 'io.kotest:kotest-assertions-core:5.6.2' | ||
|
||
String JUNIT_IMPL = '5.10.0' | ||
testImplementation "org.junit.jupiter:junit-jupiter-api:$JUNIT_IMPL" | ||
testImplementation "org.junit.jupiter:junit-jupiter-engine:$JUNIT_IMPL" | ||
} | ||
test { | ||
useJUnitPlatform() | ||
} |
90 changes: 90 additions & 0 deletions
90
selfie-runner-junit5/src/main/kotlin/com/diffplug/selfie/Selfie.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (C) 2023 DiffPlug | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.diffplug.selfie | ||
|
||
object SelfieRouting { | ||
var isWriting: Boolean = true | ||
var currentFile: SnapshotFile? = null | ||
var currentDiskPrefix: String? = null | ||
private fun assertInitializedProperly() { | ||
if (currentFile == null || currentDiskPrefix == null) { | ||
throw AssertionError("You called `toMatchDisk` without setting up snapshots.") | ||
} | ||
} | ||
fun onDiskRightNow(scenario: String?): Snapshot? { | ||
assertInitializedProperly() | ||
val snapshotSuffix = scenario?.let { "/$scenario" } ?: "" | ||
val snapshotName = "${currentDiskPrefix!!}${snapshotSuffix}" | ||
return currentFile!!.snapshots.get(snapshotName) | ||
} | ||
} | ||
|
||
open class DiskSelfie internal constructor(private val actual: Snapshot) { | ||
fun toMatchDisk(scenario: String? = null): Snapshot { | ||
val snapshot = SelfieRouting.onDiskRightNow(scenario) | ||
if (actual != snapshot) { | ||
if (SelfieRouting.isWriting) { | ||
TODO("write snapshot") | ||
} else { | ||
throw AssertionError() | ||
} | ||
} | ||
return actual | ||
} | ||
} | ||
fun <T> expectSelfie(actual: T, snapshotter: Snapshotter<T>) = | ||
DiskSelfie(snapshotter.snapshot(actual)) | ||
|
||
class StringSelfie(private val actual: String) : DiskSelfie(Snapshot.of(actual)) { | ||
fun toBe(expected: String): String = TODO() | ||
fun toBe_TODO(): String = TODO() | ||
} | ||
fun expectSelfie(actual: String) = StringSelfie(actual) | ||
|
||
class BinarySelfie(private val actual: ByteArray) : DiskSelfie(Snapshot.of(actual)) { | ||
fun toBeBase64(expected: String): ByteArray = TODO() | ||
fun toBeBase64_TODO(): ByteArray = TODO() | ||
} | ||
fun expectSelfie(actual: ByteArray) = BinarySelfie(actual) | ||
|
||
class IntSelfie(private val actual: Int) { | ||
fun toBe(expected: Int): Int = TODO() | ||
fun toBe_TODO(): Int = TODO() | ||
} | ||
fun expectSelfie(actual: Int) = IntSelfie(actual) | ||
|
||
class LongSelfie(private val actual: Long) { | ||
fun toBe(expected: Long): Long = TODO() | ||
fun toBe_TODO(): Long = TODO() | ||
} | ||
fun expectSelfie(actual: Long) = LongSelfie(actual) | ||
|
||
class BooleanSelfie(private val actual: Boolean) { | ||
fun toBe(expected: Boolean): Boolean = TODO() | ||
fun toBe_TODO(): Boolean = TODO() | ||
} | ||
fun expectSelfie(actual: Boolean) = BooleanSelfie(actual) | ||
|
||
/** Sometimes a selfie doesn't get used. */ | ||
fun preserveDiskSelfies(vararg names: String): Unit = TODO() | ||
|
||
// infix versions for the inline methods, consistent with Kotest's API | ||
infix fun String.shouldBeSelfie(expected: String): String = expectSelfie(this).toBe(expected) | ||
infix fun ByteArray.shouldBeSelfieBase64(expected: String): ByteArray = | ||
expectSelfie(this).toBeBase64(expected) | ||
infix fun Int.shouldBeSelfie(expected: Int): Int = expectSelfie(this).toBe(expected) | ||
infix fun Long.shouldBeSelfie(expected: Long): Long = expectSelfie(this).toBe(expected) | ||
infix fun Boolean.shouldBeSelfie(expected: Boolean): Boolean = expectSelfie(this).toBe(expected) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.