Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit eb829b8

Browse files
vzarytovskiinosami
authored andcommitted
Move existing Compiler.ComponentTests to a new Compiler.fs framework (dotnet#9839)
* Move existing Compiler.ComponentTests to a new Compiler.fs framework; Add 'parse' function * Changed some wording in error messages
1 parent d173a91 commit eb829b8

25 files changed

+630
-720
lines changed

tests/FSharp.Compiler.ComponentTests/ConstraintSolver/MemberConstraints.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
22

3-
namespace FSharp.Compiler.ConstraintSolver.ComponentTests
3+
namespace FSharp.Compiler.ComponentTests.ConstraintSolver
44

55
open Xunit
66
open FSharp.Test.Utilities.Compiler

tests/FSharp.Compiler.ComponentTests/ConstraintSolver/PrimitiveConstraints.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
22

3-
namespace FSharp.Compiler.ConstraintSolver.ComponentTests
3+
namespace FSharp.Compiler.ComponentTests.ConstraintSolver
44

55
open Xunit
66
open FSharp.Test.Utilities.Compiler
Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,74 @@
11
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
22

3-
namespace FSharp.Compiler.ErrorMessages.ComponentTests
3+
namespace FSharp.Compiler.ComponentTests.ErrorMessages
44

55
open Xunit
6-
open FSharp.Test.Utilities
6+
open FSharp.Test.Utilities.Compiler
77
open FSharp.Compiler.SourceCodeServices
88

99
module ``Access Of Type Abbreviation`` =
1010

11+
let warning44Message = "This construct is deprecated. The type 'Hidden' is less accessible than the value, member or type 'Exported' it is used in." + System.Environment.NewLine + "As of F# 4.1, the accessibility of type abbreviations is checked at compile-time. Consider changing the accessibility of the type abbreviation. Ignoring this warning might lead to runtime errors."
12+
1113
[<Fact>]
1214
let ``Private type produces warning when trying to export``() =
13-
CompilerAssert.TypeCheckSingleError
14-
"""
15+
FSharp """
1516
module Library =
1617
type private Hidden = Hidden of unit
1718
type Exported = Hidden
18-
"""
19-
FSharpErrorSeverity.Warning
20-
44
21-
(4, 8, 4, 16)
22-
("This construct is deprecated. The type 'Hidden' is less accessible than the value, member or type 'Exported' it is used in." + System.Environment.NewLine + "As of F# 4.1, the accessibility of type abbreviations is checked at compile-time. Consider changing the accessibility of the type abbreviation. Ignoring this warning might lead to runtime errors.")
19+
"""
20+
|> typecheck
21+
|> shouldFail
22+
|> withSingleDiagnostic (Warning 44, Line 4, Col 8, Line 4, Col 16, warning44Message)
2323

2424
[<Fact>]
2525
let ``Internal type passes when abbrev is internal``() =
26-
CompilerAssert.Pass
27-
"""
26+
FSharp """
2827
module Library =
2928
type internal Hidden = Hidden of unit
3029
type internal Exported = Hidden
31-
"""
30+
"""
31+
|> typecheck
32+
|> shouldSucceed
3233

3334
[<Fact>]
3435
let ``Internal type produces warning when trying to export``() =
35-
CompilerAssert.TypeCheckSingleError
36-
"""
36+
FSharp """
3737
module Library =
3838
type internal Hidden = Hidden of unit
3939
type Exported = Hidden
40-
"""
41-
FSharpErrorSeverity.Warning
42-
44
43-
(4, 8, 4, 16)
44-
("This construct is deprecated. The type 'Hidden' is less accessible than the value, member or type 'Exported' it is used in." + System.Environment.NewLine + "As of F# 4.1, the accessibility of type abbreviations is checked at compile-time. Consider changing the accessibility of the type abbreviation. Ignoring this warning might lead to runtime errors.")
40+
"""
41+
|> typecheck
42+
|> shouldFail
43+
|> withSingleDiagnostic (Warning 44, Line 4, Col 8, Line 4, Col 16, warning44Message)
4544

4645
[<Fact>]
4746
let ``Private type produces warning when abbrev is internal``() =
48-
CompilerAssert.TypeCheckSingleError
49-
"""
47+
FSharp """
5048
module Library =
5149
type private Hidden = Hidden of unit
5250
type internal Exported = Hidden
53-
"""
54-
FSharpErrorSeverity.Warning
55-
44
56-
(4, 17, 4, 25)
57-
("This construct is deprecated. The type 'Hidden' is less accessible than the value, member or type 'Exported' it is used in." + System.Environment.NewLine + "As of F# 4.1, the accessibility of type abbreviations is checked at compile-time. Consider changing the accessibility of the type abbreviation. Ignoring this warning might lead to runtime errors.")
51+
"""
52+
|> typecheck
53+
|> shouldFail
54+
|> withSingleDiagnostic (Warning 44, Line 4, Col 17, Line 4, Col 25, warning44Message)
5855

5956
[<Fact>]
6057
let ``Private type passes when abbrev is private``() =
61-
CompilerAssert.Pass
62-
"""
58+
FSharp """
6359
module Library =
6460
type private Hidden = Hidden of unit
6561
type private Exported = Hidden
66-
"""
62+
"""
63+
|> typecheck
64+
|> shouldSucceed
6765

6866
[<Fact>]
6967
let ``Default access type passes when abbrev is default``() =
70-
CompilerAssert.Pass
71-
"""
68+
FSharp """
7269
module Library =
7370
type Hidden = Hidden of unit
7471
type Exported = Hidden
75-
"""
72+
"""
73+
|> typecheck
74+
|> shouldSucceed
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
22

3-
namespace FSharp.Compiler.ErrorMessages.ComponentTests
3+
namespace FSharp.Compiler.ComponentTests.ErrorMessages
44

55
open Xunit
6-
open FSharp.Test.Utilities
7-
open FSharp.Compiler.SourceCodeServices
8-
6+
open FSharp.Test.Utilities.Compiler
97

108
module ``Errors assigning to mutable objects`` =
119

1210
[<Fact>]
1311
let ``Assign to immutable error``() =
14-
CompilerAssert.TypeCheckSingleError
15-
"""
12+
FSharp """
1613
let x = 10
1714
x <- 20
18-
"""
19-
FSharpErrorSeverity.Error
20-
27
21-
(3, 1, 3, 8)
22-
"This value is not mutable. Consider using the mutable keyword, e.g. 'let mutable x = expression'."
15+
"""
16+
|> typecheck
17+
|> shouldFail
18+
|> withSingleDiagnostic (Error 27, Line 3, Col 1, Line 3, Col 8,
19+
"This value is not mutable. Consider using the mutable keyword, e.g. 'let mutable x = expression'.")
Lines changed: 53 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,78 @@
11
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
22

3-
namespace FSharp.Compiler.ErrorMessages.ComponentTests
3+
namespace FSharp.Compiler.ComponentTests.ErrorMessages
44

55
open Xunit
6-
open FSharp.Test.Utilities
7-
open FSharp.Compiler.SourceCodeServices
6+
open FSharp.Test.Utilities.Compiler
87

98
module ``Classes`` =
109

1110
[<Fact>]
1211
let ``Tuple In Abstract Method``() =
13-
CompilerAssert.TypeCheckWithErrors
14-
"""
12+
FSharp """
1513
type IInterface =
1614
abstract Function : (int32 * int32) -> unit
1715
1816
let x =
1917
{ new IInterface with
2018
member this.Function (i, j) = ()
2119
}
22-
"""
23-
[|
24-
FSharpErrorSeverity.Error, 768, (7, 16, 7, 36), "The member 'Function' does not accept the correct number of arguments. 1 argument(s) are expected, but 2 were given. The required signature is 'member IInterface.Function : (int32 * int32) -> unit'.\nA tuple type is required for one or more arguments. Consider wrapping the given arguments in additional parentheses or review the definition of the interface."
25-
FSharpErrorSeverity.Error, 17, (7, 21, 7, 29), "The member 'Function : 'a * 'b -> unit' does not have the correct type to override the corresponding abstract method. The required signature is 'Function : (int32 * int32) -> unit'."
26-
FSharpErrorSeverity.Error, 783, (6, 9, 6, 19), "At least one override did not correctly implement its corresponding abstract member"
27-
|]
20+
"""
21+
|> typecheck
22+
|> shouldFail
23+
|> withDiagnostics [
24+
(Error 768, Line 7, Col 16, Line 7, Col 36, "The member 'Function' does not accept the correct number of arguments. 1 argument(s) are expected, but 2 were given. The required signature is 'member IInterface.Function : (int32 * int32) -> unit'.\nA tuple type is required for one or more arguments. Consider wrapping the given arguments in additional parentheses or review the definition of the interface.")
25+
(Error 17, Line 7, Col 21, Line 7, Col 29, "The member 'Function : 'a * 'b -> unit' does not have the correct type to override the corresponding abstract method. The required signature is 'Function : (int32 * int32) -> unit'.")
26+
(Error 783, Line 6, Col 9, Line 6, Col 19, "At least one override did not correctly implement its corresponding abstract member")]
2827

2928
[<Fact>]
3029
let ``Wrong Arity``() =
31-
CompilerAssert.TypeCheckSingleError
32-
"""
30+
FSharp """
3331
type MyType() =
3432
static member MyMember(arg1, arg2:int ) = ()
3533
static member MyMember(arg1, arg2:byte) = ()
3634
3735
3836
MyType.MyMember("", 0, 0)
39-
"""
40-
FSharpErrorSeverity.Error
41-
503
42-
(7, 1, 7, 26)
43-
"A member or object constructor 'MyMember' taking 3 arguments is not accessible from this code location. All accessible versions of method 'MyMember' take 2 arguments."
37+
"""
38+
|> typecheck
39+
|> shouldFail
40+
|> withSingleDiagnostic (Error 503, Line 7, Col 1, Line 7, Col 26,
41+
"A member or object constructor 'MyMember' taking 3 arguments is not accessible from this code location. All accessible versions of method 'MyMember' take 2 arguments.")
4442

4543
[<Fact>]
4644
let ``Method Is Not Static``() =
47-
CompilerAssert.TypeCheckSingleError
48-
"""
45+
FSharp """
4946
type Class1() =
5047
member this.X() = "F#"
5148
5249
let x = Class1.X()
53-
"""
54-
FSharpErrorSeverity.Error
55-
3214
56-
(5, 9, 5, 17)
57-
"Method or object constructor 'X' is not static"
50+
"""
51+
|> typecheck
52+
|> shouldFail
53+
|> withSingleDiagnostic (Error 3214, Line 5, Col 9, Line 5, Col 17, "Method or object constructor 'X' is not static")
5854

5955
[<Fact>]
6056
let ``Matching Method With Same Name Is Not Abstract``() =
61-
CompilerAssert.TypeCheckWithErrors
62-
"""
57+
FSharp """
6358
type Foo(x : int) =
6459
member v.MyX() = x
6560
6661
let foo =
6762
{ new Foo(3)
6863
with
6964
member v.MyX() = 4 }
70-
"""
71-
[|
72-
FSharpErrorSeverity.Error, 767, (8, 16, 8, 23), "The type Foo contains the member 'MyX' but it is not a virtual or abstract method that is available to override or implement."
73-
FSharpErrorSeverity.Error, 17, (8, 18, 8, 21), "The member 'MyX : unit -> int' does not have the correct type to override any given virtual method"
74-
FSharpErrorSeverity.Error, 783, (6, 11, 6, 14), "At least one override did not correctly implement its corresponding abstract member"
75-
|]
65+
"""
66+
|> typecheck
67+
|> shouldFail
68+
|> withDiagnostics [
69+
(Error 767, Line 8, Col 16, Line 8, Col 23, "The type Foo contains the member 'MyX' but it is not a virtual or abstract method that is available to override or implement.")
70+
(Error 17, Line 8, Col 18, Line 8, Col 21, "The member 'MyX : unit -> int' does not have the correct type to override any given virtual method")
71+
(Error 783, Line 6, Col 11, Line 6, Col 14, "At least one override did not correctly implement its corresponding abstract member")]
7672

7773
[<Fact>]
7874
let ``No Matching Abstract Method With Same Name``() =
79-
CompilerAssert.TypeCheckWithErrors
80-
"""
75+
FSharp """
8176
type IInterface =
8277
abstract MyFunction : int32 * int32 -> unit
8378
abstract SomeOtherFunction : int32 * int32 -> unit
@@ -86,42 +81,43 @@ let x =
8681
{ new IInterface with
8782
member this.Function (i, j) = ()
8883
}
89-
"""
90-
[|
91-
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:" + System.Environment.NewLine + " MyFunction"
92-
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"
93-
FSharpErrorSeverity.Error, 366, (7, 3, 9, 4), "No implementation was given for those members: " + System.Environment.NewLine + "\t'abstract member IInterface.MyFunction : int32 * int32 -> unit'" + System.Environment.NewLine + "\t'abstract member IInterface.SomeOtherFunction : int32 * int32 -> unit'" + System.Environment.NewLine + "Note that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'."
94-
FSharpErrorSeverity.Error, 783, (7, 9, 7, 19), "At least one override did not correctly implement its corresponding abstract member"
95-
|]
84+
"""
85+
|> typecheck
86+
|> shouldFail
87+
|> withDiagnostics [
88+
(Error 767, Line 8, Col 14, Line 8, Col 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:" + System.Environment.NewLine + " MyFunction")
89+
(Error 17, Line 8, Col 19, Line 8, Col 27, "The member 'Function : 'a * 'b -> unit' does not have the correct type to override any given virtual method")
90+
(Error 366, Line 7, Col 3, Line 9, Col 4, "No implementation was given for those members: " + System.Environment.NewLine + "\t'abstract member IInterface.MyFunction : int32 * int32 -> unit'" + System.Environment.NewLine + "\t'abstract member IInterface.SomeOtherFunction : int32 * int32 -> unit'" + System.Environment.NewLine + "Note that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'.")
91+
(Error 783, Line 7, Col 9, Line 7, Col 19, "At least one override did not correctly implement its corresponding abstract member")]
9692

9793
[<Fact>]
9894
let ``Member Has Multiple Possible Dispatch Slots``() =
99-
CompilerAssert.TypeCheckWithErrors
100-
"""
95+
FSharp """
10196
type IOverload =
10297
abstract member Bar : int -> int
10398
abstract member Bar : double -> int
10499
105100
type Overload =
106101
interface IOverload with
107102
override __.Bar _ = 1
108-
"""
109-
[|
110-
FSharpErrorSeverity.Error, 366, (7, 15, 7, 24), "No implementation was given for those members: " + System.Environment.NewLine + "\t'abstract member IOverload.Bar : double -> int'" + System.Environment.NewLine + "\t'abstract member IOverload.Bar : int -> int'" + System.Environment.NewLine + "Note that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'."
111-
FSharpErrorSeverity.Error, 3213, (8, 21, 8, 24), "The member 'Bar<'a0> : 'a0 -> int' matches multiple overloads of the same method.\nPlease restrict it to one of the following:" + System.Environment.NewLine + " Bar : double -> int" + System.Environment.NewLine + " Bar : int -> int."
112-
|]
103+
"""
104+
|> typecheck
105+
|> shouldFail
106+
|> withDiagnostics [
107+
(Error 366, Line 7, Col 15, Line 7, Col 24, "No implementation was given for those members: " + System.Environment.NewLine + "\t'abstract member IOverload.Bar : double -> int'" + System.Environment.NewLine + "\t'abstract member IOverload.Bar : int -> int'" + System.Environment.NewLine + "Note that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'.")
108+
(Error 3213, Line 8, Col 21, Line 8, Col 24, "The member 'Bar<'a0> : 'a0 -> int' matches multiple overloads of the same method.\nPlease restrict it to one of the following:" + System.Environment.NewLine + " Bar : double -> int" + System.Environment.NewLine + " Bar : int -> int.")]
113109

114110
[<Fact>]
115111
let ``Do Cannot Have Visibility Declarations``() =
116-
CompilerAssert.ParseWithErrors
117-
"""
112+
FSharp """
118113
type X() =
119114
do ()
120115
private do ()
121116
static member Y() = 1
122-
"""
123-
[|
124-
FSharpErrorSeverity.Error, 531, (4, 5, 4, 12), "Accessibility modifiers should come immediately prior to the identifier naming a construct"
125-
FSharpErrorSeverity.Error, 512, (4, 13, 4, 18), "Accessibility modifiers are not permitted on 'do' bindings, but 'Private' was given."
126-
FSharpErrorSeverity.Error, 222, (2, 1, 3, 1), "Files in libraries or multiple-file applications must begin with a namespace or module declaration, e.g. 'namespace SomeNamespace.SubNamespace' or 'module SomeNamespace.SomeModule'. Only the last source file of an application may omit such a declaration."
127-
|]
117+
"""
118+
|> parse
119+
|> shouldFail
120+
|> withDiagnostics [
121+
(Error 531, Line 4, Col 5, Line 4, Col 12, "Accessibility modifiers should come immediately prior to the identifier naming a construct")
122+
(Error 512, Line 4, Col 13, Line 4, Col 18, "Accessibility modifiers are not permitted on 'do' bindings, but 'Private' was given.")
123+
(Error 222, Line 2, Col 1, Line 3, Col 1, "Files in libraries or multiple-file applications must begin with a namespace or module declaration, e.g. 'namespace SomeNamespace.SubNamespace' or 'module SomeNamespace.SomeModule'. Only the last source file of an application may omit such a declaration.")]

tests/FSharp.Compiler.ComponentTests/ErrorMessages/ConfusingTypeName.fs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
22

3-
namespace FSharp.Compiler.ErrorMessages.ComponentTests
3+
namespace FSharp.Compiler.ComponentTests.ErrorMessages
44

55
open Xunit
6-
open FSharp.Test.Utilities
76
open FSharp.Test.Utilities.Compiler
8-
open FSharp.Test.Utilities.Utilities
9-
open FSharp.Compiler.SourceCodeServices
107

118
module ``Confusing Type Name`` =
129

0 commit comments

Comments
 (0)