Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Test issues
- X-seq: zsh-workers 22550
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-workers@xxxxxxxxxx (Zsh hackers list)
- Subject: Re: Test issues
- Date: Wed, 12 Jul 2006 12:48:58 +0100
- In-reply-to: <060711092333.ZM17490@xxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20a807210607110749q205d2d07n5b6957098a3ca5a1@xxxxxxxxxxxxxx> <200607111530.k6BFU0mG023293@xxxxxxxxxxxxxx> <060711092333.ZM17490@xxxxxxxxxxxxxxxxxxxxxx>
This puts tests for exec's inside subshells.
It also changes the test harness so that substitutions on variables
in output are performed after the test has run, making them rather
more useful.
That relies on the last byte of the output or error for each test being
a newline. That happens to be true, but I wondered if there was any way
around the fact that even "$(<file)" strips the last newline and doesn't
give a way of finding out if there was one there (except for examining
the file itself).
Index: Test/A04redirect.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/A04redirect.ztst,v
retrieving revision 1.11
diff -u -r1.11 A04redirect.ztst
--- Test/A04redirect.ztst 11 Jul 2006 15:36:37 -0000 1.11
+++ Test/A04redirect.ztst 12 Jul 2006 11:45:35 -0000
@@ -82,18 +82,22 @@
>b
>c
- exec 3>redir && print hello >&3 && print goodbye >&3 && cat redir
+ #
+ # exec tests: perform these in subshells so if they fail the
+ # shell won't exit.
+ #
+ (exec 3>redir && print hello >&3 && print goodbye >&3 && cat redir)
0:'>&' redirection
>hello
>goodbye
- exec 3<redir && read foo <&3 && print $foo && read foo <&3 && print $foo
+ (exec 3<redir && read foo <&3 && print $foo && read foo <&3 && print $foo)
0:'<&' redirection
>hello
>goodbye
- exec 3<&-
- read foo <&-
+ (exec 3<&-
+ read foo <&-)
1:'<&-' redirection
print foo >&-
@@ -240,7 +244,7 @@
<input
>input
- myfd=
+ (myfd=
exec {myfd}>logfile
if [[ -z $myfd ]]; then
print "Ooops, failed to set myfd to a file descriptor." >&2
@@ -248,30 +252,36 @@
print This is my logfile. >&$myfd
print Examining contents of logfile...
cat logfile
- fi
+ fi)
0:Using {fdvar}> syntax to open a new file descriptor
>Examining contents of logfile...
>This is my logfile.
- setopt noclobber
- exec {myfd}>logfile2
+ (setopt noclobber
+ exec {myfd}>logfile2
+ echo $myfd
+ exec {myfd}>logfile3) | read myfd
+ (( ! ${pipestatus[1]} ))
1q:NO_CLOBBER prevents overwriting parameter with allocated fd
-?(eval):2: can't clobber parameter myfd containing file descriptor $myfd
+?(eval):4: can't clobber parameter myfd containing file descriptor $myfd
+ (exec {myfd}>logfile4
+ echo $myfd
exec {myfd}>&-
- print This message should disappear >&$myfd
+ print This message should disappear >&$myfd) | read myfd
+ (( ! ${pipestatus[1]} ))
1q:Closing file descriptor using brace syntax
-?(eval):2: $myfd:$bad_fd_msg
+?(eval):4: $myfd:$bad_fd_msg
typeset -r myfd
echo This should not appear {myfd}>nologfile
1:Error opening file descriptor using readonly variable
?(eval):2: can't allocate file descriptor to readonly parameter myfd
- typeset +r myfd
+ (typeset +r myfd
exec {myfd}>newlogfile
typeset -r myfd
- exec {myfd}>&-
+ exec {myfd}>&-)
1:Error closing file descriptor using readonly variable
?(eval):4: can't close file descriptor from readonly parameter myfd
Index: Test/ztst.zsh
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/ztst.zsh,v
retrieving revision 1.23
diff -u -r1.23 ztst.zsh
--- Test/ztst.zsh 11 Oct 2005 16:48:06 -0000 1.23
+++ Test/ztst.zsh 12 Jul 2006 11:45:35 -0000
@@ -227,24 +227,25 @@
ZTST_verbose 2 "ZTST_getredir: read redir for '$char':
$ZTST_redir"
-case $char in
- ('<') fn=$ZTST_in
- ;;
- ('>') fn=$ZTST_out
- ;;
- ('?') fn=$ZTST_err
- ;;
- (*) ZTST_testfailed "bad redir operator: $char"
- return 1
- ;;
-esac
-if [[ $ZTST_flags = *q* ]]; then
- print -r -- "${(e)ZTST_redir}" >>$fn
-else
- print -r -- "$ZTST_redir" >>$fn
-fi
+ case $char in
+ ('<') fn=$ZTST_in
+ ;;
+ ('>') fn=$ZTST_out
+ ;;
+ ('?') fn=$ZTST_err
+ ;;
+ (*) ZTST_testfailed "bad redir operator: $char"
+ return 1
+ ;;
+ esac
+ if [[ $ZTST_flags = *q* && $char = '<' ]]; then
+ # delay substituting output until variables are set
+ print -r -- "${(e)ZTST_redir}" >>$fn
+ else
+ print -r -- "$ZTST_redir" >>$fn
+ fi
-return 0
+ return 0
}
# Execute an indented chunk. Redirections will already have
@@ -287,7 +288,7 @@
}
ZTST_test() {
- local last match mbegin mend found
+ local last match mbegin mend found substlines
while true; do
rm -f $ZTST_in $ZTST_out $ZTST_err
@@ -375,6 +376,11 @@
$(<$ZTST_terr)"
# Now check output and error.
+ if [[ $ZTST_flags = *q* && -s $ZTST_out ]]; then
+ substlines="$(<$ZTST_out)"
+ rm -rf $ZTST_out
+ print -r -- "${(e)substlines}" >$ZTST_out
+ fi
if [[ $ZTST_flags != *d* ]] && ! ZTST_diff -c $ZTST_out $ZTST_tout; then
ZTST_testfailed "output differs from expected as shown above for:
$ZTST_code${$(<$ZTST_terr):+
@@ -382,6 +388,11 @@
$(<$ZTST_terr)}"
return 1
fi
+ if [[ $ZTST_flags = *q* && -s $ZTST_err ]]; then
+ substlines="$(<$ZTST_err)"
+ rm -rf $ZTST_err
+ print -r -- "${(e)substlines}" >$ZTST_err
+ fi
if [[ $ZTST_flags != *D* ]] && ! ZTST_diff -c $ZTST_err $ZTST_terr; then
ZTST_testfailed "error output differs from expected as shown above for:
$ZTST_code"
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php
Messages sorted by:
Reverse Date,
Date,
Thread,
Author