From d906c679a5dd066b35a3809ac23fed66f12a2f32 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Tue, 31 Oct 2023 13:04:45 +0100 Subject: [PATCH] More precise warning detection Reduce false-positive while detecting warnings by searching for the word "Warning" at the beginning of a line only. --- lib/test/mdx_test.ml | 4 +++- test/bin/mdx-test/expect/warnings/test-case.md | 7 ------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/test/mdx_test.ml b/lib/test/mdx_test.ml index 08c5f6b01..bbed0cd32 100644 --- a/lib/test/mdx_test.ml +++ b/lib/test/mdx_test.ml @@ -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 diff --git a/test/bin/mdx-test/expect/warnings/test-case.md b/test/bin/mdx-test/expect/warnings/test-case.md index ac23368d0..60b1857dc 100644 --- a/test/bin/mdx-test/expect/warnings/test-case.md +++ b/test/bin/mdx-test/expect/warnings/test-case.md @@ -35,9 +35,6 @@ Test against some false positives: ```ocaml let x = [ "Warning" ] ``` -```mdx-error -val x : string list = ["Warning"] -``` ```ocaml module Warning = struct @@ -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: