Skip to content

Commit

Permalink
Merge pull request #440 from Julow/warning-false-positive
Browse files Browse the repository at this point in the history
More precise warning detection
  • Loading branch information
gpetiot authored Feb 12, 2024
2 parents 3226c6e + 8bf25f4 commit 266baf0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

- Handle the error-blocks syntax (#439, @jonludlam, @gpetiot)

#### Fixed

- Reduce false-positives while detecting warnings (#440, @Julow)

### 2.3.1

#### Added
Expand Down
4 changes: 3 additions & 1 deletion lib/test/mdx_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,11 @@ let rec error_padding = function
let xs = error_padding xs in
x :: xs

let contains_warnings l =
String.is_prefix ~affix:"Warning" l || String.is_infix ~affix:"\nWarning" l

let eval_ocaml ~(block : Block.t) ?syntax ?root c ppf errors =
let cmd = block.contents |> remove_padding in
let contains_warnings = String.is_infix ~affix:"Warning" in
let error_lines =
match eval_test ?root ~block c cmd with
| Ok lines -> List.filter contains_warnings lines
Expand Down
26 changes: 26 additions & 0 deletions test/bin/mdx-test/expect/warnings/test-case.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,29 @@ Warning 9 [missing-record-field-pattern]: the following labels are not bound in
y
Either bind these labels explicitly or add '; _' to the pattern.
```

Test against some false positives:

```ocaml
let x = [ "Warning" ]
```

```ocaml
module Warning = struct
type t = Warning
end
let warning = Warning.Warning
```

Intended false positive:

```ocaml
let x =
if true then
prerr_endline "Warning: Assert failed";
[ "foo" ]
```
```mdx-error
Warning: Assert failed
```

0 comments on commit 266baf0

Please sign in to comment.