Skip to content

Commit 266baf0

Browse files
authored
Merge pull request #440 from Julow/warning-false-positive
More precise warning detection
2 parents 3226c6e + 8bf25f4 commit 266baf0

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

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

7+
#### Fixed
8+
9+
- Reduce false-positives while detecting warnings (#440, @Julow)
10+
711
### 2.3.1
812

913
#### Added

lib/test/mdx_test.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,11 @@ let rec error_padding = function
203203
let xs = error_padding xs in
204204
x :: xs
205205

206+
let contains_warnings l =
207+
String.is_prefix ~affix:"Warning" l || String.is_infix ~affix:"\nWarning" l
208+
206209
let eval_ocaml ~(block : Block.t) ?syntax ?root c ppf errors =
207210
let cmd = block.contents |> remove_padding in
208-
let contains_warnings = String.is_infix ~affix:"Warning" in
209211
let error_lines =
210212
match eval_test ?root ~block c cmd with
211213
| Ok lines -> List.filter contains_warnings lines

test/bin/mdx-test/expect/warnings/test-case.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,29 @@ Warning 9 [missing-record-field-pattern]: the following labels are not bound in
2929
y
3030
Either bind these labels explicitly or add '; _' to the pattern.
3131
```
32+
33+
Test against some false positives:
34+
35+
```ocaml
36+
let x = [ "Warning" ]
37+
```
38+
39+
```ocaml
40+
module Warning = struct
41+
type t = Warning
42+
end
43+
44+
let warning = Warning.Warning
45+
```
46+
47+
Intended false positive:
48+
49+
```ocaml
50+
let x =
51+
if true then
52+
prerr_endline "Warning: Assert failed";
53+
[ "foo" ]
54+
```
55+
```mdx-error
56+
Warning: Assert failed
57+
```

0 commit comments

Comments
 (0)