Skip to content

Commit

Permalink
More precise warning detection
Browse files Browse the repository at this point in the history
Reduce false-positive while detecting warnings by searching for the word
"Warning" at the beginning of a line only.
  • Loading branch information
Julow committed Oct 31, 2023
1 parent c69241f commit d906c67
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
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
7 changes: 0 additions & 7 deletions test/bin/mdx-test/expect/warnings/test-case.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ Test against some false positives:
```ocaml
let x = [ "Warning" ]
```
```mdx-error
val x : string list = ["Warning"]
```

```ocaml
module Warning = struct
Expand All @@ -46,10 +43,6 @@ end
let warning = Warning.Warning
```
```mdx-error
module Warning : sig type t = Warning end
val warning : Warning.t = Warning.Warning
```

Intended false positive:

Expand Down

0 comments on commit d906c67

Please sign in to comment.