Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up FsUnit #17781

Merged
merged 24 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ let noa<'n when 'n :> Node> (n: 'n option) =
| Some n -> [| n :> Node |]
"""
|> printSignatures
|> should
equal
|> assertEqualIgnoreLineEnding
"""
module Foo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -38,8 +37,7 @@ type Foo() =
member f.Y with public get () = 'y' and internal set y = ignore<char> y
"""
|> printSignatures
|> should
equal
|> assertEqualIgnoreLineEnding
"""
module Foo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ type Map<'t,'v> =
"""
|> printSignatures
|> prependNewline
|> should
equal
|> assertEqualIgnoreLineEnding
"""
namespace Foo.Types

Expand All @@ -43,8 +42,7 @@ type Foo =
"""
|> printSignatures
|> prependNewline
|> should
equal
|> assertEqualIgnoreLineEnding
"""
namespace Hey.There

Expand Down Expand Up @@ -101,8 +99,7 @@ module internal CodePrinter =
id"""
|> printSignatures
|> prependNewline
|> should
equal
|> assertEqualIgnoreLineEnding
"""
namespace Fantomas.Core

Expand Down Expand Up @@ -156,7 +153,7 @@ open System.Runtime.CompilerServices
do ()
"""
|> printSignatures
|> should equal "namespace System"
|> assertEqualIgnoreLineEnding "namespace System"

[<Fact>]
let ``Empty module`` () =
Expand All @@ -167,7 +164,7 @@ module Foobar
do ()
"""
|> printSignatures
|> should equal "module Foobar"
|> assertEqualIgnoreLineEnding "module Foobar"

[<Fact>]
let ``Two empty namespaces`` () =
Expand All @@ -183,7 +180,7 @@ do ()
"""
|> printSignatures
|> prependNewline
|> should equal """
|> assertEqualIgnoreLineEnding """
namespace Foo
namespace Bar"""

Expand All @@ -196,7 +193,7 @@ namespace rec Foobar
do ()
"""
|> printSignatures
|> should equal "namespace Foobar"
|> assertEqualIgnoreLineEnding "namespace Foobar"

[<Fact>]
let ``Attribute on nested module`` () =
Expand All @@ -211,7 +208,7 @@ module Area =
"""
|> printSignatures
|> prependNewline
|> should equal """
|> assertEqualIgnoreLineEnding """
namespace MyApp.Types

[<RequireQualifiedAccess; CompilationRepresentation (enum<CompilationRepresentationFlags> (4))>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let f (g: Upper<int>.Lower<string>) = g.Meh()
"""
|> withReferences [ CSLib ]
|> printSignatures
|> should equal
|> assertEqualIgnoreLineEnding
"""
module Sample

Expand Down Expand Up @@ -74,7 +74,7 @@ let f (g: Root<TimeSpan,TimeSpan,TimeSpan,TimeSpan,TimeSpan>.Foo<int, float, str
"""
|> withReferences [ CSLib ]
|> printSignatures
|> should equal
|> assertEqualIgnoreLineEnding
"""
module Sample

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ type PullActions =
}
"""
|> printSignaturesWith 80
|> should
equal
|> assertEqualIgnoreLineEnding
"""
module SignatureFileGeneration.MyModule

Expand Down Expand Up @@ -63,7 +62,7 @@ type SomeTypeName =
"""
|> printSignatures
|> prependNewline
|> should equal
|> assertEqualIgnoreLineEnding
"""
namespace MyApp.Types

Expand Down
13 changes: 4 additions & 9 deletions tests/FSharp.Compiler.ComponentTests/Signatures/TestHelpers.fs
Original file line number Diff line number Diff line change
@@ -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)
T-Gro marked this conversation as resolved.
Show resolved Hide resolved

let assertSingleSignatureBinding implementation signature =
FSharp $"module A\n\n{implementation}"
|> printSignatures
|> should equal $"\nmodule A\n\n{signature}"
|> assertEqualIgnoreLineEnding $"\nmodule A\n\n{signature}"
14 changes: 7 additions & 7 deletions tests/FSharp.Compiler.ComponentTests/Signatures/TypeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ and FormatSelectionRange =
"""
|> printSignatures
|> prependNewline
|> should equal
|> assertEqualIgnoreLineEnding
"""
namespace Foo.Types

Expand Down Expand Up @@ -87,7 +87,7 @@ type List<'E> with
member this.X = this.Head
"""
|> printSignatures
|> should equal
|> assertEqualIgnoreLineEnding
"""
module Extensions
type List<'E> with
Expand All @@ -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
Expand All @@ -126,7 +126,7 @@ type ConcurrentDictionary<'key, 'value> with
| _ -> None
"""
|> printSignatures
|> should equal
|> assertEqualIgnoreLineEnding
"""
module Extensions
type System.Collections.Concurrent.ConcurrentDictionary<'key,'value> with
Expand Down Expand Up @@ -161,7 +161,7 @@ type DataItem< ^input> with
DataItem.Create< ^input>(stringValue, friendlyStringValue, item)
"""
|> printSignatures
|> should equal
|> assertEqualIgnoreLineEnding
"""
module Extensions

Expand Down Expand Up @@ -237,7 +237,7 @@ type Foo =
member x.Bar with get () = 5 and set v = ignore<int> v
"""
|> printSignatures
|> should equal
|> assertEqualIgnoreLineEnding
"""
module Lib

Expand All @@ -254,7 +254,7 @@ type Foo =
member x.Bar with get (a:int) = 5 and set (a:int) v = ignore<int> v
"""
|> printSignatures
|> should equal
|> assertEqualIgnoreLineEnding
"""
module Lib

Expand Down
22 changes: 11 additions & 11 deletions tests/FSharp.Compiler.Service.Tests/ExprTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

()

Expand Down Expand Up @@ -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)

()

Expand Down Expand Up @@ -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

[<Fact>]
Expand Down Expand Up @@ -3134,7 +3134,7 @@ let BigSequenceExpression(outFileOpt,docFileOpt,baseAddressOpt) =
let createOptions() = createProjectOptions dirName [fileSource1] []

#if !NETFRAMEWORK && DEBUG
[<Fact(Skip = "Test is known to fail in DEBUG when not using NetFramework. Use RELEASE configuration or NetFramework to run it.")>]
[<Theory(Skip = "Test is known to fail in DEBUG when not using NetFramework. Use RELEASE configuration or NetFramework to run it.")>]
#else
[<Theory>]
[<InlineData(false)>]
Expand Down Expand Up @@ -3263,7 +3263,7 @@ let ``Test ProjectForWitnesses1`` useTransparentCompiler =
|> Seq.toList
printfn "actual:\n\n%A" actual
actual
|> shouldPairwiseEqual expected
|> shouldEqual expected


[<Theory>]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -3437,7 +3437,7 @@ let ``Test ProjectForWitnesses3`` useTransparentCompiler =
|> Seq.toList
printfn "actual:\n\n%A" actual
actual
|> shouldPairwiseEqual expected
|> shouldEqual expected

[<Theory>]
[<InlineData(false)>]
Expand Down Expand Up @@ -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 =

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

[<Fact>]
let ``Test project2 all uses of all signature symbols`` () =
Expand Down
18 changes: 9 additions & 9 deletions tests/FSharp.Compiler.Service.Tests/Symbols.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

[<Fact>]
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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

[<Fact>]
Expand All @@ -406,7 +406,7 @@ let tester: Folks<int> = 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

[<Fact>]
Expand All @@ -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
)

Expand Down Expand Up @@ -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
| _ -> ()
| _ -> ()

Expand Down
Loading
Loading