Skip to content

Commit bdb229c

Browse files
sergey-tihoncartermp
authored andcommitted
Moving ClassesTests over to NUnit (#7264)
* Moving ClassesTests over to NUnit * Fixed assertion for ParseWithErrors test
1 parent e72ded1 commit bdb229c

10 files changed

Lines changed: 128 additions & 94 deletions
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace FSharp.Compiler.UnitTests
4+
5+
open NUnit.Framework
6+
open FSharp.Compiler.SourceCodeServices
7+
8+
[<TestFixture>]
9+
module ``Classes`` =
10+
11+
[<Test>]
12+
let ``Tuple In Abstract Method``() =
13+
CompilerAssert.TypeCheckWithErrors
14+
"""
15+
type IInterface =
16+
abstract Function : (int32 * int32) -> unit
17+
18+
let x =
19+
{ new IInterface with
20+
member this.Function (i, j) = ()
21+
}
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+
|]
28+
29+
[<Test>]
30+
let ``Wrong Arity``() =
31+
CompilerAssert.TypeCheckSingleError
32+
"""
33+
type MyType() =
34+
static member MyMember(arg1, arg2:int ) = ()
35+
static member MyMember(arg1, arg2:byte) = ()
36+
37+
38+
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."
44+
45+
[<Test>]
46+
let ``Method Is Not Static``() =
47+
CompilerAssert.TypeCheckSingleError
48+
"""
49+
type Class1() =
50+
member this.X() = "F#"
51+
52+
let x = Class1.X()
53+
"""
54+
FSharpErrorSeverity.Error
55+
3214
56+
(5, 9, 5, 17)
57+
"Method or object constructor 'X' is not static"
58+
59+
[<Test>]
60+
let ``Matching Method With Same Name Is Not Abstract``() =
61+
CompilerAssert.TypeCheckWithErrors
62+
"""
63+
type Foo(x : int) =
64+
member v.MyX() = x
65+
66+
let foo =
67+
{ new Foo(3)
68+
with
69+
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+
|]
76+
77+
[<Test>]
78+
let ``No Matching Abstract Method With Same Name``() =
79+
CompilerAssert.TypeCheckWithErrors
80+
"""
81+
type IInterface =
82+
abstract MyFunction : int32 * int32 -> unit
83+
abstract SomeOtherFunction : int32 * int32 -> unit
84+
85+
let x =
86+
{ new IInterface with
87+
member this.Function (i, j) = ()
88+
}
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."
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: \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 ...'."
94+
FSharpErrorSeverity.Error, 783, (7, 9, 7, 19), "At least one override did not correctly implement its corresponding abstract member"
95+
|]
96+
97+
[<Test>]
98+
let ``Member Has Multiple Possible Dispatch Slots``() =
99+
CompilerAssert.TypeCheckWithErrors
100+
"""
101+
type IOverload =
102+
abstract member Bar : int -> int
103+
abstract member Bar : double -> int
104+
105+
type Overload =
106+
interface IOverload with
107+
override __.Bar _ = 1
108+
"""
109+
[|
110+
FSharpErrorSeverity.Error, 366, (7, 15, 7, 24), "No implementation was given for those members: \r\n\t'abstract member IOverload.Bar : double -> int'\r\n\t'abstract member IOverload.Bar : int -> int'\r\nNote 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:\r\n Bar : double -> int\r\n Bar : int -> int."
112+
|]
113+
114+
[<Test>]
115+
let ``Do Cannot Have Visibility Declarations``() =
116+
CompilerAssert.ParseWithErrors
117+
"""
118+
type X() =
119+
do ()
120+
private do ()
121+
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+
|]

tests/fsharp/FSharpSuite.Tests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<Compile Include="Compiler\ILChecker.fs" />
3434
<Compile Include="Compiler\CompilerAssert.fs" />
3535
<Compile Include="Compiler\ErrorMessages\ConstructorTests.fs" />
36+
<Compile Include="Compiler\ErrorMessages\ClassesTests.fs" />
3637
<Compile Include="Compiler\ErrorMessages\AccessOfTypeAbbreviationTests.fs" />
3738
<Compile Include="Compiler\ErrorMessages\ElseBranchHasWrongTypeTests.fs" />
3839
<Compile Include="Compiler\ConstraintSolver\PrimitiveConstraints.fs" />

tests/fsharpqa/Source/Warnings/DoCannotHaveVisibilityDeclarations.fs

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/fsharpqa/Source/Warnings/MatchingMethodWithSameNameIsNotAbstract.fs

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/fsharpqa/Source/Warnings/MemberHasMultiplePossibleDispatchSlots.fs

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/fsharpqa/Source/Warnings/MethodIsNotStatic.fs

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/fsharpqa/Source/Warnings/NoMatchingAbstractMethodWithSameName.fs

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/fsharpqa/Source/Warnings/TupleInAbstractMethod.fs

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/fsharpqa/Source/Warnings/WrongArity.fs

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/fsharpqa/Source/Warnings/env.lst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
SOURCE=WrongNumericLiteral.fs # WrongNumericLiteral.fs
2-
SOURCE=TupleInAbstractMethod.fs # TupleInAbstractMethod.fs
32
SOURCE=FS0988AtEndOfFile.fs # FS0988AtEndOfFile.fs
4-
SOURCE=WrongArity.fs # WrongArity.fs
5-
SOURCE=MethodIsNotStatic.fs # MethodIsNotStatic.fs
63
SOURCE=EqualsInsteadOfInInForLoop.fs # EqualsInsteadOfInInForLoop.fs
74
SOURCE=DontWarnExternalFunctionAsUnused.fs SCFLAGS="--warnon:1182 --warnaserror+" # DontWarnExternalFunctionAsUnused.fs
85
SOURCE=SuggestTypesInModule.fs # SuggestTypesInModule.fs
@@ -25,14 +22,10 @@
2522
SOURCE=DontSuggestWhenThingsAreOpen.fs SCFLAGS="--vserrors" # DontSuggestWhenThingsAreOpen.fs
2623
SOURCE=SuggestDoubleBacktickIdentifiers.fs SCFLAGS="--vserrors" # SuggestDoubleBacktickIdentifiers.fs
2724
SOURCE=SuggestDoubleBacktickUnions.fs SCFLAGS="--vserrors" # SuggestDoubleBacktickUnions.fs
28-
SOURCE=MatchingMethodWithSameNameIsNotAbstract.fs # MatchingMethodWithSameNameIsNotAbstract.fs
29-
SOURCE=NoMatchingAbstractMethodWithSameName.fs # NoMatchingAbstractMethodWithSameName.fs
3025
SOURCE=MissingExpressionAfterLet.fs # MissingExpressionAfterLet.fs
3126
SOURCE=SuggestFieldsInCtor.fs # SuggestFieldsInCtor.fs
3227
SOURCE=FieldSuggestion.fs # FieldSuggestion.fs
3328
SOURCE=SuggestToUseIndexer.fs # SuggestToUseIndexer.fs
34-
SOURCE=MemberHasMultiplePossibleDispatchSlots.fs # MemberHasMultiplePossibleDispatchSlots.fs
3529
SOURCE=Repro1548.fs SCFLAGS="-r:Repro1548.dll" # Repro1548.fs
36-
SOURCE=DoCannotHaveVisibilityDeclarations.fs
3730
SOURCE=ModuleAbbreviationsArePrivate.fs
3831
SOURCE=DontSuggestIntentionallyUnusedVariables.fs SCFLAGS="--vserrors" # DontSuggestIntentionallyUnusedVariables.fs

0 commit comments

Comments
 (0)