Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove doubled exception message from nunit #167

Merged
merged 10 commits into from
Jul 25, 2020
8 changes: 5 additions & 3 deletions src/FsUnit.NUnit/FsUnitTyped.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ open NUnit.Framework
open System.Collections.Generic

[<AutoOpen>]

module TopLevelOperators =

[<DebuggerStepThrough>]
let shouldEqual (expected: 'a) (actual: 'a) =
Assert.That(actual, FsUnit.Equality.IsEqualTo(expected), sprintf "Expected: %A\nActual: %A" expected actual)
FsUnit.TopLevelOperators.FSharpCustomMessageFormatter() |> ignore
sergey-tihon marked this conversation as resolved.
Show resolved Hide resolved
Assert.That(actual, FsUnit.Equality.IsEqualTo(expected))

[<DebuggerStepThrough>]
let shouldNotEqual (expected: 'a) (actual: 'a) =
Assert.That(actual, FsUnit.Equality.IsNotEqualTo(expected), sprintf "Expected: %A\nActual: %A" expected actual)
FsUnit.TopLevelOperators.FSharpCustomMessageFormatter() |> ignore
Assert.That(actual, FsUnit.Equality.IsNotEqualTo(expected))

[<DebuggerStepThrough>]
let shouldContain (x: 'a) (y: 'a seq) =
Expand Down
32 changes: 30 additions & 2 deletions tests/FsUnit.NUnit.Test/typed.shouldEqualTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ open System.Collections.Immutable

open NUnit.Framework
open FsUnitTyped
open FsUnit
open System

type AlwaysEqual() =
override this.Equals(other) = true
override this.GetHashCode() = 1


type NeverEqual() =
override this.Equals(other) = false
override this.GetHashCode() = 1


[<TestFixture>]
type ``shouldEqual Tests``() =
let anObj = new obj()
Expand Down Expand Up @@ -75,6 +75,34 @@ type ``shouldEqual Tests``() =
member __.``None should equal None``() =
None |> shouldEqual None

[<Test>]
member __.``Error "Foo" should equal Error "Foo"``() =
Error "Foo" |> shouldEqual(Error "Foo")

[<Test>]
member __.``Error "Foo" should equal fails and have same message``() =
(fun () -> Error "Foo" |> shouldEqual(Error "Bar"))
|> Assert.Throws<AssertionException>
|> fun e ->
e.Message
|> should
equal
(sprintf " Expected: Error \"Bar\" or Error \"Bar\"%s But was: Error \"Foo\"%s" Environment.NewLine Environment.NewLine)

[<Test>]
member __.``Error "Foo" should not equal Error "Bar"``() =
Error "Foo" |> shouldNotEqual(Error "Bar")

[<Test>]
member __.``Error "Foo" should not equal Error "Bar" fails and have same message``() =
(fun () -> Error "Foo" |> shouldNotEqual(Error "Foo"))
|> Assert.Throws<AssertionException>
|> fun e ->
e.Message
|> should
equal
(sprintf " Expected: not Error \"Foo\" or Error \"Foo\"%s But was: Error \"Foo\"%s" Environment.NewLine Environment.NewLine)

[<Test>]
member this.``structural equality``() =
let actualList: char list = []
Expand Down