Skip to content

Commit

Permalink
Filter diagnostics for errors. (#16622)
Browse files Browse the repository at this point in the history
* Filter diagnostics for errors.

* Also filter errors in expectOk
  • Loading branch information
nojaf authored Jan 31, 2024
1 parent 33e8be6 commit af4e7a1
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions tests/FSharp.Test.Utilities/ProjectGeneration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit af4e7a1

Please sign in to comment.