From 2b967c6bc02139a6f37d42fe1561327eb855674f Mon Sep 17 00:00:00 2001 From: nojaf Date: Wed, 31 Jan 2024 12:06:15 +0100 Subject: [PATCH 1/2] Filter diagnostics for errors. --- tests/FSharp.Test.Utilities/ProjectGeneration.fs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/FSharp.Test.Utilities/ProjectGeneration.fs b/tests/FSharp.Test.Utilities/ProjectGeneration.fs index 22dcc12c184..fd6e09dfcf8 100644 --- a/tests/FSharp.Test.Utilities/ProjectGeneration.fs +++ b/tests/FSharp.Test.Utilities/ProjectGeneration.fs @@ -880,9 +880,17 @@ let SaveAndCheckProject project checker isExistingProject = let! snapshot = FSharpProjectSnapshot.FromOptions(options, getFileSnapshot project) let! results = checker.ParseAndCheckProject(snapshot) - - if not (Array.isEmpty results.Diagnostics || project.SkipInitialCheck) then - failwith $"Project {project.Name} failed initial check: \n%A{results.Diagnostics}" + let errors = + results.Diagnostics + |> Array.filter (fun diag -> + match diag.Severity with + | FSharpDiagnosticSeverity.Hidden + | FSharpDiagnosticSeverity.Info + | FSharpDiagnosticSeverity.Warning -> false + | FSharpDiagnosticSeverity.Error -> true) + + if not (Array.isEmpty errors || project.SkipInitialCheck) then + failwith $"Project {project.Name} failed initial check: \n%A{errors}" let! signatures = Async.Sequential From 095175b0b336f7086f79f1a40e5e454add252247 Mon Sep 17 00:00:00 2001 From: nojaf Date: Wed, 31 Jan 2024 12:12:51 +0100 Subject: [PATCH 2/2] Also filter errors in expectOk --- .../ProjectGeneration.fs | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/tests/FSharp.Test.Utilities/ProjectGeneration.fs b/tests/FSharp.Test.Utilities/ProjectGeneration.fs index fd6e09dfcf8..144e535bccb 100644 --- a/tests/FSharp.Test.Utilities/ProjectGeneration.fs +++ b/tests/FSharp.Test.Utilities/ProjectGeneration.fs @@ -678,11 +678,21 @@ module ProjectOperations = |> Option.map (fun s -> s.ToString()) |> Option.defaultValue "" + let filterErrors (diagnostics: FSharpDiagnostic array) = + diagnostics + |> Array.filter (fun diag -> + match diag.Severity with + | FSharpDiagnosticSeverity.Hidden + | FSharpDiagnosticSeverity.Info + | FSharpDiagnosticSeverity.Warning -> false + | FSharpDiagnosticSeverity.Error -> true) + let expectOk parseAndCheckResults _ = let checkResult = getTypeCheckResult parseAndCheckResults + let errors = filterErrors checkResult.Diagnostics - if checkResult.Diagnostics.Length > 0 then - failwith $"Expected no errors, but there were some: \n%A{checkResult.Diagnostics}" + if errors.Length > 0 then + failwith $"Expected no errors, but there were some: \n%A{errors}" let expectSingleWarningAndNoErrors (warningSubString:string) parseAndCheckResults _ = let checkResult = getTypeCheckResult parseAndCheckResults @@ -880,14 +890,7 @@ let SaveAndCheckProject project checker isExistingProject = let! snapshot = FSharpProjectSnapshot.FromOptions(options, getFileSnapshot project) let! results = checker.ParseAndCheckProject(snapshot) - let errors = - results.Diagnostics - |> Array.filter (fun diag -> - match diag.Severity with - | FSharpDiagnosticSeverity.Hidden - | FSharpDiagnosticSeverity.Info - | FSharpDiagnosticSeverity.Warning -> false - | FSharpDiagnosticSeverity.Error -> true) + let errors = filterErrors results.Diagnostics if not (Array.isEmpty errors || project.SkipInitialCheck) then failwith $"Project {project.Name} failed initial check: \n%A{errors}"