diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 77569208..c602e244 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -9,7 +9,7 @@ ] }, "fake-cli": { - "version": "5.23.0", + "version": "5.23.1", "commands": [ "fake" ] @@ -21,7 +21,7 @@ ] }, "fantomas": { - "version": "5.0.0", + "version": "5.0.6", "commands": [ "fantomas" ] diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9a4079a3..be5bb7c1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,10 +19,10 @@ jobs: runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v3 - name: Setup .NET Core - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v3 with: dotnet-version: ${{ matrix.dotnet }} diff --git a/docs/MsTest.fsx b/docs/MsTest.fsx index 924ff75f..2354797e 100644 --- a/docs/MsTest.fsx +++ b/docs/MsTest.fsx @@ -2,7 +2,7 @@ // 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. #r "../packages/MSTest.TestFramework/lib/netstandard1.0/Microsoft.VisualStudio.TestPlatform.TestFramework.dll" -#r "../packages/NHamcrest/lib/netstandard1.5/NHamcrest.dll" +#r "../packages/NHamcrest/lib/netstandard2.0/NHamcrest.dll" #r "../bin/FsUnit.MsTest/netstandard2.0/FsUnit.MsTest.dll" (** diff --git a/docs/index.fsx b/docs/index.fsx index bc94ced7..d1523e53 100644 --- a/docs/index.fsx +++ b/docs/index.fsx @@ -46,6 +46,12 @@ One object equals or does not equal another: 1 |> should equal 1 1 |> should not' (equal 2) +(** +One sequence equals or does not equal another: +*) +seq { 1; 2; 3 } |> should equalSeq (seq { 1; 2; 3 }) +seq { 1 } |> should not' (equalSeq (seq { 1; 2})) + (** One collection is equivalent or is not equivalent to another (order doesn't matter): *) diff --git a/docs/operators.md b/docs/operators.md index 9baaf23d..27ee0652 100644 --- a/docs/operators.md +++ b/docs/operators.md @@ -13,6 +13,7 @@ Operators comparison across frameworks | `unique` | ✔ | ✔ | ✔ | | `should` | ✔ | ✔ | ✔ | | `equal` | ✔ | ✔ | ✔ | +| `equalSeq` | ✔ | ✔ | ✔ | | `equivalent` | ✔ | ❌ | ✔ | | `equalWithin` | ✔ | ✔ | ✔ | | `contain` | ✔ | ✔ | ✔ | diff --git a/docs/xUnit.fsx b/docs/xUnit.fsx index 187ec3e4..783309fd 100644 --- a/docs/xUnit.fsx +++ b/docs/xUnit.fsx @@ -2,7 +2,7 @@ // 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. #r "../packages/xunit.extensibility.core/lib/netstandard1.1/xunit.core.dll" -#r "../packages/NHamcrest/lib/netstandard1.5/NHamcrest.dll" +#r "../packages/NHamcrest/lib/netstandard2.0/NHamcrest.dll" #r "../bin/FsUnit.Xunit/netstandard2.0/FsUnit.Xunit.dll" (** diff --git a/paket.lock b/paket.lock index d3b5a97a..bc594482 100644 --- a/paket.lock +++ b/paket.lock @@ -2,17 +2,17 @@ RESTRICTION: || (== net6.0) (== netstandard2.0) NUGET remote: https://api.nuget.org/v3/index.json FSharp.Core (5.0.2) - Microsoft.CodeCoverage (17.3.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= net45)) (&& (== netstandard2.0) (>= netcoreapp1.0)) - Microsoft.NET.Test.Sdk (17.3.1) - Microsoft.CodeCoverage (>= 17.3.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= net45)) (&& (== netstandard2.0) (>= netcoreapp1.0)) - Microsoft.TestPlatform.TestHost (>= 17.3.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) - Microsoft.NETCore.Platforms (6.0.5) + Microsoft.CodeCoverage (17.3.2) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= net45)) (&& (== netstandard2.0) (>= netcoreapp1.0)) + Microsoft.NET.Test.Sdk (17.3.2) + Microsoft.CodeCoverage (>= 17.3.2) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= net45)) (&& (== netstandard2.0) (>= netcoreapp1.0)) + Microsoft.TestPlatform.TestHost (>= 17.3.2) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) + Microsoft.NETCore.Platforms (6.0.6) Microsoft.NETCore.Targets (5.0) - Microsoft.TestPlatform.ObjectModel (17.3.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) + Microsoft.TestPlatform.ObjectModel (17.3.2) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) NuGet.Frameworks (>= 5.11) System.Reflection.Metadata (>= 1.6) - Microsoft.TestPlatform.TestHost (17.3.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) - Microsoft.TestPlatform.ObjectModel (>= 17.3.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) (&& (== netstandard2.0) (>= uap10.0)) + Microsoft.TestPlatform.TestHost (17.3.2) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) + Microsoft.TestPlatform.ObjectModel (>= 17.3.2) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) (&& (== netstandard2.0) (>= uap10.0)) Newtonsoft.Json (>= 9.0.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) (&& (== netstandard2.0) (>= uap10.0)) MSTest.TestAdapter (2.1.2) NETStandard.Library (>= 1.6.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) @@ -24,7 +24,7 @@ NUGET Microsoft.NETCore.Platforms (>= 1.1) Newtonsoft.Json (13.0.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) NHamcrest (3.0.1) - NuGet.Frameworks (6.3) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) (&& (== netstandard2.0) (>= netcoreapp2.1)) + NuGet.Frameworks (6.3.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) (&& (== netstandard2.0) (>= netcoreapp2.1)) NUnit (3.13.3) NETStandard.Library (>= 2.0) NUnit3TestAdapter (4.2.1) diff --git a/src/FsUnit.MsTestUnit/FsUnit.MsTest.fsproj b/src/FsUnit.MsTestUnit/FsUnit.MsTest.fsproj index 0d0df3cd..aad23efb 100644 --- a/src/FsUnit.MsTestUnit/FsUnit.MsTest.fsproj +++ b/src/FsUnit.MsTestUnit/FsUnit.MsTest.fsproj @@ -1,4 +1,4 @@ - + net6.0;netstandard2.0 FsUnit.MsTest diff --git a/src/FsUnit.MsTestUnit/FsUnit.fs b/src/FsUnit.MsTestUnit/FsUnit.fs index ddf441cb..1197ac5e 100644 --- a/src/FsUnit.MsTestUnit/FsUnit.fs +++ b/src/FsUnit.MsTestUnit/FsUnit.fs @@ -55,6 +55,9 @@ let inline shouldFail(f: unit -> unit) = let equal expected = CustomMatchers.equal expected +let equalSeq expected = + CustomMatchers.equalSeq (fun (e: seq<'a>) (a: seq<'a>) -> Assert.IsTrue(Linq.Enumerable.SequenceEqual(e, a))) expected + let equivalent expected = CustomMatchers.equivalent (fun e a -> CollectionAssert.AreEquivalent(e, a)) expected diff --git a/src/FsUnit.NUnit/FsUnit.fs b/src/FsUnit.NUnit/FsUnit.fs index 6acb0576..e3f65dff 100644 --- a/src/FsUnit.NUnit/FsUnit.fs +++ b/src/FsUnit.NUnit/FsUnit.fs @@ -46,6 +46,9 @@ module TopLevelOperators = let equal expected = Equality.IsEqualTo(expected) + let equalSeq(expected: seq<'a>) = + EqualConstraint(expected) + let equivalent expected = CollectionEquivalentConstraint(expected) diff --git a/src/FsUnit.Xunit/CustomMatchers.fs b/src/FsUnit.Xunit/CustomMatchers.fs index f234ee1b..bf7fb4e7 100644 --- a/src/FsUnit.Xunit/CustomMatchers.fs +++ b/src/FsUnit.Xunit/CustomMatchers.fs @@ -10,6 +10,16 @@ open System.Reflection let equal expected = CustomMatcher($"Equals %A{expected}", (fun actual -> expected = actual)) +let equalSeq (func: seq<'a> -> seq<'a> -> unit) (expected: seq<'a>) = + let matches(actual: obj) = + try + func expected (unbox(actual)) + true + with _ -> + false + + CustomMatcher($"Equals %A{expected}", Func<_, _> matches) + let equivalent f expected = let matches(actual: obj) = try diff --git a/src/FsUnit.Xunit/FsUnit.Xunit.fsproj b/src/FsUnit.Xunit/FsUnit.Xunit.fsproj index ab555882..ba6afd45 100644 --- a/src/FsUnit.Xunit/FsUnit.Xunit.fsproj +++ b/src/FsUnit.Xunit/FsUnit.Xunit.fsproj @@ -1,4 +1,4 @@ - + net6.0;netstandard2.0 FsUnit.Xunit diff --git a/src/FsUnit.Xunit/FsUnit.fs b/src/FsUnit.Xunit/FsUnit.fs index 792b44cc..4abba41a 100644 --- a/src/FsUnit.Xunit/FsUnit.fs +++ b/src/FsUnit.Xunit/FsUnit.fs @@ -53,6 +53,8 @@ let inline shouldFail(f: unit -> unit) = if not failed then raise(MatchException("Method should fail", "No exception raised", null)) +let equalSeq expected = + CustomMatchers.equalSeq (fun (e: seq<'a>) (a: seq<'a>) -> Assert.Equal>(e, a)) expected let equal expected = CustomMatchers.equal expected diff --git a/tests/FsUnit.MsTest.Test/FsUnit.MsTest.Test.fsproj b/tests/FsUnit.MsTest.Test/FsUnit.MsTest.Test.fsproj index 85d00995..8e64e038 100644 --- a/tests/FsUnit.MsTest.Test/FsUnit.MsTest.Test.fsproj +++ b/tests/FsUnit.MsTest.Test/FsUnit.MsTest.Test.fsproj @@ -26,6 +26,7 @@ + diff --git a/tests/FsUnit.MsTest.Test/equalSeqTests.fs b/tests/FsUnit.MsTest.Test/equalSeqTests.fs new file mode 100644 index 00000000..a956630c --- /dev/null +++ b/tests/FsUnit.MsTest.Test/equalSeqTests.fs @@ -0,0 +1,27 @@ +namespace FsUnit.Test + +open Microsoft.VisualStudio.TestTools.UnitTesting +open FsUnit.MsTest + +[] +type ``equalSeq Tests``() = + + [] + member _.``sequence should equal sequence``() = + Seq.init 3 ((+) 1) |> should equalSeq (Seq.init 3 ((+) 1)) + + [] + member _.``sequence should not equal sequence``() = + Seq.init 3 ((+) 1) |> should not' (equalSeq(Seq.init 3 ((-) 3))) + + [] + member _.``filled sequence should not equal empty sequence``() = + Seq.init 3 ((+) 1) |> should not' (equalSeq Seq.empty) + + [] + member _.``empty sequence should equal empty sequence``() = + Seq.empty |> should equalSeq Seq.empty + + [] + member _.``sequence should not equal another sequence``() = + Seq.init 4 ((+) 1) |> should not' (equalSeq(Seq.init 5 ((+) 1))) diff --git a/tests/FsUnit.NUnit.Test/FsUnit.NUnit.Test.fsproj b/tests/FsUnit.NUnit.Test/FsUnit.NUnit.Test.fsproj index f2eef68b..e65c52a0 100644 --- a/tests/FsUnit.NUnit.Test/FsUnit.NUnit.Test.fsproj +++ b/tests/FsUnit.NUnit.Test/FsUnit.NUnit.Test.fsproj @@ -20,6 +20,7 @@ + diff --git a/tests/FsUnit.NUnit.Test/equalSeqTests.fs b/tests/FsUnit.NUnit.Test/equalSeqTests.fs new file mode 100644 index 00000000..ef06547f --- /dev/null +++ b/tests/FsUnit.NUnit.Test/equalSeqTests.fs @@ -0,0 +1,27 @@ +namespace FsUnit.Test + +open System +open NUnit.Framework +open FsUnit + +type ``equalSeq Tests``() = + + [] + member _.``sequence should equal sequence``() = + Seq.init 3 ((+) 1) |> should equalSeq (Seq.init 3 ((+) 1)) + + [] + member _.``sequence should not equal sequence``() = + Seq.init 3 ((+) 1) |> should not' (equalSeq(Seq.init 3 ((-) 3))) + + [] + member _.``filled sequence should not equal empty sequence``() = + Seq.init 3 ((+) 1) |> should not' (equalSeq Seq.empty) + + [] + member _.``empty sequence should equal empty sequence``() = + Seq.empty |> should equalSeq Seq.empty + + [] + member _.``sequence should not equal another sequence``() = + Seq.init 4 ((+) 1) |> should not' (equalSeq(Seq.init 5 ((+) 1))) diff --git a/tests/FsUnit.Xunit.Test/FsUnit.Xunit.Test.fsproj b/tests/FsUnit.Xunit.Test/FsUnit.Xunit.Test.fsproj index e4579bb1..56cbbc28 100644 --- a/tests/FsUnit.Xunit.Test/FsUnit.Xunit.Test.fsproj +++ b/tests/FsUnit.Xunit.Test/FsUnit.Xunit.Test.fsproj @@ -6,6 +6,7 @@ + diff --git a/tests/FsUnit.Xunit.Test/equalSeqTests.fs b/tests/FsUnit.Xunit.Test/equalSeqTests.fs new file mode 100644 index 00000000..9b134027 --- /dev/null +++ b/tests/FsUnit.Xunit.Test/equalSeqTests.fs @@ -0,0 +1,26 @@ +namespace FsUnit.Test + +open Xunit +open FsUnit.Xunit + +type ``equalSeq Tests``() = + + [] + member _.``sequence should equal sequence``() = + Seq.init 3 ((+) 1) |> should equalSeq (Seq.init 3 ((+) 1)) + + [] + member _.``sequence should not equal sequence``() = + Seq.init 3 ((+) 1) |> should not' (equalSeq(Seq.init 3 ((-) 3))) + + [] + member _.``filled sequence should not equal empty sequence``() = + Seq.init 3 ((+) 1) |> should not' (equalSeq Seq.empty) + + [] + member _.``empty sequence should equal empty sequence``() = + Seq.empty |> should equalSeq Seq.empty + + [] + member _.``sequence should not equal another sequence``() = + Seq.init 4 ((+) 1) |> should not' (equalSeq(Seq.init 5 ((+) 1)))