From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Zsh workers <zsh-workers@zsh.org>
Subject: PATCH: test output pattern matching
Date: Thu, 1 Dec 2011 21:27:42 +0000 [thread overview]
Message-ID: <20111201212742.365c9e13@pws-pc.ntlworld.com> (raw)
In-Reply-To: <20111201125247.0abdc564@pwslap01u.europe.root.pri>
On Thu, 1 Dec 2011 12:52:47 +0000
Peter Stephenson <Peter.Stephenson@csr.com> 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)$(<errmsg1.txt)}")
- if [[ ${#input} != 1 || \
- $input[1] != "(eval):1: failed to close file descriptor 3:"* ]];
- then
- print "Unexpected error output:\n$input" >&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)$(<errmsg2.txt)}")
- if [[ ${#input} != 1 || \
- $input[1] != "(eval):2: write error:"* ]];
- then
- print "Unexpected error output:\n$input" >&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 <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
next prev parent reply other threads:[~2011-12-01 21:28 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <15488.1322689558@pws-pc.ntlworld.com>
2011-12-01 12:27 ` zsh 4.3.13 released Oliver Kiddle
2011-12-01 12:52 ` Peter Stephenson
2011-12-01 21:27 ` Peter Stephenson [this message]
2011-12-02 17:03 ` PATCH: test output pattern matching ports
2011-12-02 17:23 ` Peter Stephenson
2011-12-03 19:17 ` ports
2011-12-01 23:48 ` zsh 4.3.13 released Baptiste Daroussin
2011-12-02 13:34 ` Peter Stephenson
2011-12-02 23:06 ` Baptiste Daroussin
[not found] ` <20111203191925.GB1294@coredump.raveland.priv>
2011-12-03 19:44 ` Peter Stephenson
2011-12-03 22:19 ` ports
2011-12-03 22:56 ` Peter Stephenson
2011-12-04 12:42 ` ports
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111201212742.365c9e13@pws-pc.ntlworld.com \
--to=p.w.stephenson@ntlworld.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).