diff --git a/src/FsUnit.MbUnit/FsUnit.fs b/src/FsUnit.MbUnit/FsUnit.fs index 337fb8d9..c9380c83 100644 --- a/src/FsUnit.MbUnit/FsUnit.fs +++ b/src/FsUnit.MbUnit/FsUnit.fs @@ -11,7 +11,10 @@ let inline should (f : 'a -> ^b) x (y : obj) = match y with | :? (unit -> unit) as assertFunc -> box assertFunc | _ -> y - Assert.That(y, c) + if box c = null then + Assert.That(y, IsNull()) + else + Assert.That(y, c) let inline shouldFail (f:unit->unit) = let failed = diff --git a/src/FsUnit.MsTestUnit/FsUnit.fs b/src/FsUnit.MsTestUnit/FsUnit.fs index 7af63fef..4d45587b 100644 --- a/src/FsUnit.MsTestUnit/FsUnit.fs +++ b/src/FsUnit.MsTestUnit/FsUnit.fs @@ -20,7 +20,10 @@ let inline should (f : 'a -> ^b) x (y : obj) = match y with | :? (unit -> unit) as assertFunc -> box assertFunc | _ -> y - Assert.That(y, c) + if box c = null then + Assert.That(y, IsNull()) + else + Assert.That(y, c) let inline shouldFail (f:unit->unit) = let failed = diff --git a/src/FsUnit.NUnit/FsUnit.fs b/src/FsUnit.NUnit/FsUnit.fs index 09b933d5..29dfa89c 100644 --- a/src/FsUnit.NUnit/FsUnit.fs +++ b/src/FsUnit.NUnit/FsUnit.fs @@ -42,7 +42,10 @@ module TopLevelOperators = match y with | :? (unit -> unit) -> box (TestDelegate(y :?> unit -> unit)) | _ -> y - Assert.That(y, c) + if box c = null then + Assert.That(y, Is.Null) + else + Assert.That(y, c) let equal x = EqualsConstraint(x) @@ -87,7 +90,8 @@ module TopLevelOperators = let descending = Is.Ordered.Descending - let not' x = NotConstraint(x) + let not' x = + if box x = null then NotConstraint(Null) else NotConstraint(x) /// Deprecated operators. These will be removed in a future version of FsUnit. module FsUnitDeprecated = diff --git a/src/FsUnit.Xunit/CustomMatchers.fs b/src/FsUnit.Xunit/CustomMatchers.fs index a6663556..db807055 100644 --- a/src/FsUnit.Xunit/CustomMatchers.fs +++ b/src/FsUnit.Xunit/CustomMatchers.fs @@ -18,6 +18,7 @@ let equalWithin (t:obj) (x:obj) = CustomMatcher(sprintf "%s with a toleranc else false ) let not' (x:obj) = match box x with + | null -> Is.Not(Is.Null()) | :? IMatcher as matcher -> Is.Not(matcher) | x -> Is.Not(CustomMatcher(sprintf "Equals %s" (x.ToString()), fun a -> a = x) :> IMatcher) diff --git a/src/FsUnit.Xunit/FsUnit.fs b/src/FsUnit.Xunit/FsUnit.fs index 6abf24d6..18915460 100644 --- a/src/FsUnit.Xunit/FsUnit.fs +++ b/src/FsUnit.Xunit/FsUnit.fs @@ -24,7 +24,10 @@ let inline should (f : 'a -> ^b) x (y : obj) = match y with | :? (unit -> unit) as assertFunc -> box assertFunc | _ -> y - Assert.That(y, c) + if box c = null then + Assert.That(y, IsNull()) + else + Assert.That(y, c) let inline shouldFail (f:unit->unit) = let failed = diff --git a/tests/FsUnit.MbUnit.Test/beNullTests.fs b/tests/FsUnit.MbUnit.Test/beNullTests.fs index 28545fe5..7987f9e6 100644 --- a/tests/FsUnit.MbUnit.Test/beNullTests.fs +++ b/tests/FsUnit.MbUnit.Test/beNullTests.fs @@ -11,12 +11,29 @@ type ``be Null tests`` ()= [] member test. ``null should fail to not be Null`` ()= - null |> should be Null + shouldFail (fun () -> null |> should not' (be Null)) [] member test. - ``non-null should fail to be Null`` ()= - "something" |> should not' (be Null) + ``non-null should fail to be Null`` ()= + shouldFail (fun () -> "something" |> should be Null) [] member test. ``non-null should not be Null`` ()= "something" |> should not' (be Null) + + [] member test. + ``null should be null`` ()= + null |> should be null + + [] member test. + ``null should fail to not be null`` ()= + shouldFail (fun () -> null |> should not' (be null)) + + [] member test. + ``non-null should fail to be null`` ()= + shouldFail (fun () -> "something" |> should be null) + + [] member test. + ``non-null should not be null`` ()= + "something" |> should not' (be null) + diff --git a/tests/FsUnit.MsTest.Test/beNullTests.fs b/tests/FsUnit.MsTest.Test/beNullTests.fs index 1c58f089..ad21c59c 100644 --- a/tests/FsUnit.MsTest.Test/beNullTests.fs +++ b/tests/FsUnit.MsTest.Test/beNullTests.fs @@ -11,12 +11,28 @@ type ``be Null tests`` ()= [] member test. ``null should fail to not be Null`` ()= - null |> should be Null + shouldFail (fun () -> null |> should not' (be Null)) [] member test. - ``non-null should fail to be Null`` ()= - "something" |> should not' (be Null) + ``non-null should fail to be Null`` ()= + shouldFail (fun () -> "something" |> should be Null) [] member test. ``non-null should not be Null`` ()= "something" |> should not' (be Null) + + [] member test. + ``null should be null`` ()= + null |> should be null + + [] member test. + ``null should fail to not be null`` ()= + shouldFail (fun () -> null |> should not' (be null)) + + [] member test. + ``non-null should fail to be null`` ()= + shouldFail (fun () -> "something" |> should be null) + + [] member test. + ``non-null should not be null`` ()= + "something" |> should not' (be null) diff --git a/tests/FsUnit.NUnit.Test/beNullTests.fs b/tests/FsUnit.NUnit.Test/beNullTests.fs index 5dc244ae..bd80519d 100644 --- a/tests/FsUnit.NUnit.Test/beNullTests.fs +++ b/tests/FsUnit.NUnit.Test/beNullTests.fs @@ -13,9 +13,25 @@ type ``be Null tests`` ()= shouldFail (fun () -> null |> should not' (be Null)) [] member test. - ``non-null should fail to be Null`` ()= + ``non-null should fail to be Null`` ()= shouldFail (fun () -> "something" |> should be Null) [] member test. ``non-null should not be Null`` ()= "something" |> should not' (be Null) + + [] member test. + ``null should be null`` ()= + null |> should be null + + [] member test. + ``null should fail to not be null`` ()= + shouldFail (fun () -> null |> should not' (be null)) + + [] member test. + ``non-null should fail to be null`` ()= + shouldFail (fun () -> "something" |> should be null) + + [] member test. + ``non-null should not be null`` ()= + "something" |> should not' (be null) diff --git a/tests/FsUnit.Xunit.Test/beNullTests.fs b/tests/FsUnit.Xunit.Test/beNullTests.fs index 2606e268..288f81a0 100644 --- a/tests/FsUnit.Xunit.Test/beNullTests.fs +++ b/tests/FsUnit.Xunit.Test/beNullTests.fs @@ -10,12 +10,28 @@ type ``be Null tests`` ()= [] member test. ``null should fail to not be Null`` ()= - null |> should be Null + shouldFail (fun () -> null |> should not' (be Null)) [] member test. - ``non-null should fail to be Null`` ()= - "something" |> should not' (be Null) + ``non-null should fail to be Null`` ()= + shouldFail (fun () -> "something" |> should be Null) [] member test. ``non-null should not be Null`` ()= "something" |> should not' (be Null) + + [] member test. + ``null should be null`` ()= + null |> should be null + + [] member test. + ``null should fail to not be null`` ()= + shouldFail (fun () -> null |> should not' (be null)) + + [] member test. + ``non-null should fail to be null`` ()= + shouldFail (fun () -> "something" |> should be null) + + [] member test. + ``non-null should not be null`` ()= + "something" |> should not' (be null)