This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA/testsuite] Regexp-escape command in capture_command_output


On Thursday, June 11 2015, Keith Seitz wrote:

> On 06/11/2015 01:13 PM, Sergio Durigan Junior wrote:
>>
>> Aha, this is definitely not clear in the function comments.  Would it be
>> possible to explicitly mention this there?
>> 
>
> Sure thing!

Looks good, thanks!

> Keith
>
>
> From 52323e069647b7931ad17c906b5a77980cc8b5e9 Mon Sep 17 00:00:00 2001
> From: Keith Seitz <keiths@redhat.com>
> Date: Thu, 11 Jun 2015 13:15:17 -0700
> Subject: [PATCH] Regexp-escape command in capture_command_output
>
> The test suite library procedure capture_command_output will fail if the
> given command contains any regexp characters, such as "+" or "*". I noticed
> this while writing a test which attempts to call:
>
>    set xyz [capture_command_output "list +,-" ""]
>
> Because COMMAND is not escaped, gdb_test_multiple will generate a false
> FAIL. This simple fix corrects that oversight.
>
> I've also updated the comment to clarify that PREFIX is a regexp.
>
> testsuite/ChangeLog
>
> 	* lib/gdb.exp (capture_command_output): Regexp-escape `command'
> 	before using it in the matching pattern.
> 	Clarify that `prefix' is a regular expression.
> ---
>  gdb/testsuite/lib/gdb.exp | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index 41797e7..2796514 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -5196,12 +5196,15 @@ proc parse_args { argset } {
>      # number of items expected to be passed into the procedure...
>  }
>
> -# Capture the output of COMMAND in a string ignoring PREFIX; return
> that string.
> +# Capture the output of COMMAND in a string ignoring PREFIX (a regexp);
> +# return that string.
> +
>  proc capture_command_output { command prefix } {
>      global gdb_prompt
>      global expect_out
>
>      set output_string ""
> +    set command [string_to_regexp $command]
>      gdb_test_multiple "$command" "capture_command_output for $command" {
>  	-re "${command}\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_prompt $" {
>  	    set output_string $expect_out(1,string)
> -- 
> 2.1.0

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]