From f7bd2fa2aa1c3b08748680fd2eb6df4ccf282997 Mon Sep 17 00:00:00 2001 From: Sergey Tihon Date: Tue, 2 Feb 2016 23:55:32 +0300 Subject: [PATCH 1/7] Added FsUnit.Typed module + tests --- src/FsUnit.NUnit/FsUnit.NUnit.fsproj | 1 + src/FsUnit.NUnit/FsUnit.Typed.fs | 57 +++++++++++++++ .../FsUnit.NUnit.Test.fsproj | 9 +++ tests/FsUnit.NUnit.Test/typed.beEmptyTests.fs | 29 ++++++++ .../typed.haveLengthTests.fs | 23 ++++++ .../typed.shouldBeGreaterThanTests.fs | 13 ++++ .../typed.shouldBeSmallerThanTests.fs | 13 ++++ .../typed.shouldContainTests.fs | 53 ++++++++++++++ .../typed.shouldContainText.fs | 14 ++++ .../typed.shouldEqualNullTests.fs | 13 ++++ .../typed.shouldEqualTests.fs | 70 +++++++++++++++++++ .../typed.shouldFailTests.fs | 17 +++++ 12 files changed, 312 insertions(+) create mode 100644 src/FsUnit.NUnit/FsUnit.Typed.fs create mode 100644 tests/FsUnit.NUnit.Test/typed.beEmptyTests.fs create mode 100644 tests/FsUnit.NUnit.Test/typed.haveLengthTests.fs create mode 100644 tests/FsUnit.NUnit.Test/typed.shouldBeGreaterThanTests.fs create mode 100644 tests/FsUnit.NUnit.Test/typed.shouldBeSmallerThanTests.fs create mode 100644 tests/FsUnit.NUnit.Test/typed.shouldContainTests.fs create mode 100644 tests/FsUnit.NUnit.Test/typed.shouldContainText.fs create mode 100644 tests/FsUnit.NUnit.Test/typed.shouldEqualNullTests.fs create mode 100644 tests/FsUnit.NUnit.Test/typed.shouldEqualTests.fs create mode 100644 tests/FsUnit.NUnit.Test/typed.shouldFailTests.fs diff --git a/src/FsUnit.NUnit/FsUnit.NUnit.fsproj b/src/FsUnit.NUnit/FsUnit.NUnit.fsproj index dca1b6ac..d0439868 100644 --- a/src/FsUnit.NUnit/FsUnit.NUnit.fsproj +++ b/src/FsUnit.NUnit/FsUnit.NUnit.fsproj @@ -54,6 +54,7 @@ + CustomMatchers.fs diff --git a/src/FsUnit.NUnit/FsUnit.Typed.fs b/src/FsUnit.NUnit/FsUnit.Typed.fs new file mode 100644 index 00000000..7e741d04 --- /dev/null +++ b/src/FsUnit.NUnit/FsUnit.Typed.fs @@ -0,0 +1,57 @@ +namespace FsUnit + +open System.Diagnostics +open NUnit.Framework +open System.Collections.Generic + +module Typed = + [] + let shouldEqual (expected : 'a) (actual : 'a) = Assert.AreEqual(expected, actual, sprintf "Expected: %A\nActual: %A" expected actual) + + [] + let shouldNotEqual (expected : 'a) (actual : 'a) = Assert.AreNotEqual(expected, actual, sprintf "Expected: %A\nActual: %A" expected actual) + + [] + let shouldContain (x : 'a) (y : 'a seq) = + let list = List<_>() + for a in y do + list.Add a + Assert.Contains(x, list) + + [] + let shouldBeEmpty (list : 'a seq) = + Assert.IsEmpty(list) + + [] + let shouldNotContain (x : 'a) (y : 'a seq) = + if Seq.exists ((=) x) y then failwithf "Seq %A should not contain %A" y x + + [] + let shouldBeSmallerThan (x : 'a) (y : 'a) = Assert.GreaterOrEqual(x, y, sprintf "Expected: %A\nActual: %A" x y) + + [] + let shouldBeGreaterThan (x : 'a) (y : 'a) = Assert.Greater(y, x, sprintf "Expected: %A\nActual: %A" x y) + + [] + let shouldFail<'exn when 'exn :> exn> (f : unit -> unit) = + let succeeded = ref false + try + f() + succeeded := true + with + | exn -> + if exn :? 'exn then () else + failwithf "Exception was not of type %s" <| typeof<'exn>.ToString() + if !succeeded then + failwith "Operation did not fail." + + [] + let shouldContainText (x : string) (y : string) = + if y.Contains(x) |> not then + failwithf "\"%s\" is not a substring of \"%s\"" x y + + [] + let shouldHaveLength expected list = + let actual = Seq.length list + if actual <> expected then + failwithf "Invalid length in %A\r\nExpected: %i\r\nActual: %i" list expected actual \ No newline at end of file diff --git a/tests/FsUnit.NUnit.Test/FsUnit.NUnit.Test.fsproj b/tests/FsUnit.NUnit.Test/FsUnit.NUnit.Test.fsproj index a60b663d..1155654d 100644 --- a/tests/FsUnit.NUnit.Test/FsUnit.NUnit.Test.fsproj +++ b/tests/FsUnit.NUnit.Test/FsUnit.NUnit.Test.fsproj @@ -78,6 +78,15 @@ + + + + + + + + + diff --git a/tests/FsUnit.NUnit.Test/typed.beEmptyTests.fs b/tests/FsUnit.NUnit.Test/typed.beEmptyTests.fs new file mode 100644 index 00000000..4684102c --- /dev/null +++ b/tests/FsUnit.NUnit.Test/typed.beEmptyTests.fs @@ -0,0 +1,29 @@ +namespace FsUnit.Typed.Test +open NUnit.Framework +open FsUnit.Typed + +[] +type ``shouldBeEmpty tests`` ()= + [] member test. + ``empty List should be Empty`` ()= + [] |> shouldBeEmpty + + [] member test. + ``non-empty List should fail to be Empty`` ()= + shouldFail (fun () -> [1] |> shouldBeEmpty) + + [] member test. + ``empty Array should be Empty`` ()= + [||] |> shouldBeEmpty + + [] member test. + ``non-empty Array should fail to be Empty`` ()= + shouldFail (fun () -> [|1|] |> shouldBeEmpty) + + [] member test. + ``empty Seq should be Empty`` ()= + Seq.empty |> shouldBeEmpty + + [] member test. + ``non-empty Seq should fail to be Empty`` ()= + shouldFail (fun () -> seq { yield 1 } |> shouldBeEmpty) \ No newline at end of file diff --git a/tests/FsUnit.NUnit.Test/typed.haveLengthTests.fs b/tests/FsUnit.NUnit.Test/typed.haveLengthTests.fs new file mode 100644 index 00000000..a303f689 --- /dev/null +++ b/tests/FsUnit.NUnit.Test/typed.haveLengthTests.fs @@ -0,0 +1,23 @@ +namespace FsUnit.Typed.Test +open NUnit.Framework +open FsUnit.Typed + +[] +type ``haveLength tests`` ()= + // F# List + [] member test. + ``List with 1 item should have Length 1`` ()= + [1] |> shouldHaveLength 1 + + [] member test. + ``empty List should fail to have Length 1`` ()= + shouldFail (fun () -> [] |> shouldHaveLength 1) + + // Array + [] member test. + ``Array with 1 item should have Length 1`` ()= + [|1|] |> shouldHaveLength 1 + + [] member test. + ``empty Array should fail to have Length 1`` ()= + shouldFail (fun () -> [||] |> shouldHaveLength 1) \ No newline at end of file diff --git a/tests/FsUnit.NUnit.Test/typed.shouldBeGreaterThanTests.fs b/tests/FsUnit.NUnit.Test/typed.shouldBeGreaterThanTests.fs new file mode 100644 index 00000000..726ab8bc --- /dev/null +++ b/tests/FsUnit.NUnit.Test/typed.shouldBeGreaterThanTests.fs @@ -0,0 +1,13 @@ +namespace FsUnit.Typed.Test +open NUnit.Framework +open FsUnit.Typed + +[] +type ``shouldBeGreaterThan tests`` ()= + [] member test. + ``11 should be greater than 10`` ()= + 11 |> shouldBeGreaterThan 10 + + [] member test. + ``11.1 should be greater than 11.0`` ()= + 11.1 |> shouldBeGreaterThan 11.0 \ No newline at end of file diff --git a/tests/FsUnit.NUnit.Test/typed.shouldBeSmallerThanTests.fs b/tests/FsUnit.NUnit.Test/typed.shouldBeSmallerThanTests.fs new file mode 100644 index 00000000..5f9479e9 --- /dev/null +++ b/tests/FsUnit.NUnit.Test/typed.shouldBeSmallerThanTests.fs @@ -0,0 +1,13 @@ +namespace FsUnit.Typed.Test +open NUnit.Framework +open FsUnit.Typed + +[] +type ``shouldBeSmallerThan tests`` ()= + [] member test. + ``10 should be less than 11`` ()= + 10 |> shouldBeSmallerThan 11 + + [] member test. + ``10.0 should be less than 10.1`` ()= + 10.0 |> shouldBeSmallerThan 10.1 diff --git a/tests/FsUnit.NUnit.Test/typed.shouldContainTests.fs b/tests/FsUnit.NUnit.Test/typed.shouldContainTests.fs new file mode 100644 index 00000000..bd4b87f0 --- /dev/null +++ b/tests/FsUnit.NUnit.Test/typed.shouldContainTests.fs @@ -0,0 +1,53 @@ +namespace FsUnit.Typed.Test +open NUnit.Framework +open FsUnit.Typed + +[] +type ``shouldContain tests`` ()= + [] member test. + ``List with item should contain item`` ()= + [1] |> shouldContain 1 + + [] member test. + ``empty List should fail to contain item`` ()= + shouldFail (fun () -> [] |> shouldContain 1) + + [] member test. + ``empty List should not contain item`` ()= + [] |> shouldNotContain 1 + + [] member test. + ``List with item should fail to not contain item`` ()= + shouldFail (fun () -> [1] |> shouldNotContain 1) + + [] member test. + ``Array with item should contain item`` ()= + [|1|] |> shouldContain 1 + + [] member test. + ``empty Array should fail to contain item`` ()= + shouldFail (fun () -> [||] |> shouldContain 1) + + [] member test. + ``empty Array should not contain item`` ()= + [||] |> shouldNotContain 1 + + [] member test. + ``Array with item should fail to not contain item`` ()= + shouldFail (fun () -> [|1|] |> shouldNotContain 1) + + [] member test. + ``Seq with item should contain item`` ()= + seq { yield 1 } |> shouldContain 1 + + [] member test. + ``empty Seq should fail to contain item`` ()= + shouldFail (fun () -> Seq.empty |> shouldContain 1) + + [] member test. + ``empty Seq should not contain item`` ()= + Seq.empty |> shouldNotContain 1 + + [] member test. + ``Seq with item should fail to not contain item`` ()= + shouldFail (fun () -> seq { yield 1 } |> shouldNotContain 1) \ No newline at end of file diff --git a/tests/FsUnit.NUnit.Test/typed.shouldContainText.fs b/tests/FsUnit.NUnit.Test/typed.shouldContainText.fs new file mode 100644 index 00000000..53fe5a1d --- /dev/null +++ b/tests/FsUnit.NUnit.Test/typed.shouldContainText.fs @@ -0,0 +1,14 @@ +namespace FsUnit.Typed.Test +open NUnit.Framework +open FsUnit.Typed + +[] +type ``shouldContainText tests`` ()= + [] member test. + ``empty string should contain ""`` ()= + "" |> shouldContainText "" + + [] member test. + ``ships should contain hip`` ()= + "ships" |> shouldContainText "hip" + diff --git a/tests/FsUnit.NUnit.Test/typed.shouldEqualNullTests.fs b/tests/FsUnit.NUnit.Test/typed.shouldEqualNullTests.fs new file mode 100644 index 00000000..a2d3082f --- /dev/null +++ b/tests/FsUnit.NUnit.Test/typed.shouldEqualNullTests.fs @@ -0,0 +1,13 @@ +namespace FsUnit.Typed.Test +open NUnit.Framework +open FsUnit.Typed + +[] +type ``Typed: shouldEqual null tests`` ()= + [] member test. + ``null should be null`` ()= + null |> shouldEqual null + + [] member test. + ``null should fail to not be null`` ()= + shouldFail (fun () -> null |> shouldNotEqual null) diff --git a/tests/FsUnit.NUnit.Test/typed.shouldEqualTests.fs b/tests/FsUnit.NUnit.Test/typed.shouldEqualTests.fs new file mode 100644 index 00000000..b136db15 --- /dev/null +++ b/tests/FsUnit.NUnit.Test/typed.shouldEqualTests.fs @@ -0,0 +1,70 @@ +namespace FsUnit.Typed.Test +open NUnit.Framework +open FsUnit.Typed + +type AlwaysEqual() = + override this.Equals(other) = true + override this.GetHashCode() = 1 + + +type NeverEqual() = + override this.Equals(other) = false + override this.GetHashCode() = 1 + + +[] +type ``shouldEqual Tests`` ()= + let anObj = new obj() + let otherObj = new obj() + + [] member test. + ``value type should equal equivalent value`` ()= + 1 |> shouldEqual 1 + + [] member test. + ``value type should fail to equal nonequivalent value`` ()= + shouldFail (fun () -> 1 |> shouldEqual 2) + + [] member test. + ``value type should not equal nonequivalent value`` ()= + 1 |> shouldNotEqual 2 + + [] member test. + ``value type should fail to not equal equivalent value`` ()= + shouldFail (fun () -> 1 |> shouldNotEqual 1) + + [] member test. + ``reference type should equal itself`` ()= + anObj |> shouldEqual anObj + + [] member test. + ``reference type should fail to equal other`` ()= + shouldFail (fun () -> anObj |> shouldEqual otherObj) + + [] member test. + ``reference type should not equal other`` ()= + anObj |> shouldNotEqual otherObj + + [] member test. + ``reference type should fail to not equal itself`` ()= + shouldFail (fun () -> anObj |> shouldNotEqual anObj) + + [] member test. + ``should pass when Equals returns true`` ()= + anObj |> shouldEqual (box(new AlwaysEqual())) + + [] member test. + ``should fail when Equals returns false`` ()= + shouldFail (fun () -> anObj |> shouldEqual (box(new NeverEqual()))) + + [] member test. + ``should pass when negated and Equals returns false`` ()= + anObj |> shouldNotEqual (box(new NeverEqual())) + + [] member test. + ``should fail when negated and Equals returns true`` ()= + shouldFail (fun () -> anObj |>shouldNotEqual (box(new AlwaysEqual()))) + + [] member test. + ``None should equal None`` ()= + None |> shouldEqual None diff --git a/tests/FsUnit.NUnit.Test/typed.shouldFailTests.fs b/tests/FsUnit.NUnit.Test/typed.shouldFailTests.fs new file mode 100644 index 00000000..49b94a9d --- /dev/null +++ b/tests/FsUnit.NUnit.Test/typed.shouldFailTests.fs @@ -0,0 +1,17 @@ +namespace FsUnit.Typed.Test +open NUnit.Framework +open FsUnit.Typed + +[] +type ``shouldFail tests`` ()= + [] member test. + ``empty List should fail to contain item`` ()= + shouldFail (fun () -> [] |> shouldContain 1) + + [] member test. + ``non-null should fail to be Null`` ()= + shouldFail (fun () -> "something" |> shouldEqual null) + + [] member test. + ``shouldFail should fail when everything is OK`` ()= + shouldFail (fun () -> shouldFail id) \ No newline at end of file From 3d6be9ea85fba375595af2d4af0c240fba087066 Mon Sep 17 00:00:00 2001 From: Sergey Tihon Date: Mon, 8 Feb 2016 18:12:47 +0300 Subject: [PATCH 2/7] Added structural equality test for `FsUnit.Typed` https://github.com/fsprojects/FsUnit/issues/78 --- tests/FsUnit.NUnit.Test/typed.shouldEqualTests.fs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/FsUnit.NUnit.Test/typed.shouldEqualTests.fs b/tests/FsUnit.NUnit.Test/typed.shouldEqualTests.fs index b136db15..bcce535c 100644 --- a/tests/FsUnit.NUnit.Test/typed.shouldEqualTests.fs +++ b/tests/FsUnit.NUnit.Test/typed.shouldEqualTests.fs @@ -68,3 +68,8 @@ type ``shouldEqual Tests`` ()= [] member test. ``None should equal None`` ()= None |> shouldEqual None + + [] member this. + ``structural equality`` () = + let actualList: char list = [] in + [(actualList, "")] |> shouldEqual [([], "")] From 9a6b6b17a38c09f72179927e6eed33c7fb1c63e7 Mon Sep 17 00:00:00 2001 From: Sergey Tihon Date: Sun, 6 Mar 2016 23:07:28 +0300 Subject: [PATCH 3/7] NUnit equality replaced by F# struct equality --- src/FsUnit.NUnit/FsUnit.Typed.fs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/FsUnit.NUnit/FsUnit.Typed.fs b/src/FsUnit.NUnit/FsUnit.Typed.fs index 7e741d04..d283fccf 100644 --- a/src/FsUnit.NUnit/FsUnit.Typed.fs +++ b/src/FsUnit.NUnit/FsUnit.Typed.fs @@ -6,10 +6,12 @@ open System.Collections.Generic module Typed = [] - let shouldEqual (expected : 'a) (actual : 'a) = Assert.AreEqual(expected, actual, sprintf "Expected: %A\nActual: %A" expected actual) + let shouldEqual (expected : 'a) (actual : 'a) = + Assert.IsTrue(expected.Equals(actual), sprintf "Expected: %A\nActual: %A" expected actual) [] - let shouldNotEqual (expected : 'a) (actual : 'a) = Assert.AreNotEqual(expected, actual, sprintf "Expected: %A\nActual: %A" expected actual) + let shouldNotEqual (expected : 'a) (actual : 'a) = + Assert.IsFalse(expected.Equals(actual), sprintf "Expected: %A\nActual: %A" expected actual) [] let shouldContain (x : 'a) (y : 'a seq) = @@ -27,10 +29,12 @@ module Typed = if Seq.exists ((=) x) y then failwithf "Seq %A should not contain %A" y x [] - let shouldBeSmallerThan (x : 'a) (y : 'a) = Assert.GreaterOrEqual(x, y, sprintf "Expected: %A\nActual: %A" x y) + let shouldBeSmallerThan (x : 'a) (y : 'a) = + Assert.GreaterOrEqual(x, y, sprintf "Expected: %A\nActual: %A" x y) [] - let shouldBeGreaterThan (x : 'a) (y : 'a) = Assert.Greater(y, x, sprintf "Expected: %A\nActual: %A" x y) + let shouldBeGreaterThan (x : 'a) (y : 'a) = + Assert.Greater(y, x, sprintf "Expected: %A\nActual: %A" x y) [] let shouldFail<'exn when 'exn :> exn> (f : unit -> unit) = From 8253c9b2e622cdb58b06a6f198e4a2fe6f2cf4de Mon Sep 17 00:00:00 2001 From: Sergey Tihon Date: Sun, 6 Mar 2016 23:23:14 +0300 Subject: [PATCH 4/7] expected value can be null --- src/FsUnit.NUnit/FsUnit.Typed.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FsUnit.NUnit/FsUnit.Typed.fs b/src/FsUnit.NUnit/FsUnit.Typed.fs index d283fccf..d2188c83 100644 --- a/src/FsUnit.NUnit/FsUnit.Typed.fs +++ b/src/FsUnit.NUnit/FsUnit.Typed.fs @@ -7,11 +7,11 @@ open System.Collections.Generic module Typed = [] let shouldEqual (expected : 'a) (actual : 'a) = - Assert.IsTrue(expected.Equals(actual), sprintf "Expected: %A\nActual: %A" expected actual) + Assert.IsTrue((expected = actual), sprintf "Expected: %A\nActual: %A" expected actual) [] let shouldNotEqual (expected : 'a) (actual : 'a) = - Assert.IsFalse(expected.Equals(actual), sprintf "Expected: %A\nActual: %A" expected actual) + Assert.IsFalse((expected = actual), sprintf "Expected: %A\nActual: %A" expected actual) [] let shouldContain (x : 'a) (y : 'a seq) = From 6ecd81dcb794f935e4573328e71835325235b75d Mon Sep 17 00:00:00 2001 From: Sergey Tihon Date: Mon, 7 Mar 2016 00:51:47 +0300 Subject: [PATCH 5/7] Added test case from #20 --- tests/FsUnit.NUnit.Test/typed.shouldFailTests.fs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/FsUnit.NUnit.Test/typed.shouldFailTests.fs b/tests/FsUnit.NUnit.Test/typed.shouldFailTests.fs index 49b94a9d..6ad44cb5 100644 --- a/tests/FsUnit.NUnit.Test/typed.shouldFailTests.fs +++ b/tests/FsUnit.NUnit.Test/typed.shouldFailTests.fs @@ -14,4 +14,8 @@ type ``shouldFail tests`` ()= [] member test. ``shouldFail should fail when everything is OK`` ()= - shouldFail (fun () -> shouldFail id) \ No newline at end of file + shouldFail (fun () -> shouldFail id) + + [] member test. + ``Simplify "should throw"``() = + (fun () -> failwith "BOOM!") |> shouldFail \ No newline at end of file From 7ba59cb0b78ab495bbd190510fd2c5b10cabdd36 Mon Sep 17 00:00:00 2001 From: Sergey Tihon Date: Mon, 7 Mar 2016 01:37:21 +0300 Subject: [PATCH 6/7] Added docs --- FsUnit.sln | 3 +- docs/content/FsUnit.Typed.fsx | 98 ++++++++++++++++++++++++++++ docs/tools/templates/template.cshtml | 9 ++- 3 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 docs/content/FsUnit.Typed.fsx diff --git a/FsUnit.sln b/FsUnit.sln index 16c0cf10..deec4868 100644 --- a/FsUnit.sln +++ b/FsUnit.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.23107.0 +VisualStudioVersion = 14.0.24720.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FsUnit.NUnit", "src\FsUnit.NUnit\FsUnit.NUnit.fsproj", "{3890DC0F-5225-4ADF-9B9E-F6A482046A9E}" EndProject @@ -32,6 +32,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "content", "content", "{0BEF7A55-F158-4691-886C-1AF2FE12DD7C}" ProjectSection(SolutionItems) = preProject docs\content\FsCheck.fsx = docs\content\FsCheck.fsx + docs\content\FsUnit.Typed.fsx = docs\content\FsUnit.Typed.fsx docs\content\index.fsx = docs\content\index.fsx docs\content\MbUnit.fsx = docs\content\MbUnit.fsx docs\content\MsTest.fsx = docs\content\MsTest.fsx diff --git a/docs/content/FsUnit.Typed.fsx b/docs/content/FsUnit.Typed.fsx new file mode 100644 index 00000000..44a33e2f --- /dev/null +++ b/docs/content/FsUnit.Typed.fsx @@ -0,0 +1,98 @@ +(*** hide ***) +// This block of code is omitted in the generated HTML documentation. Use +// it to define helpers that you do not want to show in the documentation. +#I "../../bin/FsUnit.NUnit/" +#r "NUnit.Framework.dll" +#r "FsUnit.NUnit.dll" + +(** +What is FsUnit.Typed? +=============== + +**FsUnit.Typed** is a strongly typed subset of FsUnit operators that makes +unit-testing with `FsUnit` even more safe and enjoyable (Available only for `NUnit 3`). + +FsUnit.Typed from NuGet +----------------------- + +The `FsUnit.Typed` is part of `FsUnit` package for NUnit and can be [installed from NuGet](https://nuget.org/packages/FsUnit). + +FsUnit.Typed with Paket +----------------------- + +`FsUnit.Typed` supports lightweight usage scenario with [Paket](http://fsprojects.github.io/Paket/). + +In the case when you do not want to add dependency on [FsUnit](https://www.nuget.org/packages/FsUnit/) +package to your project, you can add reference to [FsUnit.Typed.fs](https://github.com/fsprojects/FsUnit/blob/master/src/FsUnit.NUnit/FsUnit.Typed.fs) +file and [NUnit](https://www.nuget.org/packages/NUnit/) package. + +Example of `paket.dependencies` file: + + [lang=paket] + source https://nuget.org/api/v2 + + nuget FSharp.Core + github fsprojects/FsUnit src/FsUnit.NUnit/FsUnit.Typed.fs + + group Test + source https://nuget.org/api/v2 + nuget NUnit.Console + nuget NUnit + +Example of `paket.reference` file for test projects: + + [lang=paket] + File:FsUnit.Typed.fs + group Test + NUnit + +Syntax +------- + +With FsUnit.Typed, you can write unit tests like this: +*) + +open NUnit.Framework +open FsUnit.Typed + +(** +One object equals or does not equal another: +*) + +1 |> shouldEqual 1 +1 |> shouldNotEqual 2 + +(** +One comparable value greater or smaller than another: +*) + +11 |> shouldBeGreaterThan 10 +10 |> shouldBeSmallerThan 11 + + +(** +A string contains specified substring: +*) +"ships" |> shouldContainText "hip" + +(** +A List, Seq, or Array instance contains, does not contain a value or empty: +*) +[1] |> shouldContain 1 +[] |> shouldNotContain 1 +[] |> shouldBeEmpty + +(** +A List or Array instance has a certain length: +*) +[|1;2;3;4|] |> shouldHaveLength 4 + +(** +A function should throw a certain type of exception: +*) +(fun _ -> failwith "BOOM!") |> shouldFail + +(** +A function should fail +*) +shouldFail (fun _ -> 5/0 |> ignore) diff --git a/docs/tools/templates/template.cshtml b/docs/tools/templates/template.cshtml index 46db257c..1f016389 100644 --- a/docs/tools/templates/template.cshtml +++ b/docs/tools/templates/template.cshtml @@ -47,14 +47,13 @@
  • Release Notes
  • -
  • NUnit
  • +
  • NUnit Classic
  • +
  • Lightweight FsUnit with Paket
  • +
  • FsUnit.Typed
  • +
  • xUnit
  • MbUnit
  • MsTest
  • -
  • -
  • Paket
  • -
  • FsCheck
  • -
  • Operators
  • From 49e5ce195591bb5c73fd91b1acc5eed772b789b1 Mon Sep 17 00:00:00 2001 From: Sergey Tihon Date: Mon, 7 Mar 2016 10:05:14 +0300 Subject: [PATCH 7/7] `FsUnit.Typed` renamed to `FsUnitTyped` to allow import of only one set of operators --- FsUnit.sln | 2 +- .../{FsUnit.Typed.fsx => FsUnitTyped.fsx} | 26 +++++++++++-------- docs/tools/templates/template.cshtml | 4 +-- src/FsUnit.NUnit/FsUnit.NUnit.fsproj | 2 +- .../{FsUnit.Typed.fs => FsUnitTyped.fs} | 5 ++-- tests/FsUnit.NUnit.Test/typed.beEmptyTests.fs | 2 +- .../typed.haveLengthTests.fs | 2 +- .../typed.shouldBeGreaterThanTests.fs | 2 +- .../typed.shouldBeSmallerThanTests.fs | 2 +- .../typed.shouldContainTests.fs | 2 +- .../typed.shouldContainText.fs | 2 +- .../typed.shouldEqualNullTests.fs | 2 +- .../typed.shouldEqualTests.fs | 2 +- .../typed.shouldFailTests.fs | 2 +- 14 files changed, 31 insertions(+), 26 deletions(-) rename docs/content/{FsUnit.Typed.fsx => FsUnitTyped.fsx} (73%) rename src/FsUnit.NUnit/{FsUnit.Typed.fs => FsUnitTyped.fs} (96%) diff --git a/FsUnit.sln b/FsUnit.sln index deec4868..7b0beab0 100644 --- a/FsUnit.sln +++ b/FsUnit.sln @@ -32,7 +32,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "content", "content", "{0BEF7A55-F158-4691-886C-1AF2FE12DD7C}" ProjectSection(SolutionItems) = preProject docs\content\FsCheck.fsx = docs\content\FsCheck.fsx - docs\content\FsUnit.Typed.fsx = docs\content\FsUnit.Typed.fsx + docs\content\FsUnitTyped.fsx = docs\content\FsUnitTyped.fsx docs\content\index.fsx = docs\content\index.fsx docs\content\MbUnit.fsx = docs\content\MbUnit.fsx docs\content\MsTest.fsx = docs\content\MsTest.fsx diff --git a/docs/content/FsUnit.Typed.fsx b/docs/content/FsUnitTyped.fsx similarity index 73% rename from docs/content/FsUnit.Typed.fsx rename to docs/content/FsUnitTyped.fsx index 44a33e2f..ad286227 100644 --- a/docs/content/FsUnit.Typed.fsx +++ b/docs/content/FsUnitTyped.fsx @@ -6,24 +6,28 @@ #r "FsUnit.NUnit.dll" (** -What is FsUnit.Typed? +What is FsUnitTyped? =============== -**FsUnit.Typed** is a strongly typed subset of FsUnit operators that makes -unit-testing with `FsUnit` even more safe and enjoyable (Available only for `NUnit 3`). +**FsUnitTyped** is a statically typed set of FsUnit operators that makes +unit-testing with `FsUnit` even more safe and enjoyable (Available only for `NUnit`). -FsUnit.Typed from NuGet +No more untyped constrains and tests like + + 1 |> should equal "1" + +FsUnitTyped from NuGet ----------------------- The `FsUnit.Typed` is part of `FsUnit` package for NUnit and can be [installed from NuGet](https://nuget.org/packages/FsUnit). -FsUnit.Typed with Paket +FsUnitTyped with Paket ----------------------- -`FsUnit.Typed` supports lightweight usage scenario with [Paket](http://fsprojects.github.io/Paket/). +`FsUnitTyped` supports lightweight usage scenario with [Paket](http://fsprojects.github.io/Paket/). In the case when you do not want to add dependency on [FsUnit](https://www.nuget.org/packages/FsUnit/) -package to your project, you can add reference to [FsUnit.Typed.fs](https://github.com/fsprojects/FsUnit/blob/master/src/FsUnit.NUnit/FsUnit.Typed.fs) +package to your project, you can add reference to [FsUnitTyped.fs](https://github.com/fsprojects/FsUnit/blob/master/src/FsUnit.NUnit/FsUnit.Typed.fs) file and [NUnit](https://www.nuget.org/packages/NUnit/) package. Example of `paket.dependencies` file: @@ -32,7 +36,7 @@ Example of `paket.dependencies` file: source https://nuget.org/api/v2 nuget FSharp.Core - github fsprojects/FsUnit src/FsUnit.NUnit/FsUnit.Typed.fs + github fsprojects/FsUnit src/FsUnit.NUnit/FsUnitTyped.fs group Test source https://nuget.org/api/v2 @@ -42,18 +46,18 @@ Example of `paket.dependencies` file: Example of `paket.reference` file for test projects: [lang=paket] - File:FsUnit.Typed.fs + File:FsUnitTyped.fs group Test NUnit Syntax ------- -With FsUnit.Typed, you can write unit tests like this: +With FsUnitTyped, you can write unit tests like this: *) open NUnit.Framework -open FsUnit.Typed +open FsUnitTyped (** One object equals or does not equal another: diff --git a/docs/tools/templates/template.cshtml b/docs/tools/templates/template.cshtml index 1f016389..c618e1cf 100644 --- a/docs/tools/templates/template.cshtml +++ b/docs/tools/templates/template.cshtml @@ -49,11 +49,11 @@
  • NUnit Classic
  • Lightweight FsUnit with Paket
  • -
  • FsUnit.Typed
  • +
  • FsUnitTyped
  • xUnit
  • -
  • MbUnit
  • MsTest
  • +
  • MbUnit
  • Operators
  • diff --git a/src/FsUnit.NUnit/FsUnit.NUnit.fsproj b/src/FsUnit.NUnit/FsUnit.NUnit.fsproj index d0439868..0c2f319a 100644 --- a/src/FsUnit.NUnit/FsUnit.NUnit.fsproj +++ b/src/FsUnit.NUnit/FsUnit.NUnit.fsproj @@ -54,7 +54,7 @@ - + CustomMatchers.fs diff --git a/src/FsUnit.NUnit/FsUnit.Typed.fs b/src/FsUnit.NUnit/FsUnitTyped.fs similarity index 96% rename from src/FsUnit.NUnit/FsUnit.Typed.fs rename to src/FsUnit.NUnit/FsUnitTyped.fs index d2188c83..8d59e9d8 100644 --- a/src/FsUnit.NUnit/FsUnit.Typed.fs +++ b/src/FsUnit.NUnit/FsUnitTyped.fs @@ -1,10 +1,11 @@ -namespace FsUnit +namespace FsUnitTyped open System.Diagnostics open NUnit.Framework open System.Collections.Generic -module Typed = +[] +module TopLevelOperators = [] let shouldEqual (expected : 'a) (actual : 'a) = Assert.IsTrue((expected = actual), sprintf "Expected: %A\nActual: %A" expected actual) diff --git a/tests/FsUnit.NUnit.Test/typed.beEmptyTests.fs b/tests/FsUnit.NUnit.Test/typed.beEmptyTests.fs index 4684102c..5fcf7f50 100644 --- a/tests/FsUnit.NUnit.Test/typed.beEmptyTests.fs +++ b/tests/FsUnit.NUnit.Test/typed.beEmptyTests.fs @@ -1,6 +1,6 @@ namespace FsUnit.Typed.Test open NUnit.Framework -open FsUnit.Typed +open FsUnitTyped [] type ``shouldBeEmpty tests`` ()= diff --git a/tests/FsUnit.NUnit.Test/typed.haveLengthTests.fs b/tests/FsUnit.NUnit.Test/typed.haveLengthTests.fs index a303f689..b4d6a415 100644 --- a/tests/FsUnit.NUnit.Test/typed.haveLengthTests.fs +++ b/tests/FsUnit.NUnit.Test/typed.haveLengthTests.fs @@ -1,6 +1,6 @@ namespace FsUnit.Typed.Test open NUnit.Framework -open FsUnit.Typed +open FsUnitTyped [] type ``haveLength tests`` ()= diff --git a/tests/FsUnit.NUnit.Test/typed.shouldBeGreaterThanTests.fs b/tests/FsUnit.NUnit.Test/typed.shouldBeGreaterThanTests.fs index 726ab8bc..8b8d6187 100644 --- a/tests/FsUnit.NUnit.Test/typed.shouldBeGreaterThanTests.fs +++ b/tests/FsUnit.NUnit.Test/typed.shouldBeGreaterThanTests.fs @@ -1,6 +1,6 @@ namespace FsUnit.Typed.Test open NUnit.Framework -open FsUnit.Typed +open FsUnitTyped [] type ``shouldBeGreaterThan tests`` ()= diff --git a/tests/FsUnit.NUnit.Test/typed.shouldBeSmallerThanTests.fs b/tests/FsUnit.NUnit.Test/typed.shouldBeSmallerThanTests.fs index 5f9479e9..77717d99 100644 --- a/tests/FsUnit.NUnit.Test/typed.shouldBeSmallerThanTests.fs +++ b/tests/FsUnit.NUnit.Test/typed.shouldBeSmallerThanTests.fs @@ -1,6 +1,6 @@ namespace FsUnit.Typed.Test open NUnit.Framework -open FsUnit.Typed +open FsUnitTyped [] type ``shouldBeSmallerThan tests`` ()= diff --git a/tests/FsUnit.NUnit.Test/typed.shouldContainTests.fs b/tests/FsUnit.NUnit.Test/typed.shouldContainTests.fs index bd4b87f0..37b8baa9 100644 --- a/tests/FsUnit.NUnit.Test/typed.shouldContainTests.fs +++ b/tests/FsUnit.NUnit.Test/typed.shouldContainTests.fs @@ -1,6 +1,6 @@ namespace FsUnit.Typed.Test open NUnit.Framework -open FsUnit.Typed +open FsUnitTyped [] type ``shouldContain tests`` ()= diff --git a/tests/FsUnit.NUnit.Test/typed.shouldContainText.fs b/tests/FsUnit.NUnit.Test/typed.shouldContainText.fs index 53fe5a1d..99b22d2c 100644 --- a/tests/FsUnit.NUnit.Test/typed.shouldContainText.fs +++ b/tests/FsUnit.NUnit.Test/typed.shouldContainText.fs @@ -1,6 +1,6 @@ namespace FsUnit.Typed.Test open NUnit.Framework -open FsUnit.Typed +open FsUnitTyped [] type ``shouldContainText tests`` ()= diff --git a/tests/FsUnit.NUnit.Test/typed.shouldEqualNullTests.fs b/tests/FsUnit.NUnit.Test/typed.shouldEqualNullTests.fs index a2d3082f..4c3a8981 100644 --- a/tests/FsUnit.NUnit.Test/typed.shouldEqualNullTests.fs +++ b/tests/FsUnit.NUnit.Test/typed.shouldEqualNullTests.fs @@ -1,6 +1,6 @@ namespace FsUnit.Typed.Test open NUnit.Framework -open FsUnit.Typed +open FsUnitTyped [] type ``Typed: shouldEqual null tests`` ()= diff --git a/tests/FsUnit.NUnit.Test/typed.shouldEqualTests.fs b/tests/FsUnit.NUnit.Test/typed.shouldEqualTests.fs index bcce535c..09d8018b 100644 --- a/tests/FsUnit.NUnit.Test/typed.shouldEqualTests.fs +++ b/tests/FsUnit.NUnit.Test/typed.shouldEqualTests.fs @@ -1,6 +1,6 @@ namespace FsUnit.Typed.Test open NUnit.Framework -open FsUnit.Typed +open FsUnitTyped type AlwaysEqual() = override this.Equals(other) = true diff --git a/tests/FsUnit.NUnit.Test/typed.shouldFailTests.fs b/tests/FsUnit.NUnit.Test/typed.shouldFailTests.fs index 6ad44cb5..43542a2d 100644 --- a/tests/FsUnit.NUnit.Test/typed.shouldFailTests.fs +++ b/tests/FsUnit.NUnit.Test/typed.shouldFailTests.fs @@ -1,6 +1,6 @@ namespace FsUnit.Typed.Test open NUnit.Framework -open FsUnit.Typed +open FsUnitTyped [] type ``shouldFail tests`` ()=