[1/2] testsuite: Provide means to regexp in multiline patterns

Message ID 20230224191603.3935F20447@pchp3.se.axis.com
State Committed
Commit 82318c57607ca983742630c9884e5d30920a3ce1
Headers
Series [1/2] testsuite: Provide means to regexp in multiline patterns |

Commit Message

Hans-Peter Nilsson Feb. 24, 2023, 7:16 p.m. UTC
  Ok to commit?
-- >8 --
Those multi-line-patterns are literal.  Sometimes a regexp
needs to be matched.  This is a start: just three elements
are supported: "(" ")" and the compound ")?" (and on second
thought, it can be argued that "(...)" alone is not useful).
Note that Tcl "string map" is documented to have the desired
effect: a once-over but no re-recognitions of previously
replaced mapped elements.  Also, drop a doubled "containing".

testsuite:
	* lib/multiline.exp (_build_multiline_regex): Map
	"{re:" to "(", ":re}" to ")" and ":re?}" to ")?".
---
 gcc/testsuite/lib/multiline.exp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
  

Comments

Hans-Peter Nilsson March 4, 2023, 1:58 a.m. UTC | #1
Ping...

> From: Hans-Peter Nilsson <hp@axis.com>
> Date: Fri, 24 Feb 2023 20:16:03 +0100
> 
> Ok to commit?
> -- >8 --
> Those multi-line-patterns are literal.  Sometimes a regexp
> needs to be matched.  This is a start: just three elements
> are supported: "(" ")" and the compound ")?" (and on second
> thought, it can be argued that "(...)" alone is not useful).
> Note that Tcl "string map" is documented to have the desired
> effect: a once-over but no re-recognitions of previously
> replaced mapped elements.  Also, drop a doubled "containing".
> 
> testsuite:
> 	* lib/multiline.exp (_build_multiline_regex): Map
> 	"{re:" to "(", ":re}" to ")" and ":re?}" to ")?".
> ---
>  gcc/testsuite/lib/multiline.exp | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/gcc/testsuite/lib/multiline.exp b/gcc/testsuite/lib/multiline.exp
> index 5eccf2bbebc1..f746bc3a618e 100644
> --- a/gcc/testsuite/lib/multiline.exp
> +++ b/gcc/testsuite/lib/multiline.exp
> @@ -297,7 +297,7 @@ proc _get_lines { filename first_line last_line } {
>  
>  # Convert $multiline from a list of strings to a multiline regex
>  # We need to support matching arbitrary followup text on each line,
> -# to deal with comments containing containing DejaGnu directives.
> +# to deal with comments containing DejaGnu directives.
>  
>  proc _build_multiline_regex { multiline index } {
>      verbose "_build_multiline_regex: $multiline $index" 4
> @@ -307,7 +307,10 @@ proc _build_multiline_regex { multiline index } {
>  	verbose "  line: $line" 4
>  
>  	# We need to escape "^" and other regexp metacharacters.
> -	set line [string map {"^" "\\^"
> +	set line [string map {"\{re:" "("
> +	                      ":re?\}" ")?"
> +	                      ":re\}" ")"
> +	                      "^" "\\^"
>  	                      "(" "\\("
>  	                      ")" "\\)"
>  	                      "[" "\\["
> -- 
> 2.30.2
>
  
Mike Stump March 6, 2023, 10:05 a.m. UTC | #2
Ok

On Mar 3, 2023, at 5:58 PM, Hans-Peter Nilsson <hp@axis.com> wrote:
> 
> Ping...
> 
>> From: Hans-Peter Nilsson <hp@axis.com>
>> Date: Fri, 24 Feb 2023 20:16:03 +0100
>> 
>> Ok to commit?
  
Hans-Peter Nilsson March 7, 2023, 12:32 a.m. UTC | #3
> From: Mike Stump <mikestump@comcast.net>
> Date: Mon, 6 Mar 2023 02:05:35 -0800

> Ok

Thanks!  The server-side hook didn't like my ChangeLog
entry:

            * lib/multiline.exp (_build_multiline_regex): Map
            "{re:" to "(", ":re}" to ")" and ":re?}" to ")?".

It seems I forgot to validate that patch by
contrib/gcc-changelog/git_check_commit.py, which complains:

Checking c0debd6f586ef76f1ceabfed11d7eaf8f6d1b110: FAILED
ERR: bad wrapping of parenthesis: "	"{re:" to "(", ":re}" to ")" and ":re?}" to ")?"."

I gave in and took the easy way out; not fixing the bug in
that script, but instead "wrapped the parenthesis" to:

	* lib/multiline.exp (_build_multiline_regex): Map
	"{re:" to "(", similarly ")?" from ":re?}" and the
	same without question mark.

I hope to make amends by fixing git_check_commit.py, if
given guidance.

brgds, H-P
  
Martin Liška March 7, 2023, 2:34 p.m. UTC | #4
On 3/7/23 01:32, Hans-Peter Nilsson wrote:
>> From: Mike Stump <mikestump@comcast.net>
>> Date: Mon, 6 Mar 2023 02:05:35 -0800
> 
>> Ok
> 
> Thanks!  The server-side hook didn't like my ChangeLog
> entry:
> 
>             * lib/multiline.exp (_build_multiline_regex): Map
>             "{re:" to "(", ":re}" to ")" and ":re?}" to ")?".
> 
> It seems I forgot to validate that patch by
> contrib/gcc-changelog/git_check_commit.py, which complains:
> 
> Checking c0debd6f586ef76f1ceabfed11d7eaf8f6d1b110: FAILED
> ERR: bad wrapping of parenthesis: "	"{re:" to "(", ":re}" to ")" and ":re?}" to ")?"."

Hello.

Yeah, that's quite interesting problem ;)


> 
> I gave in and took the easy way out; not fixing the bug in
> that script, but instead "wrapped the parenthesis" to:
> 
> 	* lib/multiline.exp (_build_multiline_regex): Map
> 	"{re:" to "(", similarly ")?" from ":re?}" and the
> 	same without question mark.
> 
> I hope to make amends by fixing git_check_commit.py, if
> given guidance.

Sure, you can take a look at:
contrib/gcc-changelog/git_commit.py::process_parentheses
where we might want to skip the stack push/pop if the character is wrapper
in apostrophes or double quotes.

Martin

> 
> brgds, H-P
  

Patch

diff --git a/gcc/testsuite/lib/multiline.exp b/gcc/testsuite/lib/multiline.exp
index 5eccf2bbebc1..f746bc3a618e 100644
--- a/gcc/testsuite/lib/multiline.exp
+++ b/gcc/testsuite/lib/multiline.exp
@@ -297,7 +297,7 @@  proc _get_lines { filename first_line last_line } {
 
 # Convert $multiline from a list of strings to a multiline regex
 # We need to support matching arbitrary followup text on each line,
-# to deal with comments containing containing DejaGnu directives.
+# to deal with comments containing DejaGnu directives.
 
 proc _build_multiline_regex { multiline index } {
     verbose "_build_multiline_regex: $multiline $index" 4
@@ -307,7 +307,10 @@  proc _build_multiline_regex { multiline index } {
 	verbose "  line: $line" 4
 
 	# We need to escape "^" and other regexp metacharacters.
-	set line [string map {"^" "\\^"
+	set line [string map {"\{re:" "("
+	                      ":re?\}" ")?"
+	                      ":re\}" ")"
+	                      "^" "\\^"
 	                      "(" "\\("
 	                      ")" "\\)"
 	                      "[" "\\["