Skip to content

Commit

Permalink
Use 1-based column numbers in tests (#7141)
Browse files Browse the repository at this point in the history
* Use 1-based column numbers in tests

* Helper that can check for multiple type errors
  • Loading branch information
forki authored and KevinRansom committed Jul 11, 2019
1 parent 0c9ccae commit 598db3e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
18 changes: 12 additions & 6 deletions tests/fsharp/Compiler/CompilerAssert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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, 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")
)

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
Expand Down
9 changes: 6 additions & 3 deletions tests/fsharp/Compiler/Language/AnonRecordTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace FSharp.Compiler.UnitTests

open NUnit.Framework
open FSharp.Compiler.SourceCodeServices

[<TestFixture>]
module AnonRecordsTests =
Expand Down Expand Up @@ -30,8 +31,9 @@ let sAnon = StructClass<struct {| S: int |}>()
type RefClass<'a when 'a : not struct>() = class end
let rAnon = RefClass<struct {| R: int |}>()
"""
FSharpErrorSeverity.Error
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"

[<Test>]
Expand All @@ -40,7 +42,8 @@ let rAnon = RefClass<struct {| R: int |}>()
"""
type StructClass<'a when 'a : struct>() = class end
let sAnon = StructClass<{| S: int |}>()
"""
"""
FSharpErrorSeverity.Error
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"

0 comments on commit 598db3e

Please sign in to comment.