From d8a8cea5815d1d17ab4ba8bffc8b165ff5c2101c Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Thu, 11 Jul 2019 08:55:37 +0200 Subject: [PATCH 1/2] Use 1-based column numbers in tests --- tests/fsharp/Compiler/CompilerAssert.fs | 2 +- tests/fsharp/Compiler/Language/AnonRecordTests.fs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/fsharp/Compiler/CompilerAssert.fs b/tests/fsharp/Compiler/CompilerAssert.fs index 40da516c515..0d0bf7d3dae 100644 --- a/tests/fsharp/Compiler/CompilerAssert.fs +++ b/tests/fsharp/Compiler/CompilerAssert.fs @@ -130,7 +130,7 @@ module CompilerAssert = |> Array.iter (fun info -> Assert.AreEqual(FSharpErrorSeverity.Error, info.Severity) Assert.AreEqual(expectedErrorNumber, info.ErrorNumber, "expectedErrorNumber") - Assert.AreEqual(expectedErrorRange, (info.StartLineAlternate, info.StartColumn, info.EndLineAlternate, info.EndColumn), "expectedErrorRange") + Assert.AreEqual(expectedErrorRange, (info.StartLineAlternate, info.StartColumn + 1, info.EndLineAlternate, info.EndColumn + 1), "expectedErrorRange") Assert.AreEqual(expectedErrorMsg, info.Message, "expectedErrorMsg") ) diff --git a/tests/fsharp/Compiler/Language/AnonRecordTests.fs b/tests/fsharp/Compiler/Language/AnonRecordTests.fs index 7182e359b19..ab65194f220 100644 --- a/tests/fsharp/Compiler/Language/AnonRecordTests.fs +++ b/tests/fsharp/Compiler/Language/AnonRecordTests.fs @@ -31,7 +31,7 @@ type RefClass<'a when 'a : not struct>() = class end let rAnon = RefClass() """ 1 - (3, 12, 3, 41) + (3, 13, 3, 42) "A generic construct requires that the type 'struct {|R : int|}' have reference semantics, but it does not, i.e. it is a struct" [] @@ -42,5 +42,5 @@ type StructClass<'a when 'a : struct>() = class end let sAnon = StructClass<{| S: int |}>() """ 1 - (3, 12, 3, 37) + (3, 13, 3, 38) "A generic construct requires that the type '{|S : int|}' is a CLI or F# struct type" \ No newline at end of file From 065eff8954349f32cd181b7b9c958532377b96dc Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Thu, 11 Jul 2019 09:03:18 +0200 Subject: [PATCH 2/2] Helper that can check for multiple type errors --- tests/fsharp/Compiler/CompilerAssert.fs | 16 +++++++++++----- .../fsharp/Compiler/Language/AnonRecordTests.fs | 5 ++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/fsharp/Compiler/CompilerAssert.fs b/tests/fsharp/Compiler/CompilerAssert.fs index 0d0bf7d3dae..9c748455498 100644 --- a/tests/fsharp/Compiler/CompilerAssert.fs +++ b/tests/fsharp/Compiler/CompilerAssert.fs @@ -111,7 +111,8 @@ module CompilerAssert = Assert.IsEmpty(typeCheckResults.Errors, sprintf "Type Check errors: %A" typeCheckResults.Errors) - let TypeCheckSingleError (source: string) (expectedErrorNumber: int) (expectedErrorRange: int * int * int * int) (expectedErrorMsg: string) = + + let TypeCheckWithErrors (source: string) expectedTypeErrors = lock gate <| fun () -> let parseResults, fileAnswer = checker.ParseAndCheckFileInProject("test.fs", 0, SourceText.ofString source, defaultProjectOptions) |> Async.RunSynchronously @@ -125,15 +126,20 @@ module CompilerAssert = typeCheckResults.Errors |> Array.distinctBy (fun e -> e.Severity, e.ErrorNumber, e.StartLineAlternate, e.StartColumn, e.EndLineAlternate, e.EndColumn, e.Message) - Assert.AreEqual(1, errors.Length, sprintf "Expected one type check error: %A" typeCheckResults.Errors) - errors - |> Array.iter (fun info -> - Assert.AreEqual(FSharpErrorSeverity.Error, info.Severity) + Assert.AreEqual(Array.length expectedTypeErrors, errors.Length, sprintf "Type check errors: %A" typeCheckResults.Errors) + + Array.zip errors expectedTypeErrors + |> Array.iter (fun (info, expectedError) -> + let (expectedServerity: FSharpErrorSeverity, expectedErrorNumber: int, expectedErrorRange: int * int * int * int, expectedErrorMsg: string) = expectedError + Assert.AreEqual(expectedServerity, info.Severity) Assert.AreEqual(expectedErrorNumber, info.ErrorNumber, "expectedErrorNumber") Assert.AreEqual(expectedErrorRange, (info.StartLineAlternate, info.StartColumn + 1, info.EndLineAlternate, info.EndColumn + 1), "expectedErrorRange") Assert.AreEqual(expectedErrorMsg, info.Message, "expectedErrorMsg") ) + let TypeCheckSingleError (source: string) (expectedServerity: FSharpErrorSeverity) (expectedErrorNumber: int) (expectedErrorRange: int * int * int * int) (expectedErrorMsg: string) = + TypeCheckWithErrors (source: string) [| expectedServerity, expectedErrorNumber, expectedErrorRange, expectedErrorMsg |] + let CompileExe (source: string) = compile true source (fun (errors, _) -> if errors.Length > 0 then diff --git a/tests/fsharp/Compiler/Language/AnonRecordTests.fs b/tests/fsharp/Compiler/Language/AnonRecordTests.fs index ab65194f220..0a4d1c18d9f 100644 --- a/tests/fsharp/Compiler/Language/AnonRecordTests.fs +++ b/tests/fsharp/Compiler/Language/AnonRecordTests.fs @@ -3,6 +3,7 @@ namespace FSharp.Compiler.UnitTests open NUnit.Framework +open FSharp.Compiler.SourceCodeServices [] module AnonRecordsTests = @@ -30,6 +31,7 @@ let sAnon = StructClass() type RefClass<'a when 'a : not struct>() = class end let rAnon = RefClass() """ + FSharpErrorSeverity.Error 1 (3, 13, 3, 42) "A generic construct requires that the type 'struct {|R : int|}' have reference semantics, but it does not, i.e. it is a struct" @@ -40,7 +42,8 @@ let rAnon = RefClass() """ type StructClass<'a when 'a : struct>() = class end let sAnon = StructClass<{| S: int |}>() - """ + """ + FSharpErrorSeverity.Error 1 (3, 13, 3, 38) "A generic construct requires that the type '{|S : int|}' is a CLI or F# struct type" \ No newline at end of file