diff --git a/src/FsUnit.MbUnit/FsUnit.fs b/src/FsUnit.MbUnit/FsUnit.fs index 337fb8d9..0b0b14f2 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 = @@ -27,7 +30,8 @@ let equal expected = CustomMatchers.equal expected let equalWithin (tolerance:obj) (expected:obj) = CustomMatchers.equalWithin tolerance expected -let not' (expected:obj) = CustomMatchers.not' expected +let not' (expected:obj) = + if box expected = null then CustomMatchers.not' (IsNull()) else (CustomMatchers.not' expected) let throw (t:Type) = CustomMatchers.throw t diff --git a/src/FsUnit.MsTestUnit/FsUnit.fs b/src/FsUnit.MsTestUnit/FsUnit.fs index 7af63fef..8faf303d 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 = @@ -37,7 +40,8 @@ let equal expected = CustomMatchers.equal expected let equalWithin (tolerance:obj) (expected:obj) = CustomMatchers.equalWithin tolerance expected -let not' (expected:obj) = CustomMatchers.not' expected +let not' (expected:obj) = + if box expected = null then CustomMatchers.not' (IsNull()) else (CustomMatchers.not' expected) let throw (t:Type) = CustomMatchers.throw t 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/FsUnit.fs b/src/FsUnit.Xunit/FsUnit.fs index 6abf24d6..4898c24f 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 = @@ -41,7 +44,8 @@ let equal expected = CustomMatchers.equal expected let equalWithin (tolerance:obj) (expected:obj) = CustomMatchers.equalWithin tolerance expected -let not' (expected:obj) = CustomMatchers.not' expected +let not' (expected:obj) = + if box expected = null then CustomMatchers.not' (IsNull()) else (CustomMatchers.not' expected) let throw (t:Type) = CustomMatchers.throw t 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)