From 940ee266ce132a843b38e18ac534b592a868f4c2 Mon Sep 17 00:00:00 2001 From: Patrick Baudin <patrick.baudin@cea.fr> Date: Mon, 24 Jan 2022 17:55:18 +0100 Subject: [PATCH] [ptests] remove false negative alerts about DEPRECATED messages --- ptests/ptests.ml | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/ptests/ptests.ml b/ptests/ptests.ml index d118911f384..2ad28477afb 100644 --- a/ptests/ptests.ml +++ b/ptests/ptests.ml @@ -71,6 +71,20 @@ let str_global_replace regex repl s = let res = Str.global_replace regex repl s in Mutex.unlock str_mutex; res +(* The match may start after [pos] (instead of [str_string_match]) *) +let str_string_contains regexp s pos = + Mutex.lock str_mutex; + let res = try + ignore (Str.search_forward regexp s pos) ; + true + with Not_found -> false + in + Mutex.unlock str_mutex; res + +let str_string_contains_option opt = + let re = Str.regexp ("\\( \\|^\\)"^ opt ^ "\\( \\|=\\|$\\)") in + str_string_contains re + let str_string_match regex s n = Mutex.lock str_mutex; let res = Str.string_match regex s n in @@ -812,14 +826,9 @@ struct let expand_directive = let deprecated_opts = "(-load-module|-load-script)" in - let re = Str.regexp "\\(-load-module\\|-load-script\\)" in + let contains_deprecated_opts = str_string_contains_option "\\(-load-module\\|-load-script\\)" in fun ~file macros s -> - Mutex.lock str_mutex; - let contains = - try ignore (Str.search_forward re s 0); true - with Not_found -> false - in - Mutex.unlock str_mutex; + let contains = contains_deprecated_opts s 0 in if contains then lock_eprintf "%s: DEPRECATED direct use of %s option: %s@.Please use PLUGIN, MODULE, SCRIPT or LIBS directive instead of the deprecated option.@." file deprecated_opts s; expand macros s -- GitLab