From e74ba0b54ccd4fdbc70710ef0fbb7e0b19a0a3c8 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 26 Dec 2023 22:16:37 -0800 Subject: [PATCH] Turn WriteTracker's management of inline snapshots. --- CHANGELOG.md | 2 ++ .../main/kotlin/com/diffplug/selfie/junit5/WriteTracker.kt | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdc61973..6e286216 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +* When `toBe()` snapshots fail in write mode, they now include the expected / actual values, to fill the gap until #49 is finished. ## [0.2.0] - 2023-12-27 ### Added diff --git a/selfie-runner-junit5/src/main/kotlin/com/diffplug/selfie/junit5/WriteTracker.kt b/selfie-runner-junit5/src/main/kotlin/com/diffplug/selfie/junit5/WriteTracker.kt index 448f2868..02928b1a 100644 --- a/selfie-runner-junit5/src/main/kotlin/com/diffplug/selfie/junit5/WriteTracker.kt +++ b/selfie-runner-junit5/src/main/kotlin/com/diffplug/selfie/junit5/WriteTracker.kt @@ -22,6 +22,7 @@ import java.nio.file.Files import java.nio.file.Path import java.util.stream.Collectors import kotlin.io.path.name +import org.opentest4j.AssertionFailedError /** Represents the line at which user code called into Selfie. */ data class CallLocation(val clazz: String, val method: String, val file: String?, val line: Int) : @@ -101,8 +102,10 @@ internal class InlineWriteTracker : WriteTracker>( fun record(call: CallStack, literalValue: LiteralValue<*>, layout: SnapshotFileLayout) { recordInternal(call.location, literalValue, call, layout) if (literalValue.expected != null) { - throw UnsupportedOperationException( - "`.toBe() didn't match! Change to `toBe_TODO()` to record a new value until https://github.com/diffplug/selfie/pull/49 is merged.") + throw AssertionFailedError( + "`.toBe() didn't match! Change to `toBe_TODO()` to record a new value until https://github.com/diffplug/selfie/pull/49 is merged", + literalValue.expected, + literalValue.actual) } } fun hasWrites(): Boolean = writes.isNotEmpty()