diff --git a/WoofWare.Expect.Test/SimpleTest.fs b/WoofWare.Expect.Test/SimpleTest.fs index c7a20dd..d5c5acc 100644 --- a/WoofWare.Expect.Test/SimpleTest.fs +++ b/WoofWare.Expect.Test/SimpleTest.fs @@ -27,7 +27,7 @@ actual was: return Assert - .Throws(fun () -> + .Throws(fun () -> expectWithMockedFilePath ("filepath.fs", 99) { snapshot "123" return 124 diff --git a/WoofWare.Expect/Library.fs b/WoofWare.Expect/Library.fs index 2bfc555..b5b39b4 100644 --- a/WoofWare.Expect/Library.fs +++ b/WoofWare.Expect/Library.fs @@ -15,6 +15,9 @@ type private SnapshotValue = | BareString of string | Json of string +/// An exception indicating that a value failed to match its snapshot. +exception ExpectException of Message : string + /// A dummy type which is here to provide better error messages when you supply /// the `snapshot` keyword multiple times. type YouHaveSuppliedMultipleSnapshots = private | NonConstructible @@ -160,25 +163,29 @@ type ExpectBuilder (?sourceOverride : string * int) = JsonSerializer.Serialize (actual, options) |> JsonDocument.Parse if not (JsonElement.DeepEquals (canonicalActual.RootElement, canonicalSnapshot.RootElement)) then - failwithf + sprintf "snapshot mismatch! snapshot at %s:%i (%s) was:\n\n%s\n\nactual was:\n\n%s" (sourceOverride |> Option.map fst |> Option.defaultValue source.FilePath) (sourceOverride |> Option.map snd |> Option.defaultValue source.LineNumber) source.MemberName (canonicalSnapshot.RootElement.ToString () |> Text.predent '-') (canonicalActual.RootElement.ToString () |> Text.predent '-') + |> ExpectException + |> raise | SnapshotValue.BareString snapshot -> let actual = actual.ToString () if actual <> snapshot then - failwithf + sprintf "snapshot mismatch! snapshot at %s:%i (%s) was:\n\n%s\n\nactual was:\n\n%s" (sourceOverride |> Option.map fst |> Option.defaultValue source.FilePath) (sourceOverride |> Option.map snd |> Option.defaultValue source.LineNumber) source.MemberName (snapshot |> Text.predent '-') (actual |> Text.predent '+') + |> ExpectException + |> raise | None, _ -> failwith "Must specify snapshot" | _, None -> failwith "Must specify actual value with 'return'" diff --git a/WoofWare.Expect/SurfaceBaseline.txt b/WoofWare.Expect/SurfaceBaseline.txt index 5d8e006..d70148d 100644 --- a/WoofWare.Expect/SurfaceBaseline.txt +++ b/WoofWare.Expect/SurfaceBaseline.txt @@ -11,6 +11,12 @@ WoofWare.Expect.ExpectBuilder.Return [method]: unit -> 'T WoofWare.Expect.Expect WoofWare.Expect.ExpectBuilder.Run [method]: (unit -> 'T WoofWare.Expect.ExpectState) -> unit WoofWare.Expect.ExpectBuilder.Snapshot [method]: (unit WoofWare.Expect.ExpectState, string, string option, int option, string option) -> WoofWare.Expect.YouHaveSuppliedMultipleSnapshots WoofWare.Expect.ExpectState WoofWare.Expect.ExpectBuilder.SnapshotJson [method]: (unit WoofWare.Expect.ExpectState, string, string option, int option, string option) -> WoofWare.Expect.YouHaveSuppliedMultipleSnapshots WoofWare.Expect.ExpectState +WoofWare.Expect.ExpectException inherit System.Exception, implements System.Collections.IStructuralEquatable +WoofWare.Expect.ExpectException..ctor [constructor]: string +WoofWare.Expect.ExpectException..ctor [constructor]: unit +WoofWare.Expect.ExpectException.Equals [method]: (System.Exception, System.Collections.IEqualityComparer) -> bool +WoofWare.Expect.ExpectException.Equals [method]: System.Exception -> bool +WoofWare.Expect.ExpectException.Message [property]: [read-only] string WoofWare.Expect.ExpectState`1 inherit obj, implements 'T WoofWare.Expect.ExpectState System.IEquatable, System.Collections.IStructuralEquatable, 'T WoofWare.Expect.ExpectState System.IComparable, System.IComparable, System.Collections.IStructuralComparable WoofWare.Expect.ExpectState`1.Equals [method]: ('T WoofWare.Expect.ExpectState, System.Collections.IEqualityComparer) -> bool WoofWare.Expect.YouHaveSuppliedMultipleSnapshots inherit obj, implements WoofWare.Expect.YouHaveSuppliedMultipleSnapshots System.IEquatable, System.Collections.IStructuralEquatable, WoofWare.Expect.YouHaveSuppliedMultipleSnapshots System.IComparable, System.IComparable, System.Collections.IStructuralComparable