Skip to content

Commit

Permalink
Moving TypeMismatchTests over to NUnit (#7250)
Browse files Browse the repository at this point in the history
* Moving TypeMismatchTests over to NUnit

* ci restart
  • Loading branch information
sergey-tihon authored and KevinRansom committed Jul 19, 2019
1 parent 4151eb2 commit bdb2b79
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 105 deletions.
135 changes: 135 additions & 0 deletions tests/fsharp/Compiler/ErrorMessages/TypeMismatchTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// 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 ``Type Mismatch`` =

[<Test>]
let ``return Instead Of return!``() =
CompilerAssert.TypeCheckSingleError
"""
let rec foo() = async { return foo() }
"""
FSharpErrorSeverity.Error
1
(2, 32, 2, 37)
"Type mismatch. Expecting a\n ''a' \nbut given a\n 'Async<'a>' \nThe types ''a' and 'Async<'a>' cannot be unified. Consider using 'return!' instead of 'return'."

[<Test>]
let ``yield Instead Of yield!``() =
CompilerAssert.TypeCheckSingleError
"""
type Foo() =
member this.Yield(x) = [x]
let rec f () = Foo() { yield f ()}
"""
FSharpErrorSeverity.Error
1
(5, 30, 5, 34)
"Type mismatch. Expecting a\n ''a' \nbut given a\n ''a list' \nThe types ''a' and ''a list' cannot be unified. Consider using 'yield!' instead of 'yield'."

[<Test>]
let ``Ref Cell Instead Of Not``() =
CompilerAssert.TypeCheckSingleError
"""
let x = true
if !x then
printfn "hello"
"""
FSharpErrorSeverity.Error
1
(3, 5, 3, 6)
"This expression was expected to have type\n 'bool ref' \nbut here has type\n 'bool' \r\nThe '!' operator is used to dereference a ref cell. Consider using 'not expr' here."

[<Test>]
let ``Ref Cell Instead Of Not 2``() =
CompilerAssert.TypeCheckSingleError
"""
let x = true
let y = !x
"""
FSharpErrorSeverity.Error
1
(3, 10, 3, 11)
"This expression was expected to have type\n ''a ref' \nbut here has type\n 'bool' \r\nThe '!' operator is used to dereference a ref cell. Consider using 'not expr' here."

[<Test>]
let ``Guard Has Wrong Type``() =
CompilerAssert.TypeCheckWithErrors
"""
let x = 1
match x with
| 1 when "s" -> true
| _ -> false
"""
[|
FSharpErrorSeverity.Error, 1, (4, 10, 4, 13), "A pattern match guard must be of type 'bool', but this 'when' expression is of type 'string'."
FSharpErrorSeverity.Warning, 20, (3, 1, 5, 13), "The result of this expression has type 'bool' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'."
|]

[<Test>]
let ``Runtime Type Test In Pattern``() =
CompilerAssert.TypeCheckWithErrors
"""
open System.Collections.Generic
let orig = Dictionary<obj,obj>()
let c =
match orig with
| :? IDictionary<obj,obj> -> "yes"
| _ -> "no"
"""
[|
FSharpErrorSeverity.Warning, 67, (8, 5, 8, 28), "This type test or downcast will always hold"
FSharpErrorSeverity.Error, 193, (8, 5, 8, 28), "Type constraint mismatch. The type \n 'IDictionary<obj,obj>' \nis not compatible with type\n 'Dictionary<obj,obj>' \n"
|]

[<Test>]
let ``Runtime Type Test In Pattern 2``() =
CompilerAssert.TypeCheckWithErrors
"""
open System.Collections.Generic
let orig = Dictionary<obj,obj>()
let c =
match orig with
| :? IDictionary<obj,obj> as y -> "yes" + y.ToString()
| _ -> "no"
"""
[|
FSharpErrorSeverity.Warning, 67, (8, 5, 8, 28), "This type test or downcast will always hold"
FSharpErrorSeverity.Error, 193, (8, 5, 8, 28), "Type constraint mismatch. The type \n 'IDictionary<obj,obj>' \nis not compatible with type\n 'Dictionary<obj,obj>' \n"
|]

[<Test>]
let ``Override Errors``() =
CompilerAssert.TypeCheckWithErrors
"""
type Base() =
abstract member Member: int * string -> string
default x.Member (i, s) = s
type Derived1() =
inherit Base()
override x.Member() = 5
type Derived2() =
inherit Base()
override x.Member (i : int) = "Hello"
type Derived3() =
inherit Base()
override x.Member (s : string, i : int) = sprintf "Hello %s" s
"""
[|
FSharpErrorSeverity.Error, 856, (8, 16, 8, 22), "This override takes a different number of arguments to the corresponding abstract member. The following abstract members were found:\r\n abstract member Base.Member : int * string -> string"
FSharpErrorSeverity.Error, 856, (12, 16, 12, 22), "This override takes a different number of arguments to the corresponding abstract member. The following abstract members were found:\r\n abstract member Base.Member : int * string -> string"
FSharpErrorSeverity.Error, 1, (16, 24, 16, 34), "This expression was expected to have type\n 'int' \nbut here has type\n 'string' "
|]
1 change: 1 addition & 0 deletions tests/fsharp/FSharpSuite.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<Compile Include="Compiler\ErrorMessages\MissingElseBranch.fs" />
<Compile Include="Compiler\ErrorMessages\UnitGenericAbstactType.fs" />
<Compile Include="Compiler\ErrorMessages\NameResolutionTests.fs" />
<Compile Include="Compiler\ErrorMessages\TypeMismatchTests.fs" />
<Compile Include="Compiler\ErrorMessages\UpcastDowncastTests.fs" />
<Compile Include="Compiler\ErrorMessages\AssignmentErrorTests.fs" />
<Compile Include="Compiler\ErrorMessages\WarnExpressionTests.fs" />
Expand Down
9 changes: 0 additions & 9 deletions tests/fsharpqa/Source/Warnings/GuardHasWrongType.fs

This file was deleted.

22 changes: 0 additions & 22 deletions tests/fsharpqa/Source/Warnings/OverrideErrors.fs

This file was deleted.

9 changes: 0 additions & 9 deletions tests/fsharpqa/Source/Warnings/RefCellInsteadOfNot.fs

This file was deleted.

8 changes: 0 additions & 8 deletions tests/fsharpqa/Source/Warnings/RefCellInsteadOfNot2.fs

This file was deleted.

10 changes: 0 additions & 10 deletions tests/fsharpqa/Source/Warnings/ReturnInsteadOfReturnBang.fs

This file was deleted.

13 changes: 0 additions & 13 deletions tests/fsharpqa/Source/Warnings/RuntimeTypeTestInPattern.fs

This file was deleted.

13 changes: 0 additions & 13 deletions tests/fsharpqa/Source/Warnings/RuntimeTypeTestInPattern2.fs

This file was deleted.

13 changes: 0 additions & 13 deletions tests/fsharpqa/Source/Warnings/YieldInsteadOfYieldBang.fs

This file was deleted.

8 changes: 0 additions & 8 deletions tests/fsharpqa/Source/Warnings/env.lst
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
SOURCE=WrongNumericLiteral.fs # WrongNumericLiteral.fs
SOURCE=ReturnInsteadOfReturnBang.fs # ReturnInsteadOfReturnBang.fs
SOURCE=YieldInsteadOfYieldBang.fs # YieldInsteadOfYieldBang.fs
SOURCE=TupleInAbstractMethod.fs # TupleInAbstractMethod.fs
SOURCE=FS0988AtEndOfFile.fs # FS0988AtEndOfFile.fs
SOURCE=WrongArity.fs # WrongArity.fs
SOURCE=OverrideErrors.fs # OverrideErrors.fs
SOURCE=MethodIsNotStatic.fs # MethodIsNotStatic.fs
SOURCE=EqualsInsteadOfInInForLoop.fs # EqualsInsteadOfInInForLoop.fs
SOURCE=DontWarnExternalFunctionAsUnused.fs SCFLAGS="--warnon:1182 --warnaserror+" # DontWarnExternalFunctionAsUnused.fs
Expand All @@ -28,17 +25,12 @@
SOURCE=DontSuggestWhenThingsAreOpen.fs SCFLAGS="--vserrors" # DontSuggestWhenThingsAreOpen.fs
SOURCE=SuggestDoubleBacktickIdentifiers.fs SCFLAGS="--vserrors" # SuggestDoubleBacktickIdentifiers.fs
SOURCE=SuggestDoubleBacktickUnions.fs SCFLAGS="--vserrors" # SuggestDoubleBacktickUnions.fs
SOURCE=GuardHasWrongType.fs # GuardHasWrongType.fs
SOURCE=MatchingMethodWithSameNameIsNotAbstract.fs # MatchingMethodWithSameNameIsNotAbstract.fs
SOURCE=NoMatchingAbstractMethodWithSameName.fs # NoMatchingAbstractMethodWithSameName.fs
SOURCE=MissingExpressionAfterLet.fs # MissingExpressionAfterLet.fs
SOURCE=SuggestFieldsInCtor.fs # SuggestFieldsInCtor.fs
SOURCE=FieldSuggestion.fs # FieldSuggestion.fs
SOURCE=SuggestToUseIndexer.fs # SuggestToUseIndexer.fs
SOURCE=RefCellInsteadOfNot.fs # RefCellInsteadOfNot.fs
SOURCE=RefCellInsteadOfNot2.fs # RefCellInsteadOfNot2.fs
SOURCE=RuntimeTypeTestInPattern.fs # RuntimeTypeTestInPattern.fs
SOURCE=RuntimeTypeTestInPattern2.fs # RuntimeTypeTestInPattern2.fs
SOURCE=MemberHasMultiplePossibleDispatchSlots.fs # MemberHasMultiplePossibleDispatchSlots.fs
SOURCE=Repro1548.fs SCFLAGS="-r:Repro1548.dll" # Repro1548.fs
SOURCE=DoCannotHaveVisibilityDeclarations.fs
Expand Down

0 comments on commit bdb2b79

Please sign in to comment.