Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] Add support for a %attr section and the mutetty attribute



And here is the patch that I forgot to attach.

Philippe


diff --git a/.gitignore b/.gitignore
index b8922ef6f..f636f4d0c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -154,5 +154,8 @@ Src/Zle/zle_things.h
 Src/Zle/zle_widget.h
 
 Test/*.tmp
+Test/*-status.txt
+Test/*-tty.log
+
 /.project
 .DS_Store
diff --git a/Test/B01cd.ztst b/Test/B01cd.ztst
index a1f614b40..8641f5027 100644
--- a/Test/B01cd.ztst
+++ b/Test/B01cd.ztst
@@ -9,9 +9,10 @@
 
 # All section names start with a % in the first column.  The names
 # must be in the expected order, though not all sections are required.
-# The sections are %prep (preparatory setup:  code executed should return
-# status 0, but no other tests are performed), %test (the main tests), and
-# %clean (to cleanup: the code is simply unconditionally executed).
+# The sections are %attr (to specify test attributes), %prep
+# (preparatory setup: code executed should return status 0, but no
+# other tests are performed), %test (the main tests), and %clean (to
+# cleanup: the code is simply unconditionally executed).
 #
 # Literal shell code to be evaluated must be indented with any number
 # of spaces and/or tabs, to differentiate it from tags with a special
@@ -22,6 +23,15 @@
 # execution of different code chunks; initially, all standard zsh options
 # (the effect of `emulate -R zsh') are set.
 
+%attr
+# This optional section lists test attributes (on the section line).
+# The section may otherwise only contain comments, no code.  There is
+# currently only one supported attribute:
+#
+# - mutetty: directs the test harness to capture any output written
+#   directly to the terminal. The captured output is saved in the file
+#   ${testfile%.ztst}-tty.log.
+
 %prep
 # This optional section prepares the test, creating directories and files
 # and so on.  Chunks of code are separated by blank lines (which is not
diff --git a/Test/Makefile.in b/Test/Makefile.in
index 09f37bf53..327a8bb58 100644
--- a/Test/Makefile.in
+++ b/Test/Makefile.in
@@ -68,7 +68,7 @@ check test:
 @CLEAN_MK@
 
 mostlyclean-here:
-	rm -rf Modules .zcompdump *.tmp
+	rm -rf Modules .zcompdump *.tmp *-status.txt *-tty.log
 
 distclean-here:
 	rm -f Makefile
diff --git a/Test/W01history.ztst b/Test/W01history.ztst
index 5794f79ac..fcb233bb9 100644
--- a/Test/W01history.ztst
+++ b/Test/W01history.ztst
@@ -1,5 +1,7 @@
 # Tests for BANG_HIST replacements
 
+%attr mutetty
+
 %prep
 
   if [[ -t 0 ]]; then print -u $ZTST_fd History tests write to /dev/tty; fi
diff --git a/Test/runtests.zsh b/Test/runtests.zsh
index 7dbe89214..475f0cdc4 100644
--- a/Test/runtests.zsh
+++ b/Test/runtests.zsh
@@ -21,9 +21,28 @@ else
   unset -m "ZTST_*color"
 fi
 
+# Set the module load path to correspond to this build of zsh.
+# This Modules directory should have been created by "make check".
+module_path=( $0:a:h:h/Test/Modules )
+
 run-test() {
-  $ZTST_exe +Z -f $ZTST_srcdir/ztst.zsh $test
-  local -i result=$?
+  local attrs=(${(s: :)${${(M)${(f)"$(<$test)"}:#%attr*}#%attr}})
+  local testcmd=($ZTST_exe +Z -f $ZTST_srcdir/ztst.zsh $test)
+  if [[ -n ${(M)attrs:#mutetty} ]] && zmodload -s zsh/zpty; then
+    local -i fd1 fd2 && exec {fd1}>&1 {fd2}>&2
+    zpty zsh "
+        exec 1>&$fd1 2>&$fd2
+        ${(@q)testcmd}
+        echo \$? >${test%.ztst}-status.txt
+    "
+    zpty -r zsh >${test%.ztst}-tty.log
+    zpty -d zsh
+    local -i result=$(<${test%.ztst}-status.txt)
+    exec {fd1}>&- {fd2}>&-
+  else
+    $testcmd
+    local -i result=$?
+  fi
   (( result > 128 )) && {
     [[ -n $ZTST_failcolor ]] && print -rnP "%F{$ZTST_failcolor}"
     print -r - "$test: test failed: SIG$signals[result - 127]."
diff --git a/Test/ztst.zsh b/Test/ztst.zsh
index 89d5c5917..4dad10225 100755
--- a/Test/ztst.zsh
+++ b/Test/ztst.zsh
@@ -305,6 +305,14 @@ $ZTST_code"
   return 0
 }
 
+ZTST_attr() {
+  if ZTST_getchunk; then
+    ZTST_testfailed "code not allowed in \`attr' section, found:
+$ZTST_code"
+    return 1
+  fi
+}
+
 # diff wrapper
 ZTST_diff() {
   emulate -L zsh
@@ -577,7 +585,7 @@ $ZTST_code"
 
 # Remember which sections we've done.
 typeset -A ZTST_sects
-ZTST_sects=(prep 0 test 0 clean 0)
+ZTST_sects=(attr 0 prep 0 test 0 clean 0)
 
 print "$ZTST_testname: starting."
 
@@ -587,39 +595,49 @@ print "$ZTST_testname: starting."
 ZTST_skipok=
 ZTST_unimplemented=
 while [[ -z "$ZTST_unimplemented" ]] && ZTST_getsect $ZTST_skipok; do
+  if (( ${ZTST_sects[$ZTST_cursect]} )); then
+    ZTST_testfailed "duplicate \`$ZTST_cursect' section not allowed"
+    break
+  fi
   case $ZTST_cursect in
-    (prep) if (( ${ZTST_sects[prep]} + ${ZTST_sects[test]} + \
-	        ${ZTST_sects[clean]} )); then
-	    ZTST_testfailed "\`prep' section must come first"
-	    break   # skip %test and %clean sections, but run ZTST_cleanup
-	  fi
-	  ZTST_prep || ZTST_skipok=1
-	  ZTST_sects[prep]=1
-	  ;;
+    (attr)
+      if (( ${ZTST_sects[prep]} + ${ZTST_sects[test]} )); then
+	ZTST_testfailed "\`attr' section must come first"
+	break
+      fi
+      ZTST_attr || break
+      ZTST_sects[attr]=1
+      ;;
+    (prep)
+      if (( ${ZTST_sects[test]} )); then
+	ZTST_testfailed "\`prep' section must come before \`test' section"
+	break
+      fi
+      ZTST_prep || ZTST_skipok=1
+      ZTST_sects[prep]=1
+      ;;
     (test)
-	  if (( ${ZTST_sects[test]} + ${ZTST_sects[clean]} )); then
-	    ZTST_testfailed "bad placement of \`test' section"
-	    break   # skip %clean section, but run ZTST_cleanup
-	  fi
-          if [[ -z "$ZTST_skipok" ]]; then  # if no error in %prep
-            # careful here: we can't execute ZTST_test before || or &&
-            # because that affects the behaviour of traps in the tests.
-            ZTST_test
-            (( $? )) && ZTST_skipok=1
-          fi
-	  ZTST_sects[test]=1
-	  ;;
+      if [[ -z "$ZTST_skipok" ]]; then  # if no error in %prep
+	# careful here: we can't execute ZTST_test before || or &&
+	# because that affects the behaviour of traps in the tests.
+	ZTST_test
+	(( $? )) && ZTST_skipok=1
+      fi
+      ZTST_sects[test]=1
+      ;;
     (clean)
-	   if (( ${ZTST_sects[test]} == 0 || ${ZTST_sects[clean]} )); then
-	     ZTST_testfailed "bad use of \`clean' section"
-	   else
-	     ZTST_clean
-	     ZTST_sects[clean]=1
-	   fi
-	   ZTST_skipok=
-	   ;;
-    *) ZTST_testfailed "bad section name: $ZTST_cursect"
-       ;;
+      if (( ${ZTST_sects[test]} == 0 )); then
+	ZTST_testfailed "\`clean' section must come after \`test' section"
+	break
+      fi
+      ZTST_clean
+      ZTST_sects[clean]=1
+      ZTST_skipok=
+      ;;
+    (*)
+      ZTST_testfailed "bad section name: $ZTST_cursect"
+      break
+      ;;
   esac
 done
 


Messages sorted by: Reverse Date, Date, Thread, Author