From mboxrd@z Thu Jan 1 00:00:00 1970 From: Keith Seitz To: Michael Snyder Cc: Subject: Re: [RFC/A] testsuite/gdb.c++/ref-types.exp "cleanup" Date: Fri, 19 Oct 2001 12:58:00 -0000 Message-id: References: <3BD07EBA.1F02F0E8@cygnus.com> X-SW-Source: 2001-10/msg00267.html On Fri, 19 Oct 2001, Michael Snyder wrote: > > +gdb_test {print s} {.[0-9]* = -1} {print value of s} > > +gdb_test {ptype s} {type = short (int)?} {ptype s} > > I'm just curious why these would not be: > > gdb_test "print s" ".[0-9]* = -1" "print value of s" > gdb_test "ptype s" "type = short (int?)" "ptype s" Aha! I was hoping someone would ask. The difference is that in tcl, strings are evaluated, lists are not. Consider: tclsh> set a 3 3 tclsh> puts "a is $a" a is 3 tclsh> puts {a is $a} a is $a > Seems like the use of quotes in this context is ubiquitous > throughout the rest of the testsuite. Is there any reason > for switching to curly braces here? Is consistancy good? The use of quotes is not incorrect, but when I start thinking about regexps (which, I admit, usually make my head hurt), I like to think [0-9]\(foo\)\*, not \[0-9\]\\\(foo\\\)\\\*. It's just easier to read (for me, I guess). > Also I agree with the suggestion by Fernando to make the pattern > "short( int)?". Already done. My bad. > > +set pattern {.[0-9]* = \(short (int)? &\) @} > > +append pattern "$hex: -1" > > send_gdb "print rs\n" > > gdb_expect { > > - -re ".\[0-9\]* = \\(short &\\) @$hex: -1.*$gdb_prompt $" { > > - pass "print value of rs" > > - } > > - -re ".\[0-9\]* = \\(short int &\\) @$hex: -1.*$gdb_prompt $" { > > - pass "print value of rs" > > - } > > - -re ".*$gdb_prompt $" { fail "print value of rs" } > > - timeout { fail "(timeout) print value of rs" } > > - eof { fail "print rs ($GDB dumped core) (FIXME)" ; gdb_start_again ; } > > - > > + -re $pattern { > > + pass "print value of rs" > > } > > Would it be possible to accomplish the same thing by > combining the two "pass" regexps thusly? > > -re ".\[0-9\]* = \\(short( int)? &\) @$hex: -1.*$gdb_prompt $" { Close (now you see why I like to use {} instead of "" for regular expressions): -re ".\[0-9\]* = \\\(short( int)? &\\\) @$hex: -1.*gdb_prompt $" { When this is passed to expect, tcl will evaluate the special characters. So ".\[0-9\]" will turn into '.[0-9]" (which is the range atom used by regexp) and "\\\(" will become '\(' (which is the literal character '(' to expect), $hex will get substituted (and become another regexp atom to expect), and so on. Like I said, maybe it's just style, but I find the _real_ regular expressions easier to read than all the "\\\(", "\\\[", "\\\$", and such, and there is no ambiguity about how many "\" are needed. It's never more than one (unless you mean literally mean '\', in which case it's "\\"). You could also think of it as {} being more like a C-string, whereas "..." is more like a shell (a la bash) string. Keith