mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-06-01 04:46:08 +02:00
29924: add ability to match test output using patterns
This commit is contained in:
parent
d6d0297b10
commit
ae8e3ba86d
|
@ -1,3 +1,8 @@
|
|||
2011-12-01 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
||||
|
||||
* 29924: Test/A04redirect.ztst, Test/B01cd.ztst, Test/ztst.zsh:
|
||||
add ability to match output of tests using patterns.
|
||||
|
||||
2011-12-01 Peter Stephenson <pws@csr.com>
|
||||
|
||||
* unposted: Completion/Unix/Command/_nm: also complete
|
||||
|
@ -15635,5 +15640,5 @@
|
|||
|
||||
*****************************************************
|
||||
* This is used by the shell to define $ZSH_PATCHLEVEL
|
||||
* $Revision: 1.5511 $
|
||||
* $Revision: 1.5512 $
|
||||
*****************************************************
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue