From af4e7a1a5ec946d09c6ddb970a4c08a7a18c7f66 Mon Sep 17 00:00:00 2001 From: Florian Verdonck Date: Wed, 31 Jan 2024 15:45:32 +0000 Subject: [PATCH] Filter diagnostics for errors. (#16622) * Filter diagnostics for errors. * Also filter errors in expectOk --- .../ProjectGeneration.fs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/FSharp.Test.Utilities/ProjectGeneration.fs b/tests/FSharp.Test.Utilities/ProjectGeneration.fs index 22dcc12c184..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,9 +890,10 @@ let SaveAndCheckProject project checker isExistingProject = let! snapshot = FSharpProjectSnapshot.FromOptions(options, getFileSnapshot project) let! results = checker.ParseAndCheckProject(snapshot) + let errors = filterErrors results.Diagnostics - if not (Array.isEmpty results.Diagnostics || project.SkipInitialCheck) then - failwith $"Project {project.Name} failed initial check: \n%A{results.Diagnostics}" + if not (Array.isEmpty errors || project.SkipInitialCheck) then + failwith $"Project {project.Name} failed initial check: \n%A{errors}" let! signatures = Async.Sequential