Skip to content

Commit af4e7a1

Browse files
authored
Filter diagnostics for errors. (#16622)
* Filter diagnostics for errors. * Also filter errors in expectOk
1 parent 33e8be6 commit af4e7a1

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

tests/FSharp.Test.Utilities/ProjectGeneration.fs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -678,11 +678,21 @@ module ProjectOperations =
678678
|> Option.map (fun s -> s.ToString())
679679
|> Option.defaultValue ""
680680

681+
let filterErrors (diagnostics: FSharpDiagnostic array) =
682+
diagnostics
683+
|> Array.filter (fun diag ->
684+
match diag.Severity with
685+
| FSharpDiagnosticSeverity.Hidden
686+
| FSharpDiagnosticSeverity.Info
687+
| FSharpDiagnosticSeverity.Warning -> false
688+
| FSharpDiagnosticSeverity.Error -> true)
689+
681690
let expectOk parseAndCheckResults _ =
682691
let checkResult = getTypeCheckResult parseAndCheckResults
692+
let errors = filterErrors checkResult.Diagnostics
683693

684-
if checkResult.Diagnostics.Length > 0 then
685-
failwith $"Expected no errors, but there were some: \n%A{checkResult.Diagnostics}"
694+
if errors.Length > 0 then
695+
failwith $"Expected no errors, but there were some: \n%A{errors}"
686696

687697
let expectSingleWarningAndNoErrors (warningSubString:string) parseAndCheckResults _ =
688698
let checkResult = getTypeCheckResult parseAndCheckResults
@@ -880,9 +890,10 @@ let SaveAndCheckProject project checker isExistingProject =
880890
let! snapshot = FSharpProjectSnapshot.FromOptions(options, getFileSnapshot project)
881891

882892
let! results = checker.ParseAndCheckProject(snapshot)
893+
let errors = filterErrors results.Diagnostics
883894

884-
if not (Array.isEmpty results.Diagnostics || project.SkipInitialCheck) then
885-
failwith $"Project {project.Name} failed initial check: \n%A{results.Diagnostics}"
895+
if not (Array.isEmpty errors || project.SkipInitialCheck) then
896+
failwith $"Project {project.Name} failed initial check: \n%A{errors}"
886897

887898
let! signatures =
888899
Async.Sequential

0 commit comments

Comments
 (0)