Skip to content

Commit

Permalink
Activate suggestions in unit tests and move some tests (dotnet#7251)
Browse files Browse the repository at this point in the history
* Moved Suggestion Tests over to NUnit

* Try to activate suggestions in unit tests

* Fix suggestion tests

* Fix suggestion tests

* Fix suggestion tests

* Fix suggestion tests
  • Loading branch information
forki authored and KevinRansom committed Aug 2, 2019
1 parent 31388f7 commit 7c7a87b
Show file tree
Hide file tree
Showing 29 changed files with 330 additions and 272 deletions.
2 changes: 1 addition & 1 deletion tests/fsharp/Compiler/CompilerAssert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type ILVerifier (dllFilePath: string) =
[<RequireQualifiedAccess>]
module CompilerAssert =

let checker = FSharpChecker.Create()
let checker = FSharpChecker.Create(suggestNamesForErrors=true)

let private config = TestFramework.initializeSuite ()

Expand Down
2 changes: 1 addition & 1 deletion tests/fsharp/Compiler/ErrorMessages/ClassesTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ let x =
}
"""
[|
FSharpErrorSeverity.Error, 767, (8, 14, 8, 34), "The member 'Function' does not correspond to any abstract or virtual method available to override or implement."
FSharpErrorSeverity.Error, 767, (8, 14, 8, 34), "The member 'Function' does not correspond to any abstract or virtual method available to override or implement. Maybe you want one of the following:\r\n MyFunction"
FSharpErrorSeverity.Error, 17, (8, 19, 8, 27), "The member 'Function : 'a * 'b -> unit' does not have the correct type to override any given virtual method"
FSharpErrorSeverity.Error, 366, (7, 3, 9, 4), "No implementation was given for those members: \r\n\t'abstract member IInterface.MyFunction : int32 * int32 -> unit'\r\n\t'abstract member IInterface.SomeOtherFunction : int32 * int32 -> unit'\r\nNote that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'."
FSharpErrorSeverity.Error, 783, (7, 9, 7, 19), "At least one override did not correctly implement its corresponding abstract member"
Expand Down
2 changes: 1 addition & 1 deletion tests/fsharp/Compiler/ErrorMessages/ConstructorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ let p =
Age = 18)
"""
[|
FSharpErrorSeverity.Error, 39, (7, 12, 7, 16), "The value or constructor 'Name' is not defined."
FSharpErrorSeverity.Error, 39, (7, 12, 7, 16), "The value or constructor 'Name' is not defined. Maybe you want one of the following:\r\n nan"
FSharpErrorSeverity.Warning, 20, (7, 12, 7, 25), "The result of this equality expression has type 'bool' and is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'."
FSharpErrorSeverity.Error, 39, (8, 12, 8, 15), "The value or constructor 'Age' is not defined."
FSharpErrorSeverity.Error, 501, (7, 5, 8, 21), "The object constructor 'Person' takes 0 argument(s) but is here given 1. The required signature is 'new : unit -> Person'. If some of the arguments are meant to assign values to properties, consider separating those arguments with a comma (',')."
Expand Down
2 changes: 1 addition & 1 deletion tests/fsharp/Compiler/ErrorMessages/DontSuggestTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let _ = Path.GetFullPath "images"
FSharpErrorSeverity.Error
39
(2, 9, 2, 13)
"The value, namespace, type or module 'Path' is not defined."
"The value, namespace, type or module 'Path' is not defined. Maybe you want one of the following:\r\n Math"

[<Test>]
let ``Dont Suggest When Things Are Open``() =
Expand Down
10 changes: 5 additions & 5 deletions tests/fsharp/Compiler/ErrorMessages/NameResolutionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ open NUnit.Framework
open FSharp.Compiler.SourceCodeServices

[<TestFixture>]
module NameResolutionTests =
module NameResolutionTests =

[<Test>]
let FieldNotInRecord () =
CompilerAssert.TypeCheckSingleError
Expand All @@ -24,7 +24,7 @@ let r:F = { Size=3; Height=4; Wall=1 }
FSharpErrorSeverity.Error
1129
(9, 31, 9, 35)
"The record type 'F' does not contain a label 'Wall'."
"The record type 'F' does not contain a label 'Wall'. Maybe you want one of the following:\r\n Wallis"

[<Test>]
let RecordFieldProposal () =
Expand All @@ -36,10 +36,10 @@ type C = { Wheels:int }
type D = { Size:int; Height:int; Walls:int }
type E = { Unknown:string }
type F = { Wallis:int; Size:int; Height:int; }
let r = { Size=3; Height=4; Wall=1 }
"""
FSharpErrorSeverity.Error
39
(9, 29, 9, 33)
"The record label 'Wall' is not defined."
"The record label 'Wall' is not defined. Maybe you want one of the following:\r\n Walls\r\n Wallis"
320 changes: 320 additions & 0 deletions tests/fsharp/Compiler/ErrorMessages/SuggestionsTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,320 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.UnitTests

open NUnit.Framework
open FSharp.Compiler.SourceCodeServices

[<TestFixture>]
module Suggestions =

[<Test>]
let ``Field Suggestion`` () =
CompilerAssert.TypeCheckSingleError
"""
type Person = { Name : string; }
let x = { Person.Names = "Isaac" }
"""
FSharpErrorSeverity.Error
39
(4, 18, 4, 23)
"The field, constructor or member 'Names' is not defined. Maybe you want one of the following:\r\n Name"


[<Test>]
let ``Suggest Array Module Functions`` () =
CompilerAssert.TypeCheckSingleError
"""
let f =
Array.blt
"""
FSharpErrorSeverity.Error
39
(3, 11, 3, 14)
"The value, constructor, namespace or type 'blt' is not defined. Maybe you want one of the following:\r\n blit"


[<Test>]
let ``Suggest Async Module`` () =
CompilerAssert.TypeCheckSingleError
"""
let f =
Asnc.Sleep 1000
"""
FSharpErrorSeverity.Error
39
(3, 5, 3, 9)
"The value, namespace, type or module 'Asnc' is not defined. Maybe you want one of the following:\r\n Async\r\n async\r\n asin\r\n snd"


[<Test>]
let ``Suggest Attribute`` () =
CompilerAssert.TypeCheckSingleError
"""
[<AbstractClas>]
type MyClass<'Bar>() =
abstract M<'T> : 'T -> 'T
abstract M2<'T> : 'T -> 'Bar
"""
FSharpErrorSeverity.Error
39
(2, 3, 2, 15)
"The type 'AbstractClas' is not defined. Maybe you want one of the following:\r\n AbstractClass\r\n AbstractClassAttribute"


[<Test>]
let ``Suggest Double Backtick Identifiers`` () =
CompilerAssert.TypeCheckSingleError
"""
module N =
let ``longer name`` = "hallo"
let x = N.``longe name``
"""
FSharpErrorSeverity.Error
39
(5, 11, 5, 25)
"The value, constructor, namespace or type 'longe name' is not defined. Maybe you want one of the following:\r\n longer name"


[<Test>]
let ``Suggest Double Backtick Unions`` () =
CompilerAssert.TypeCheckSingleError
"""
module N =
type MyUnion =
| ``My Case1``
| Case2
open N
let x = N.MyUnion.``My Case2``
"""
FSharpErrorSeverity.Error
39
(9, 19, 9,31)
"The field, constructor or member 'My Case2' is not defined. Maybe you want one of the following:\r\n My Case1\r\n Case2"


[<Test>]
let ``Suggest Fields In Constructor`` () =
CompilerAssert.TypeCheckSingleError
"""
type MyClass() =
member val MyProperty = "" with get, set
member val MyProperty2 = "" with get, set
member val ABigProperty = "" with get, set
let c = MyClass(Property = "")
"""
FSharpErrorSeverity.Error
495
(7, 17, 7, 25)
"The object constructor 'MyClass' has no argument or settable return property 'Property'. The required signature is new : unit -> MyClass. Maybe you want one of the following:\r\n MyProperty\r\n MyProperty2\r\n ABigProperty"


[<Test>]
let ``Suggest Generic Type`` () =
CompilerAssert.TypeCheckSingleError
"""
type T = System.Collections.Generic.Dictionary<int11,int>
"""
FSharpErrorSeverity.Error
39
(2, 48, 2, 53)
"The type 'int11' is not defined. Maybe you want one of the following:\r\n int16\r\n int16`1\r\n int8\r\n uint16\r\n int"


[<Test>]
let ``Suggest Methods`` () =
CompilerAssert.TypeCheckSingleError
"""
module Test2 =
type D() =
static let x = 1
member x.Method1() = 10
D.Method2()
"""
FSharpErrorSeverity.Error
39
(9, 7, 9, 14)
"The field, constructor or member 'Method2' is not defined. Maybe you want one of the following:\r\n Method1"


[<Test>]
let ``Suggest Modules`` () =
CompilerAssert.TypeCheckSingleError
"""
module Collections =
let f () = printfn "%s" "Hello"
open Collectons
"""
FSharpErrorSeverity.Error
39
(6, 6, 6, 16)
"The namespace or module 'Collectons' is not defined. Maybe you want one of the following:\r\n Collections"


[<Test>]
let ``Suggest Namespaces`` () =
CompilerAssert.TypeCheckSingleError
"""
open System.Collectons
"""
FSharpErrorSeverity.Error
39
(2, 13, 2, 23)
"The namespace 'Collectons' is not defined."


[<Test>]
let ``Suggest Record Labels`` () =
CompilerAssert.TypeCheckSingleError
"""
type MyRecord = { Hello: int; World: bool}
let r = { Hello = 2 ; World = true}
let x = r.ello
"""
FSharpErrorSeverity.Error
39
(6, 11, 6, 15)
"The field, constructor or member 'ello' is not defined. Maybe you want one of the following:\r\n Hello"


[<Test>]
let ``Suggest Record Type for RequireQualifiedAccess Records`` () =
CompilerAssert.TypeCheckSingleError
"""
[<RequireQualifiedAccess>]
type MyRecord = {
Field1: string
Field2: int
}
let r = { Field1 = "hallo"; Field2 = 1 }
"""
FSharpErrorSeverity.Error
39
(8, 11, 8, 17)
"The record label 'Field1' is not defined. Maybe you want one of the following:\r\n MyRecord.Field1"


[<Test>]
let ``Suggest To Use Indexer`` () =
CompilerAssert.TypeCheckWithErrors
"""
let d = [1,1] |> dict
let y = d[1]
let z = d[|1|]
let f() = d
let a = (f())[1]
"""
[|
FSharpErrorSeverity.Error, 3217, (3, 9, 3, 10), "This value is not a function and cannot be applied. Did you intend to access the indexer via d.[index] instead?"
FSharpErrorSeverity.Error, 3, (5, 9, 5, 10), "This value is not a function and cannot be applied."
FSharpErrorSeverity.Error, 3217, (8, 10, 8, 13), "This expression is not a function and cannot be applied. Did you intend to access the indexer via expr.[index] instead?"
|]


[<Test>]
let ``Suggest Type Parameters`` () =
CompilerAssert.TypeCheckSingleError
"""
[<AbstractClass>]
type MyClass<'Bar>() =
abstract M<'T> : 'T -> 'T
abstract M2<'T> : 'T -> 'Bar
abstract M3<'T> : 'T -> 'B
"""
FSharpErrorSeverity.Error
39
(6, 28, 6, 30)
"The type parameter 'B is not defined."


[<Test>]
let ``Suggest Types in Module`` () =
CompilerAssert.TypeCheckSingleError
"""
let x : System.Collections.Generic.Lst = ResizeArray()
"""
FSharpErrorSeverity.Error
39
(2, 36, 2, 39)
"The type 'Lst' is not defined in 'System.Collections.Generic'. Maybe you want one of the following:\r\n List\r\n IList\r\n List`1"

[<Test>]
let ``Suggest Types in Namespace`` () =
CompilerAssert.TypeCheckSingleError
"""
let x = System.DateTie.MaxValue
"""
FSharpErrorSeverity.Error
39
(2, 16, 2, 23)
"The value, constructor, namespace or type 'DateTie' is not defined. Maybe you want one of the following:\r\n DateTime\r\n DateTimeKind\r\n DateTimeOffset\r\n Data"


[<Test>]
let ``Suggest Union Cases`` () =
CompilerAssert.TypeCheckSingleError
"""
type MyUnion =
| ASimpleCase
| AnotherCase of int
let u = MyUnion.AntherCase
"""
FSharpErrorSeverity.Error
39
(6, 17, 6, 27)
"The field, constructor or member 'AntherCase' is not defined. Maybe you want one of the following:\r\n AnotherCase"


[<Test>]
let ``Suggest Union Type for RequireQualifiedAccess Unions`` () =
CompilerAssert.TypeCheckSingleError
"""
[<RequireQualifiedAccess>]
type MyUnion =
| MyCase1
| MyCase2 of string
let x : MyUnion = MyCase1
"""
FSharpErrorSeverity.Error
39
(7, 19, 7, 26)
"The value or constructor 'MyCase1' is not defined. Maybe you want one of the following:\r\n MyUnion.MyCase1"


[<Test>]
let ``Suggest Unions in PatternMatch`` () =
CompilerAssert.TypeCheckSingleError
"""
[<RequireQualifiedAccess>]
type MyUnion =
| Case1
| Case2
let y = MyUnion.Case1
let x =
match y with
| MyUnion.Cas1 -> 1
| _ -> 2
"""
FSharpErrorSeverity.Error
39
(11, 15, 11, 19)
"The field, constructor or member 'Cas1' is not defined. Maybe you want one of the following:\r\n Case1\r\n Case2"
Loading

0 comments on commit 7c7a87b

Please sign in to comment.