From 63a318ae0aea851fee7bf37f2e35c491c3c12eac Mon Sep 17 00:00:00 2001
From: Virgile Prevosto <virgile.prevosto@m4x.org>
Date: Wed, 12 Jul 2023 09:57:05 +0200
Subject: [PATCH] [ptests] fix warning msg generated for complex enabled_if
 conditions

Far from perfect, but at least we now generate a correct dune file in such case.
---
 tools/ptests/ptests.ml | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tools/ptests/ptests.ml b/tools/ptests/ptests.ml
index 6c843295890..afe8a2c8e94 100644
--- a/tools/ptests/ptests.ml
+++ b/tools/ptests/ptests.ml
@@ -1977,11 +1977,15 @@ let warn_if_not_enabled =
   let dune_cond_regexp = Str.regexp "^(\\(.*\\))" in
   let doublequote_regexp = Str.regexp "\"" in
   let dune_var_regexp = Str.regexp "%{" in
+  let paren_regexp = Str.regexp "[()]" in
   let dune_cond_item s = Str.global_replace dune_cond_regexp "\\1" s in
   let escaped_cond s =
     let s = Str.global_replace dune_var_regexp "\\%{" s in
     Str.global_replace doublequote_regexp "\\\"" s
   in
+  let safe_cond s =
+    Str.global_replace paren_regexp "\"\\0\"" s
+  in
   fun ~env ~suite fmt enabled_if ->
     if not (StringSet.is_empty enabled_if) then begin
       Format.fprintf fmt
@@ -2000,7 +2004,7 @@ let warn_if_not_enabled =
       let pp_enabled  fmt cond =
         let cond = dune_cond_item cond in
         Format.fprintf fmt "              (echo \"- %s: \" %s \"\\n\")\n  "
-          (escaped_cond cond) cond
+          (escaped_cond cond) (safe_cond cond)
       in
       let conds = StringSet.elements enabled_if in
       Format.fprintf fmt
-- 
GitLab