-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add typed aliases around Xunit (#203)
* Add typed aliases around Xunit * Add typed tests * Add missing line * Update doc * Include in fsproj files * Trying to get it to compile - GitHub please tell me if this worked * Fix syntax error * Fix more errors * Fix contains error * Fix more errors * Fix brackets * Pipeline, please tell me what exception gets thrown * feat: fantomas format * Fix all but a couple of equality tests * Format * Fix remaining tests * Push tests that demonstrate inconsistency * Document bug 207 * And document instance in XUnit typed test * Lint nits * fix: actual/expected naming * Revert tests which demonstrated the fixed bug * fix: remove outdated comment Co-authored-by: Sergey Tihon <[email protected]>
- Loading branch information
1 parent
4fe7a5b
commit 736b7a1
Showing
15 changed files
with
412 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
namespace FsUnitTyped | ||
|
||
open System.Diagnostics | ||
open Xunit | ||
open FsUnit.Xunit | ||
|
||
[<AutoOpen>] | ||
module TopLevelOperators = | ||
|
||
/// Asserts that `expected` is equal to `actual`. | ||
/// The equality instance on `actual` is used, if available. | ||
[<DebuggerStepThrough>] | ||
let shouldEqual<'a> (expected: 'a) (actual: 'a) = | ||
actual |> should equal expected | ||
|
||
/// Asserts that `expected` is not equal to `actual`. | ||
/// The equality instance on `actual` is used, if available. | ||
[<DebuggerStepThrough>] | ||
let shouldNotEqual<'a> (expected: 'a) (actual: 'a) = | ||
actual |> should not' (equal expected) | ||
|
||
[<DebuggerStepThrough>] | ||
let shouldContain<'a when 'a: equality> (expected: 'a) (actual: 'a seq) = | ||
actual |> should contain expected | ||
|
||
[<DebuggerStepThrough>] | ||
let shouldBeEmpty<'a>(actual: 'a seq) = | ||
Assert.Empty actual | ||
|
||
[<DebuggerStepThrough>] | ||
let shouldNotContain<'a when 'a: equality> (expected: 'a) (actual: 'a seq) = | ||
if Seq.exists ((=) expected) actual then | ||
failwith $"Seq %A{actual} should not contain %A{expected}" | ||
|
||
[<DebuggerStepThrough>] | ||
let shouldBeSmallerThan<'a when 'a: comparison> (expected: 'a) (actual: 'a) = | ||
actual |> should be (lessThan expected) | ||
|
||
[<DebuggerStepThrough>] | ||
let shouldBeGreaterThan<'a when 'a: comparison> (expected: 'a) (actual: 'a) = | ||
actual |> should be (greaterThan expected) | ||
|
||
[<DebuggerStepThrough>] | ||
let shouldFail<'exn when 'exn :> exn>(f: unit -> unit) = | ||
f |> should throw typeof<'exn> | ||
|
||
[<DebuggerStepThrough>] | ||
let shouldContainText (expected: string) (actual: string) = | ||
if actual.Contains(expected) |> not then | ||
failwith $"\"{expected}\" is not a substring of \"{actual}\"" | ||
|
||
[<DebuggerStepThrough>] | ||
let shouldNotContainText (expected: string) (actual: string) = | ||
if actual.Contains(expected) then | ||
failwith $"\"{expected}\" is a substring of \"{actual}\"" | ||
|
||
[<DebuggerStepThrough>] | ||
let shouldHaveLength<'a> (expected: int) (actual: 'a seq) = | ||
let actual = Seq.length actual | ||
|
||
if actual <> expected then | ||
failwith $"Invalid length in %A{actual}\r\nExpected: {expected}\r\nActual: {actual}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace FsUnit.Typed.Test | ||
|
||
open Xunit | ||
open FsUnitTyped | ||
|
||
type ``shouldBeEmpty tests``() = | ||
[<Fact>] | ||
member __.``empty List should be Empty``() = | ||
[] |> shouldBeEmpty | ||
|
||
[<Fact>] | ||
member __.``non-empty List should fail to be Empty``() = | ||
shouldFail(fun () -> [ 1 ] |> shouldBeEmpty) | ||
|
||
[<Fact>] | ||
member __.``empty Array should be Empty``() = | ||
[||] |> shouldBeEmpty | ||
|
||
[<Fact>] | ||
member __.``non-empty Array should fail to be Empty``() = | ||
shouldFail(fun () -> [| 1 |] |> shouldBeEmpty) | ||
|
||
[<Fact>] | ||
member __.``empty Seq should be Empty``() = | ||
Seq.empty |> shouldBeEmpty | ||
|
||
[<Fact>] | ||
member __.``non-empty Seq should fail to be Empty``() = | ||
shouldFail(fun () -> seq { 1 } |> shouldBeEmpty) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace FsUnit.Typed.Test | ||
|
||
open Xunit | ||
open FsUnitTyped | ||
|
||
type ``haveLength tests``() = | ||
// F# List | ||
[<Fact>] | ||
member __.``List with 1 item should have Length 1``() = | ||
[ 1 ] |> shouldHaveLength 1 | ||
|
||
[<Fact>] | ||
member __.``empty List should fail to have Length 1``() = | ||
shouldFail(fun () -> [] |> shouldHaveLength 1) | ||
|
||
// Array | ||
[<Fact>] | ||
member __.``Array with 1 item should have Length 1``() = | ||
[| 1 |] |> shouldHaveLength 1 | ||
|
||
[<Fact>] | ||
member __.``empty Array should fail to have Length 1``() = | ||
shouldFail(fun () -> [||] |> shouldHaveLength 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace FsUnit.Typed.Test | ||
|
||
open Xunit | ||
open FsUnitTyped | ||
|
||
type ``shouldBeGreaterThan tests``() = | ||
[<Fact>] | ||
member __.``11 should be greater than 10``() = | ||
11 |> shouldBeGreaterThan 10 | ||
|
||
[<Fact>] | ||
member __.``11[dot]1 should be greater than 11[dot]0``() = | ||
11.1 |> shouldBeGreaterThan 11.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace FsUnit.Typed.Test | ||
|
||
open FsUnit.Xunit | ||
open Xunit | ||
open FsUnitTyped | ||
|
||
type ``shouldBeSmallerThan tests``() = | ||
[<Fact>] | ||
member __.``10 should be less than 11``() = | ||
10 |> shouldBeSmallerThan 11 | ||
|
||
[<Fact>] | ||
member __.``10 should not be less than 10``() = | ||
(fun () -> 10 |> shouldBeSmallerThan 10) |> shouldFail<MatchException> | ||
|
||
[<Fact>] | ||
member __.``10[dot]0 should be less than 10[dot]1``() = | ||
10.0 |> shouldBeSmallerThan 10.1 | ||
|
||
[<Fact>] | ||
member __.``10[dot]0 should not be less than 10[dot]0``() = | ||
(fun () -> 10.0 |> shouldBeSmallerThan 10.0) | ||
|> should throw typeof<MatchException> | ||
//|> shouldFail<MatchException> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
namespace FsUnit.Typed.Test | ||
|
||
open Xunit | ||
open FsUnitTyped | ||
|
||
type ``shouldContain tests``() = | ||
[<Fact>] | ||
member __.``List with item should contain item``() = | ||
[ 1 ] |> shouldContain 1 | ||
|
||
[<Fact>] | ||
member __.``empty List should fail to contain item``() = | ||
shouldFail(fun () -> [] |> shouldContain 1) | ||
|
||
[<Fact>] | ||
member __.``empty List should not contain item``() = | ||
[] |> shouldNotContain 1 | ||
|
||
[<Fact>] | ||
member __.``List with item should fail to not contain item``() = | ||
shouldFail(fun () -> [ 1 ] |> shouldNotContain 1) | ||
|
||
[<Fact>] | ||
member __.``Array with item should contain item``() = | ||
[| 1 |] |> shouldContain 1 | ||
|
||
[<Fact>] | ||
member __.``empty Array should fail to contain item``() = | ||
shouldFail(fun () -> [||] |> shouldContain 1) | ||
|
||
[<Fact>] | ||
member __.``empty Array should not contain item``() = | ||
[||] |> shouldNotContain 1 | ||
|
||
[<Fact>] | ||
member __.``Array with item should fail to not contain item``() = | ||
shouldFail(fun () -> [| 1 |] |> shouldNotContain 1) | ||
|
||
[<Fact>] | ||
member __.``Seq with item should contain item``() = | ||
seq { 1 } |> shouldContain 1 | ||
|
||
[<Fact>] | ||
member __.``empty Seq should fail to contain item``() = | ||
shouldFail(fun () -> Seq.empty |> shouldContain 1) | ||
|
||
[<Fact>] | ||
member __.``empty Seq should not contain item``() = | ||
Seq.empty |> shouldNotContain 1 | ||
|
||
[<Fact>] | ||
member __.``Seq with item should fail to not contain item``() = | ||
shouldFail(fun () -> seq { 1 } |> shouldNotContain 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace FsUnit.Typed.Test | ||
|
||
open Xunit | ||
open FsUnitTyped | ||
|
||
type ``shouldContainText tests``() = | ||
[<Fact>] | ||
member __.``empty string should contain ""``() = | ||
"" |> shouldContainText "" | ||
|
||
[<Fact>] | ||
member __.``ships should contain hip``() = | ||
"ships" |> shouldContainText "hip" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace FsUnit.Typed.Test | ||
|
||
open Xunit | ||
open FsUnitTyped | ||
|
||
type ``Typed: shouldEqual null tests``() = | ||
[<Fact>] | ||
member __.``null should be null``() = | ||
null |> shouldEqual null | ||
|
||
[<Fact>] | ||
member __.``null should fail to not be null``() = | ||
shouldFail(fun () -> null |> shouldNotEqual null) |
Oops, something went wrong.