diff --git a/tests/FSharp.Compiler.ComponentTests/Signatures/HashConstraintTests.fs b/tests/FSharp.Compiler.ComponentTests/Signatures/HashConstraintTests.fs index beb33a8bac55..ac624ec19a79 100644 --- a/tests/FSharp.Compiler.ComponentTests/Signatures/HashConstraintTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Signatures/HashConstraintTests.fs @@ -21,8 +21,7 @@ let noa<'n when 'n :> Node> (n: 'n option) = | Some n -> [| n :> Node |] """ |> printSignatures - |> should - equal + |> assertEqualIgnoreLineEnding """ module Foo diff --git a/tests/FSharp.Compiler.ComponentTests/Signatures/MemberTests.fs b/tests/FSharp.Compiler.ComponentTests/Signatures/MemberTests.fs index 2452a9008819..3475535249a8 100644 --- a/tests/FSharp.Compiler.ComponentTests/Signatures/MemberTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Signatures/MemberTests.fs @@ -15,8 +15,7 @@ type Foo() = member f.X with internal get (key1, key2) = true and public set (key1, key2) value = () """ |> printSignatures - |> should - equal + |> assertEqualIgnoreLineEnding """ module Foo @@ -38,8 +37,7 @@ type Foo() = member f.Y with public get () = 'y' and internal set y = ignore y """ |> printSignatures - |> should - equal + |> assertEqualIgnoreLineEnding """ module Foo diff --git a/tests/FSharp.Compiler.ComponentTests/Signatures/ModuleOrNamespaceTests.fs b/tests/FSharp.Compiler.ComponentTests/Signatures/ModuleOrNamespaceTests.fs index d4d9d408df97..413e4a7fdf9a 100644 --- a/tests/FSharp.Compiler.ComponentTests/Signatures/ModuleOrNamespaceTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Signatures/ModuleOrNamespaceTests.fs @@ -20,8 +20,7 @@ type Map<'t,'v> = """ |> printSignatures |> prependNewline - |> should - equal + |> assertEqualIgnoreLineEnding """ namespace Foo.Types @@ -43,8 +42,7 @@ type Foo = """ |> printSignatures |> prependNewline - |> should - equal + |> assertEqualIgnoreLineEnding """ namespace Hey.There @@ -101,8 +99,7 @@ module internal CodePrinter = id""" |> printSignatures |> prependNewline - |> should - equal + |> assertEqualIgnoreLineEnding """ namespace Fantomas.Core @@ -156,7 +153,7 @@ open System.Runtime.CompilerServices do () """ |> printSignatures - |> should equal "namespace System" + |> assertEqualIgnoreLineEnding "namespace System" [] let ``Empty module`` () = @@ -167,7 +164,7 @@ module Foobar do () """ |> printSignatures - |> should equal "module Foobar" + |> assertEqualIgnoreLineEnding "module Foobar" [] let ``Two empty namespaces`` () = @@ -183,7 +180,7 @@ do () """ |> printSignatures |> prependNewline - |> should equal """ + |> assertEqualIgnoreLineEnding """ namespace Foo namespace Bar""" @@ -196,7 +193,7 @@ namespace rec Foobar do () """ |> printSignatures - |> should equal "namespace Foobar" + |> assertEqualIgnoreLineEnding "namespace Foobar" [] let ``Attribute on nested module`` () = @@ -211,7 +208,7 @@ module Area = """ |> printSignatures |> prependNewline - |> should equal """ + |> assertEqualIgnoreLineEnding """ namespace MyApp.Types [ (4))>] diff --git a/tests/FSharp.Compiler.ComponentTests/Signatures/NestedTypeTests.fs b/tests/FSharp.Compiler.ComponentTests/Signatures/NestedTypeTests.fs index 669faca6d5fa..4dfce060679b 100644 --- a/tests/FSharp.Compiler.ComponentTests/Signatures/NestedTypeTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Signatures/NestedTypeTests.fs @@ -35,7 +35,7 @@ let f (g: Upper.Lower) = g.Meh() """ |> withReferences [ CSLib ] |> printSignatures - |> should equal + |> assertEqualIgnoreLineEnding """ module Sample @@ -74,7 +74,7 @@ let f (g: Root.Foo withReferences [ CSLib ] |> printSignatures - |> should equal + |> assertEqualIgnoreLineEnding """ module Sample diff --git a/tests/FSharp.Compiler.ComponentTests/Signatures/RecordTests.fs b/tests/FSharp.Compiler.ComponentTests/Signatures/RecordTests.fs index 27c5159a3f30..cb5ec18da97c 100644 --- a/tests/FSharp.Compiler.ComponentTests/Signatures/RecordTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Signatures/RecordTests.fs @@ -19,8 +19,7 @@ type PullActions = } """ |> printSignaturesWith 80 - |> should - equal + |> assertEqualIgnoreLineEnding """ module SignatureFileGeneration.MyModule @@ -63,7 +62,7 @@ type SomeTypeName = """ |> printSignatures |> prependNewline - |> should equal + |> assertEqualIgnoreLineEnding """ namespace MyApp.Types diff --git a/tests/FSharp.Compiler.ComponentTests/Signatures/TestHelpers.fs b/tests/FSharp.Compiler.ComponentTests/Signatures/TestHelpers.fs index 8f3d1019ae03..b778cb3d783e 100644 --- a/tests/FSharp.Compiler.ComponentTests/Signatures/TestHelpers.fs +++ b/tests/FSharp.Compiler.ComponentTests/Signatures/TestHelpers.fs @@ -1,20 +1,15 @@ module Signatures.TestHelpers open System -open FsUnit +open Xunit open FSharp.Test.Compiler let prependNewline v = String.Concat("\n", v) -let equal x = - let x = - match box x with - | :? String as s -> s.Replace("\r\n", "\n") |> box - | x -> x - - equal x +let assertEqualIgnoreLineEnding (x: string) (y: string) = + Assert.Equal(x, y, ignoreLineEndingDifferences = true) let assertSingleSignatureBinding implementation signature = FSharp $"module A\n\n{implementation}" |> printSignatures - |> should equal $"\nmodule A\n\n{signature}" + |> assertEqualIgnoreLineEnding $"\nmodule A\n\n{signature}" diff --git a/tests/FSharp.Compiler.ComponentTests/Signatures/TypeTests.fs b/tests/FSharp.Compiler.ComponentTests/Signatures/TypeTests.fs index 1494c465af93..d066d74dd9a9 100644 --- a/tests/FSharp.Compiler.ComponentTests/Signatures/TypeTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Signatures/TypeTests.fs @@ -44,7 +44,7 @@ and FormatSelectionRange = """ |> printSignatures |> prependNewline - |> should equal + |> assertEqualIgnoreLineEnding """ namespace Foo.Types @@ -87,7 +87,7 @@ type List<'E> with member this.X = this.Head """ |> printSignatures - |> should equal + |> assertEqualIgnoreLineEnding """ module Extensions type List<'E> with @@ -104,7 +104,7 @@ type Map<'K, 'V when 'K: comparison> with member m.X (t: 'T) (k: 'K) = Some k, ({| n = [|k|] |}, 0) """ |> printSignatures - |> should equal + |> assertEqualIgnoreLineEnding """ module Extensions type Map<'K,'V when 'K: comparison> with @@ -126,7 +126,7 @@ type ConcurrentDictionary<'key, 'value> with | _ -> None """ |> printSignatures - |> should equal + |> assertEqualIgnoreLineEnding """ module Extensions type System.Collections.Concurrent.ConcurrentDictionary<'key,'value> with @@ -161,7 +161,7 @@ type DataItem< ^input> with DataItem.Create< ^input>(stringValue, friendlyStringValue, item) """ |> printSignatures - |> should equal + |> assertEqualIgnoreLineEnding """ module Extensions @@ -237,7 +237,7 @@ type Foo = member x.Bar with get () = 5 and set v = ignore v """ |> printSignatures - |> should equal + |> assertEqualIgnoreLineEnding """ module Lib @@ -254,7 +254,7 @@ type Foo = member x.Bar with get (a:int) = 5 and set (a:int) v = ignore v """ |> printSignatures - |> should equal + |> assertEqualIgnoreLineEnding """ module Lib diff --git a/tests/FSharp.Compiler.Service.Tests/ExprTests.fs b/tests/FSharp.Compiler.Service.Tests/ExprTests.fs index 3a7cf3eb68d4..c8870dd700eb 100644 --- a/tests/FSharp.Compiler.Service.Tests/ExprTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/ExprTests.fs @@ -788,12 +788,12 @@ let ``Test Unoptimized Declarations Project1`` useTransparentCompiler = printDeclarations None (List.ofSeq file1.Declarations) |> Seq.toList |> Utils.filterHack - |> shouldPairwiseEqual (Utils.filterHack expected) + |> shouldEqual (Utils.filterHack expected) printDeclarations None (List.ofSeq file2.Declarations) |> Seq.toList |> Utils.filterHack - |> shouldPairwiseEqual (Utils.filterHack expected2) + |> shouldEqual (Utils.filterHack expected2) () @@ -930,12 +930,12 @@ let ``Test Optimized Declarations Project1`` useTransparentCompiler = printDeclarations None (List.ofSeq file1.Declarations) |> Seq.toList |> Utils.filterHack - |> shouldPairwiseEqual (Utils.filterHack expected) + |> shouldEqual (Utils.filterHack expected) printDeclarations None (List.ofSeq file2.Declarations) |> Seq.toList |> Utils.filterHack - |> shouldPairwiseEqual (Utils.filterHack expected2) + |> shouldEqual (Utils.filterHack expected2) () @@ -1045,11 +1045,11 @@ let testOperators dnName fsName excludedTests expectedUnoptimized expectedOptimi // fail test on first line that fails, show difference in output window resultUnoptFiltered - |> shouldPairwiseEqual expectedUnoptFiltered + |> shouldEqual expectedUnoptFiltered // fail test on first line that fails, show difference in output window resultOptFiltered - |> shouldPairwiseEqual expectedOptFiltered + |> shouldEqual expectedOptFiltered end [] @@ -3134,7 +3134,7 @@ let BigSequenceExpression(outFileOpt,docFileOpt,baseAddressOpt) = let createOptions() = createProjectOptions dirName [fileSource1] [] #if !NETFRAMEWORK && DEBUG -[] +[] #else [] [] @@ -3263,7 +3263,7 @@ let ``Test ProjectForWitnesses1`` useTransparentCompiler = |> Seq.toList printfn "actual:\n\n%A" actual actual - |> shouldPairwiseEqual expected + |> shouldEqual expected [] @@ -3380,7 +3380,7 @@ let ``Test ProjectForWitnesses2`` useTransparentCompiler = |> Seq.toList printfn "actual:\n\n%A" actual actual - |> shouldPairwiseEqual expected + |> shouldEqual expected //--------------------------------------------------------------------------------------------------------- // This project is for witness arguments, testing for https://github.com/dotnet/fsharp/issues/10364 @@ -3437,7 +3437,7 @@ let ``Test ProjectForWitnesses3`` useTransparentCompiler = |> Seq.toList printfn "actual:\n\n%A" actual actual - |> shouldPairwiseEqual expected + |> shouldEqual expected [] [] @@ -3532,7 +3532,7 @@ let ``Test ProjectForWitnesses4 GetWitnessPassingInfo`` useTransparentCompiler = |> Seq.toList printfn "actual:\n\n%A" actual actual - |> shouldPairwiseEqual expected + |> shouldEqual expected module internal ProjectForNoWarnHashDirective = diff --git a/tests/FSharp.Compiler.Service.Tests/ProjectAnalysisTests.fs b/tests/FSharp.Compiler.Service.Tests/ProjectAnalysisTests.fs index 92ca4a070917..78d03ac8a9b4 100644 --- a/tests/FSharp.Compiler.Service.Tests/ProjectAnalysisTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/ProjectAnalysisTests.fs @@ -713,7 +713,7 @@ let ``Test project2 all symbols in signature`` () = "field x"; "field y"; "GenericClass`1"; "generic parameter T"; "member .ctor"; "member GenericMethod"; "generic parameter U"] |> List.sort - shouldPairwiseEqual e r + shouldEqual e r [] let ``Test project2 all uses of all signature symbols`` () = diff --git a/tests/FSharp.Compiler.Service.Tests/Symbols.fs b/tests/FSharp.Compiler.Service.Tests/Symbols.fs index c63dca9f6de4..e0082fcde303 100644 --- a/tests/FSharp.Compiler.Service.Tests/Symbols.fs +++ b/tests/FSharp.Compiler.Service.Tests/Symbols.fs @@ -68,7 +68,7 @@ extern int private c() |> List.zip decls |> List.iter (fun (actual, expected) -> match actual with - | SynModuleDecl.Let (_, [SynBinding (accessibility = access)], _) -> Option.map string access |> should equal expected + | SynModuleDecl.Let (_, [SynBinding (accessibility = access)], _) -> Option.map string access |> shouldEqual expected | decl -> failwithf "unexpected decl: %O" decl) [ "a", (true, false, false, false) @@ -79,7 +79,7 @@ extern int private c() | :? FSharpMemberOrFunctionOrValue as mfv -> let access = mfv.Accessibility (access.IsPublic, access.IsProtected, access.IsInternal, access.IsPrivate) - |> should equal expected + |> shouldEqual expected | _ -> failwithf "Couldn't get mfv: %s" name) [] @@ -289,7 +289,7 @@ type E = Ns1.Ns2.T match symbolUse.Symbol with | :? FSharpEntity as entity -> entity.AbbreviatedType.Format(symbolUse.DisplayContext) - |> should equal expectedPrintedType + |> shouldEqual expectedPrintedType | _ -> failwithf "Couldn't get entity: %s" symbolName) @@ -388,7 +388,7 @@ let tester: int folks = Cons(1, Nil) match symbolUse.Symbol with | :? FSharpMemberOrFunctionOrValue as v -> v.FullType.Format (symbolUse.DisplayContext.WithPrefixGenericParameters()) - |> should equal prefixForm + |> shouldEqual prefixForm | _ -> failwithf "Couldn't get member: %s" entity [] @@ -406,7 +406,7 @@ let tester: Folks = Cons(1, Nil) match symbolUse.Symbol with | :? FSharpMemberOrFunctionOrValue as v -> v.FullType.Format (symbolUse.DisplayContext.WithSuffixGenericParameters()) - |> should equal suffixForm + |> shouldEqual suffixForm | _ -> failwithf "Couldn't get member: %s" entity [] @@ -431,7 +431,7 @@ let tester2: int Group = [] match symbolUse.Symbol with | :? FSharpMemberOrFunctionOrValue as v -> v.FullType.Format symbolUse.DisplayContext - |> should equal expectedTypeFormat + |> shouldEqual expectedTypeFormat | _ -> failwithf "Couldn't get member: %s" entityName ) @@ -497,10 +497,10 @@ let f2 b1 b2 b3 b4 b5 = | :? FSharpMemberOrFunctionOrValue as mfv -> match symbolTypes.TryGetValue(mfv.DisplayName) with | true, Some expectedType -> - mfv.FullType.TypeDefinition.DisplayName |> should equal expectedType + mfv.FullType.TypeDefinition.DisplayName |> shouldEqual expectedType | true, None -> - mfv.FullType.IsGenericParameter |> should equal true - mfv.FullType.AllInterfaces.Count |> should equal 0 + mfv.FullType.IsGenericParameter |> shouldEqual true + mfv.FullType.AllInterfaces.Count |> shouldEqual 0 | _ -> () | _ -> () diff --git a/tests/service/FsUnit.fs b/tests/service/FsUnit.fs index 729ecbc91448..e17be4117767 100644 --- a/tests/service/FsUnit.fs +++ b/tests/service/FsUnit.fs @@ -1,38 +1,6 @@ module FsUnit -open System.Diagnostics open Xunit -[] -let should (f: 'a -> objnull -> unit) x (y: obj) = - let y = - match y with - | :? (unit -> unit) -> box (fun () -> (y :?> unit -> unit)) - | _ -> y - f x y - -/// Note, xunit does check types by default. -/// These are artifacts of nunit and not necessary now, just used in many places. -let equal (expected: 'a) (actual: 'a) = - Assert.Equal<'a>(expected, actual) - let shouldEqual (x: 'a) (y: 'a) = - Assert.Equal<'a>(x, y) - -/// Same as 'shouldEqual' but goes pairwise over the collections. Lengths must be equal. -let shouldPairwiseEqual (x: seq<_>) (y: seq<_>) = - // using enumerators, because Seq.iter2 allows different lengths silently - let ex = x.GetEnumerator() - let ey = y.GetEnumerator() - let mutable countx = 0 - let mutable county = 0 - while ex.MoveNext() do - countx <- countx + 1 - if ey.MoveNext() then - county <- county + 1 - ey.Current |> shouldEqual ex.Current - - while ex.MoveNext() do countx <- countx + 1 - while ey.MoveNext() do county <- county + 1 - if countx <> county then - Assert.Fail($"Collections are of unequal lengths, expected length {countx}, actual length is {county}.") + Assert.Equal<'a>(x, y) \ No newline at end of file