From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29419 invoked by alias); 1 Dec 2011 21:28:02 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 29924 Received: (qmail 22623 invoked from network); 1 Dec 2011 21:27:59 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 Received-SPF: neutral (ns1.primenet.com.au: 209.85.215.171 is neither permitted nor denied by SPF record at ntlworld.com) X-ProxyUser-IP: 86.6.29.42 Date: Thu, 1 Dec 2011 21:27:42 +0000 From: Peter Stephenson To: Zsh workers Subject: PATCH: test output pattern matching Message-ID: <20111201212742.365c9e13@pws-pc.ntlworld.com> In-Reply-To: <20111201125247.0abdc564@pwslap01u.europe.root.pri> References: <15488.1322689558@pws-pc.ntlworld.com> <14298.1322742430@thecus.kiddle.eu> <20111201125247.0abdc564@pwslap01u.europe.root.pri> X-Mailer: Claws Mail 3.7.9 (GTK+ 2.24.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 1 Dec 2011 12:52:47 +0000 Peter Stephenson wrote: > We really need a way of telling the test system that it should match > output by pattern, but I've never got round to it. This could probably be used in other places. Index: Test/A04redirect.ztst =================================================================== RCS file: /cvsroot/zsh/zsh/Test/A04redirect.ztst,v retrieving revision 1.21 diff -p -u -r1.21 A04redirect.ztst --- Test/A04redirect.ztst 1 Dec 2011 14:22:56 -0000 1.21 +++ Test/A04redirect.ztst 1 Dec 2011 21:24:02 -0000 @@ -153,31 +153,17 @@ >goodbye (exec 3<&- - read foo <&-) 2>errmsg1.txt - mystat=$? - (( $mystat == 1 )) || print "Unexpected error status $mystat" >&2 - input=("${(f)$(&2 - fi -0:'<&-' redirection + read foo <&-) +1:'<&-' redirection +*?\(eval\):1: failed to close file descriptor 3:* print foo >&- 0:'>&-' redirection (exec >&- - print foo) 2>errmsg2.txt - mystat=$? - (( $mystat == 0 )) || print "Unexpected error status $mystat" >&2 - input=("${(f)$(&2 - fi + print foo) 0:'>&-' with attempt to use closed fd +*?\(eval\):2: write error:* fn() { local foo; read foo; print $foo; } coproc fn Index: Test/B01cd.ztst =================================================================== RCS file: /cvsroot/zsh/zsh/Test/B01cd.ztst,v retrieving revision 1.4 diff -p -u -r1.4 B01cd.ztst --- Test/B01cd.ztst 20 Mar 2009 22:52:56 -0000 1.4 +++ Test/B01cd.ztst 1 Dec 2011 21:24:02 -0000 @@ -57,6 +57,14 @@ # lines are not subject to any substitution unless the `q' flag (see # below) is set. # +# '>' and '?' may be preceded by a '*', in which case all lines +# in the chunk must be so delimited (i.e. all lines must start either +# '*>' or '>' but not a mixture). If the '*' is present, the lines +# in the actual output are pattern matched against the lines in the +# test output. The entire line following '*>' or '*?' must be a +# valid pattern, so characters special to patterns such as parentheses +# must be quoted. The EXTENDED_GLOB option is used for all such patterns. +# # Each chunk of indented code is to be evaluated in one go and is to # be followed by a line starting (in the first column) with # the expected status returned by the code when run, or - if it is Index: Test/ztst.zsh =================================================================== RCS file: /cvsroot/zsh/zsh/Test/ztst.zsh,v retrieving revision 1.29 diff -p -u -r1.29 ztst.zsh --- Test/ztst.zsh 25 Dec 2007 01:40:18 -0000 1.29 +++ Test/ztst.zsh 1 Dec 2011 21:24:02 -0000 @@ -285,12 +285,52 @@ $ZTST_code" && return 0 # diff wrapper ZTST_diff() { - local diff_out diff_ret + emulate -L zsh + setopt extendedglob - diff_out=$(diff "$@") - diff_ret="$?" - if [[ "$diff_ret" != "0" ]]; then - print -r "$diff_out" + local diff_out + integer diff_pat diff_ret + + case $1 in + (p) + diff_pat=1 + ;; + + (d) + ;; + + (*) + print "Bad ZTST_diff code: d for diff, p for pattern match" + ;; + esac + shift + + if (( diff_pat )); then + local -a diff_lines1 diff_lines2 + integer failed i + + diff_lines1=("${(f)$(<$argv[-2])}") + diff_lines2=("${(f)$(<$argv[-1])}") + if (( ${#diff_lines1} != ${#diff_lines2} )); then + failed=1 + else + for (( i = 1; i <= ${#diff_lines1}; i++ )); do + if [[ ${diff_lines2[i]} != ${~diff_lines1[i]} ]]; then + failed=1 + break + fi + done + fi + if (( failed )); then + print -rl "Pattern match failed:" \<${^diff_lines1} \>${^diff_lines2} + diff_ret=1 + fi + else + diff_out=$(diff "$@") + diff_ret="$?" + if [[ "$diff_ret" != "0" ]]; then + print -r "$diff_out" + fi fi return "$diff_ret" @@ -298,6 +338,7 @@ ZTST_diff() { ZTST_test() { local last match mbegin mend found substlines + local diff_out diff_err while true; do rm -f $ZTST_in $ZTST_out $ZTST_err @@ -305,6 +346,8 @@ ZTST_test() { ZTST_message='' ZTST_failmsg='' found=0 + diff_out=d + diff_err=d ZTST_verbose 2 "ZTST_test: looking for new test" @@ -343,10 +386,20 @@ $ZTST_curline" ('<'*) ZTST_getredir || return 1 found=1 ;; - ('>'*) ZTST_getredir || return 1 + ('*>'*) + ZTST_curline=${ZTST_curline[2,-1]} + diff_out=p + ;& + ('>'*) + ZTST_getredir || return 1 found=1 ;; - ('?'*) ZTST_getredir || return 1 + ('*?'*) + ZTST_curline=${ZTST_curline[2,-1]} + diff_err=p + ;& + ('?'*) + ZTST_getredir || return 1 found=1 ;; ('F:'*) ZTST_failmsg="${ZTST_failmsg:+${ZTST_failmsg} @@ -390,7 +443,7 @@ $(<$ZTST_terr)" rm -rf $ZTST_out print -r -- "${(e)substlines}" >$ZTST_out fi - if [[ $ZTST_flags != *d* ]] && ! ZTST_diff -c $ZTST_out $ZTST_tout; then + if [[ $ZTST_flags != *d* ]] && ! ZTST_diff $diff_out -c $ZTST_out $ZTST_tout; then ZTST_testfailed "output differs from expected as shown above for: $ZTST_code${$(<$ZTST_terr):+ Error output: @@ -402,7 +455,7 @@ $(<$ZTST_terr)}" rm -rf $ZTST_err print -r -- "${(e)substlines}" >$ZTST_err fi - if [[ $ZTST_flags != *D* ]] && ! ZTST_diff -c $ZTST_err $ZTST_terr; then + if [[ $ZTST_flags != *D* ]] && ! ZTST_diff $diff_err -c $ZTST_err $ZTST_terr; then ZTST_testfailed "error output differs from expected as shown above for: $ZTST_code" return 1 -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/