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

Moving ConstructorTests over to NUnit #7236

Merged
merged 1 commit into from
Jul 15, 2019
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
115 changes: 115 additions & 0 deletions tests/fsharp/Compiler/ErrorMessages/ConstructorTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// 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 ``Constructor`` =

[<Test>]
let ``Invalid Record``() =
CompilerAssert.TypeCheckWithErrors
"""
type Record = {field1:int; field2:int}
let doSomething (xs) = List.map (fun {field1=x} -> x) xs

doSomething {Record.field1=0; field2=0}
"""
[|
FSharpErrorSeverity.Error, 1, (5, 13, 5, 40), "This expression was expected to have type\n 'Record list' \nbut here has type\n 'Record' "
FSharpErrorSeverity.Warning, 20, (5, 1, 5, 40), "The result of this expression has type 'int list' 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 ``Comma In Rec Ctor``() =
CompilerAssert.TypeCheckWithErrors
"""
type Person = { Name : string; Age : int; City : string }
let x = { Name = "Isaac", Age = 21, City = "London" }
"""
[|
FSharpErrorSeverity.Error, 1, (3, 18, 3, 52), "This expression was expected to have type\n 'string' \nbut here has type\n ''a * 'b * 'c' \r\nA ';' is used to separate field values in records. Consider replacing ',' with ';'."
FSharpErrorSeverity.Error, 764, (3, 9, 3, 54), "No assignment given for field 'Age' of type 'Test.Person'"
|]

[<Test>]
let ``Missing Comma In Ctor``() =
CompilerAssert.TypeCheckWithErrors
"""
type Person() =
member val Name = "" with get,set
member val Age = 0 with get,set

let p =
Person(Name = "Fred"
Age = 18)
"""
[|
FSharpErrorSeverity.Error, 39, (7, 12, 7, 16), "The value or constructor 'Name' is not defined."
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 (',')."
|]

[<Test>]
let ``Missing Ctor Value``() =
CompilerAssert.TypeCheckSingleError
"""
type Person(x:int) =
member val Name = "" with get,set
member val Age = x with get,set

let p =
Person(Name = "Fred",
Age = 18)
"""
FSharpErrorSeverity.Error
496
(7, 5, 8, 21)
"The member or object constructor 'Person' requires 1 argument(s). The required signature is 'new : x:int -> Person'."

[<Test>]
let ``Extra Argument In Ctor``() =
CompilerAssert.TypeCheckSingleError
"""
type Person() =
member val Name = "" with get,set
member val Age = 0 with get,set

let p =
Person(1)
"""
FSharpErrorSeverity.Error
501
(7, 5, 7, 14)
"The object constructor 'Person' takes 0 argument(s) but is here given 1. The required signature is 'new : unit -> Person'."

[<Test>]
let ``Extra Argument In Ctor2``() =
CompilerAssert.TypeCheckSingleError
"""
type Person() =
member val Name = "" with get,set
member val Age = 0 with get,set

let b = 1

let p =
Person(1=b)
"""
FSharpErrorSeverity.Error
501
(9, 5, 9, 16)
"The object constructor 'Person' takes 0 argument(s) but is here given 1. The required signature is 'new : unit -> Person'."

[<Test>]
let ``Valid Comma In Rec Ctor``() =
CompilerAssert.Pass
"""
type Person = { Name : string * bool * bool }
let Age = 22
let City = "London"
let x = { Name = "Isaac", Age = 21, City = "London" }
"""
1 change: 1 addition & 0 deletions tests/fsharp/FSharpSuite.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<Compile Include="tests.fs" />
<Compile Include="Compiler\ILChecker.fs" />
<Compile Include="Compiler\CompilerAssert.fs" />
<Compile Include="Compiler\ErrorMessages\ConstructorTests.fs" />
<Compile Include="Compiler\ErrorMessages\AccessOfTypeAbbreviationTests.fs" />
<Compile Include="Compiler\ErrorMessages\ElseBranchHasWrongTypeTests.fs" />
<Compile Include="Compiler\ErrorMessages\MissingElseBranch.fs" />
Expand Down
12 changes: 0 additions & 12 deletions tests/fsharpqa/Source/Warnings/CommaInRecCtor.fs

This file was deleted.

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

This file was deleted.

11 changes: 0 additions & 11 deletions tests/fsharpqa/Source/Warnings/ExtraArgumentInCtor2.fs

This file was deleted.

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

This file was deleted.

11 changes: 0 additions & 11 deletions tests/fsharpqa/Source/Warnings/MissingCommaInCtor.fs

This file was deleted.

11 changes: 0 additions & 11 deletions tests/fsharpqa/Source/Warnings/MissingCtorValue.fs

This file was deleted.

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

This file was deleted.

7 changes: 0 additions & 7 deletions tests/fsharpqa/Source/Warnings/env.lst
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
SOURCE=ReturnInsteadOfReturnBang.fs # ReturnInsteadOfReturnBang.fs
SOURCE=YieldInsteadOfYieldBang.fs # YieldInsteadOfYieldBang.fs
SOURCE=TupleInAbstractMethod.fs # TupleInAbstractMethod.fs
SOURCE=InvalidRecord.fs # InvalidRecord.fs
SOURCE=CommaInRecCtor.fs # CommaInRecCtor.fs
SOURCE=MissingCommaInCtor.fs # MissingCommaInCtor.fs
SOURCE=MissingCtorValue.fs # MissingCtorValue.fs
SOURCE=ExtraArgumentInCtor.fs # ExtraArgumentInCtor.fs
SOURCE=ExtraArgumentInCtor2.fs # ExtraArgumentInCtor2.fs
SOURCE=ValidCommaInRecCtor.fs # ValidCommaInRecCtor.fs
SOURCE=FS0988AtEndOfFile.fs # FS0988AtEndOfFile.fs
SOURCE=WrongArity.fs # WrongArity.fs
SOURCE=OverrideErrors.fs # OverrideErrors.fs
Expand Down