From edaa86ae5cb20338a28a9da50753311a09de994c Mon Sep 17 00:00:00 2001 From: Sergey Tihon Date: Sun, 14 Jul 2019 21:22:38 +0300 Subject: [PATCH] Moving ConstructorTests over to NUnit --- .../ErrorMessages/ConstructorTests.fs | 115 ++++++++++++++++++ tests/fsharp/FSharpSuite.Tests.fsproj | 1 + .../Source/Warnings/CommaInRecCtor.fs | 12 -- .../Source/Warnings/ExtraArgumentInCtor.fs | 10 -- .../Source/Warnings/ExtraArgumentInCtor2.fs | 11 -- .../fsharpqa/Source/Warnings/InvalidRecord.fs | 9 -- .../Source/Warnings/MissingCommaInCtor.fs | 11 -- .../Source/Warnings/MissingCtorValue.fs | 11 -- .../Source/Warnings/ValidCommaInRecCtor.fs | 9 -- tests/fsharpqa/Source/Warnings/env.lst | 7 -- 10 files changed, 116 insertions(+), 80 deletions(-) create mode 100644 tests/fsharp/Compiler/ErrorMessages/ConstructorTests.fs delete mode 100644 tests/fsharpqa/Source/Warnings/CommaInRecCtor.fs delete mode 100644 tests/fsharpqa/Source/Warnings/ExtraArgumentInCtor.fs delete mode 100644 tests/fsharpqa/Source/Warnings/ExtraArgumentInCtor2.fs delete mode 100644 tests/fsharpqa/Source/Warnings/InvalidRecord.fs delete mode 100644 tests/fsharpqa/Source/Warnings/MissingCommaInCtor.fs delete mode 100644 tests/fsharpqa/Source/Warnings/MissingCtorValue.fs delete mode 100644 tests/fsharpqa/Source/Warnings/ValidCommaInRecCtor.fs diff --git a/tests/fsharp/Compiler/ErrorMessages/ConstructorTests.fs b/tests/fsharp/Compiler/ErrorMessages/ConstructorTests.fs new file mode 100644 index 00000000000..97aa66e60a4 --- /dev/null +++ b/tests/fsharp/Compiler/ErrorMessages/ConstructorTests.fs @@ -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 + +[] +module ``Constructor`` = + + [] + 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'." + |] + + [] + 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'" + |] + + [] + 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 (',')." + |] + + [] + 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'." + + [] + 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'." + + [] + 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'." + + [] + 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" } + """ diff --git a/tests/fsharp/FSharpSuite.Tests.fsproj b/tests/fsharp/FSharpSuite.Tests.fsproj index 5976803c10e..55fad20ad29 100644 --- a/tests/fsharp/FSharpSuite.Tests.fsproj +++ b/tests/fsharp/FSharpSuite.Tests.fsproj @@ -32,6 +32,7 @@ + diff --git a/tests/fsharpqa/Source/Warnings/CommaInRecCtor.fs b/tests/fsharpqa/Source/Warnings/CommaInRecCtor.fs deleted file mode 100644 index b14d6c6dc98..00000000000 --- a/tests/fsharpqa/Source/Warnings/CommaInRecCtor.fs +++ /dev/null @@ -1,12 +0,0 @@ -// #Warnings -//This expression was expected to have type -// 'string' -//but here has type -// ''a \* 'b \* 'c' -//A ';' is used to separate field values in records. Consider replacing ',' with ';'. - - -type Person = { Name : string; Age : int; City : string } -let x = { Name = "Isaac", Age = 21, City = "London" } - -exit 0 \ No newline at end of file diff --git a/tests/fsharpqa/Source/Warnings/ExtraArgumentInCtor.fs b/tests/fsharpqa/Source/Warnings/ExtraArgumentInCtor.fs deleted file mode 100644 index 794245b450b..00000000000 --- a/tests/fsharpqa/Source/Warnings/ExtraArgumentInCtor.fs +++ /dev/null @@ -1,10 +0,0 @@ -// #Warnings -//The object constructor 'Person' takes 0 argument\(s\) but is here given 1. The required signature is 'new : unit -> Person'.$ - -type Person() = - member val Name = "" with get,set - member val Age = 0 with get,set - - -let p = - Person(1) \ No newline at end of file diff --git a/tests/fsharpqa/Source/Warnings/ExtraArgumentInCtor2.fs b/tests/fsharpqa/Source/Warnings/ExtraArgumentInCtor2.fs deleted file mode 100644 index c73f250c551..00000000000 --- a/tests/fsharpqa/Source/Warnings/ExtraArgumentInCtor2.fs +++ /dev/null @@ -1,11 +0,0 @@ -// #Warnings -//The object constructor 'Person' takes 0 argument\(s\) but is here given 1. The required signature is 'new : unit -> Person'.$ - -type Person() = - member val Name = "" with get,set - member val Age = 0 with get,set - -let b = 1 - -let p = - Person(1=b) \ No newline at end of file diff --git a/tests/fsharpqa/Source/Warnings/InvalidRecord.fs b/tests/fsharpqa/Source/Warnings/InvalidRecord.fs deleted file mode 100644 index f04f24e4576..00000000000 --- a/tests/fsharpqa/Source/Warnings/InvalidRecord.fs +++ /dev/null @@ -1,9 +0,0 @@ -// #Warnings -//This expression was expected to have type - -type Record = {field1:int; field2:int} -let doSomething (xs) = List.map (fun {field1=x} -> x) xs - -doSomething {Record.field1=0; field2=0} - -exit 0 \ No newline at end of file diff --git a/tests/fsharpqa/Source/Warnings/MissingCommaInCtor.fs b/tests/fsharpqa/Source/Warnings/MissingCommaInCtor.fs deleted file mode 100644 index 6c407bc6c4e..00000000000 --- a/tests/fsharpqa/Source/Warnings/MissingCommaInCtor.fs +++ /dev/null @@ -1,11 +0,0 @@ -// #Warnings -//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 \(','\). - -type Person() = - member val Name = "" with get,set - member val Age = 0 with get,set - - -let p = - Person(Name = "Fred" - Age = 18) \ No newline at end of file diff --git a/tests/fsharpqa/Source/Warnings/MissingCtorValue.fs b/tests/fsharpqa/Source/Warnings/MissingCtorValue.fs deleted file mode 100644 index c90377be50b..00000000000 --- a/tests/fsharpqa/Source/Warnings/MissingCtorValue.fs +++ /dev/null @@ -1,11 +0,0 @@ -// #Warnings -//The member or object constructor 'Person' requires 1 argument\(s\). The required signature is 'new : x:int -> Person'. - -type Person(x:int) = - member val Name = "" with get,set - member val Age = x with get,set - - -let p = - Person(Name = "Fred", - Age = 18) \ No newline at end of file diff --git a/tests/fsharpqa/Source/Warnings/ValidCommaInRecCtor.fs b/tests/fsharpqa/Source/Warnings/ValidCommaInRecCtor.fs deleted file mode 100644 index 6cbee50f02c..00000000000 --- a/tests/fsharpqa/Source/Warnings/ValidCommaInRecCtor.fs +++ /dev/null @@ -1,9 +0,0 @@ -// #Warnings -// - -type Person = { Name : string * bool * bool } -let Age = 22 -let City = "London" -let x = { Name = "Isaac", Age = 21, City = "London" } - -exit 0 \ No newline at end of file diff --git a/tests/fsharpqa/Source/Warnings/env.lst b/tests/fsharpqa/Source/Warnings/env.lst index 14b61a4649a..350dc92a0d9 100644 --- a/tests/fsharpqa/Source/Warnings/env.lst +++ b/tests/fsharpqa/Source/Warnings/env.lst @@ -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