about summary refs log tree commit diff
path: root/Test
diff options
context:
space:
mode:
Diffstat (limited to 'Test')
-rw-r--r--Test/A04redirect.ztst36
-rwxr-xr-xTest/ztst.zsh47
2 files changed, 52 insertions, 31 deletions
diff --git a/Test/A04redirect.ztst b/Test/A04redirect.ztst
index 104ed433e..2813d0e28 100644
--- a/Test/A04redirect.ztst
+++ b/Test/A04redirect.ztst
@@ -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
 
diff --git a/Test/ztst.zsh b/Test/ztst.zsh
index c0fbc179f..348ec4a7f 100755
--- a/Test/ztst.zsh
+++ b/Test/ztst.zsh
@@ -227,24 +227,25 @@ ${ZTST_curline[2,-1]}"
   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_diff() {
 }
     
 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_test: and standard error:
 $(<$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 @@ Error output:
 $(<$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"