about summary refs log tree commit diff
path: root/Test
diff options
context:
space:
mode:
authorBart Schaefer <barts@users.sourceforge.net>2001-06-18 17:40:52 +0000
committerBart Schaefer <barts@users.sourceforge.net>2001-06-18 17:40:52 +0000
commitd1fa8106b43e1d7eac0fbbd4741a8fd7107914b2 (patch)
tree387f5de311b9e6ba48135a47793aad8eff6fc7f5 /Test
parent619d2d4b64d807b12dc6e37482db76a4102c1f48 (diff)
downloadzsh-d1fa8106b43e1d7eac0fbbd4741a8fd7107914b2.tar.gz
zsh-d1fa8106b43e1d7eac0fbbd4741a8fd7107914b2.tar.xz
zsh-d1fa8106b43e1d7eac0fbbd4741a8fd7107914b2.zip
Merge assorted fixes from the development version.
Diffstat (limited to 'Test')
-rw-r--r--Test/C02cond.ztst185
-rw-r--r--Test/comptest151
2 files changed, 261 insertions, 75 deletions
diff --git a/Test/C02cond.ztst b/Test/C02cond.ztst
new file mode 100644
index 000000000..fd9f1205b
--- /dev/null
+++ b/Test/C02cond.ztst
@@ -0,0 +1,185 @@
+# Tests corresponding to the texinfo node `Conditional Expressions'
+
+%prep
+
+  umask 077
+
+  mkdir cond.tmp
+
+  cd cond.tmp
+
+  touch	unmodified
+
+  touch zerolength
+  chgrp $EGID zerolength
+  print 'Garbuglio' >nonzerolength
+
+  mkdir modish
+  chgrp $EGID modish
+  chmod g+xs modish
+  chmod u+s modish
+  chmod +t modish
+
+  touch unmodish
+  chmod 000 unmodish
+
+  print 'MZ' > cmd.exe
+  chmod +x cmd.exe
+%test
+
+  [[ -a zerolength && ! -a nonexistent ]]
+0:-a cond
+
+  # Find a block special file system.  This is a little tricky.
+  block=$(find /dev(|ices)/ -type b -print)
+  if [[ -n $block ]]; then
+    [[ -b $block[(f)1] && ! -b zerolength ]]
+  else
+    print -u8 'Warning: Not testing [[ -b blockdevice ]] (no devices found)'
+    [[ ! -b zerolength ]]
+  fi
+0D:-b cond
+
+  # Use hardcoded /dev/tty because globbing inside /dev fails on Cygwin
+  char=/dev/tty
+  [[ -c $char && ! -c $zerolength ]]
+0:-c cond
+
+  [[ -d . && ! -d zerolength ]]
+0:-d cond
+
+  [[ -e zerolength && ! -e nonexistent ]]
+0:-e cond
+
+  [[ -f zerolength && ! -f cond && ! -f $char && ! -f $block && ! -f . ]]
+0:-f cond
+
+  [[ -g modish && ! -g zerolength ]]
+0:-g cond
+
+  ln -s zerolength link
+  [[ -h link && ! -h zerolength ]]
+0:-h cond
+
+  [[ -k modish && ! -k zerolength ]]
+0:-k cond
+
+  foo=foo
+  bar=
+  [[ -n $foo && ! -n $bar && ! -n '' ]]
+0:-n cond
+
+  [[ -o rcs && ! -o norcs && -o noerrexit && ! -o errexit ]]
+0:-o cond
+
+  if ! grep '#define HAVE_FIFOS' $ZTST_testdir/../config.h; then
+    print -u8 'Warning: Not testing [[ -p pipe ]] (FIFOs not supported)'
+    [[ ! -p zerolength ]]
+  else
+    if whence mkfifo && mkfifo pipe || mknod pipe p; then
+      [[ -p pipe && ! -p zerolength ]]
+    else
+      print -u8 'Warning: Not testing [[ -p pipe ]] (cannot create FIFO)'
+      [[ ! -p zerolength ]]
+    fi
+  fi
+0dD:-p cond
+
+  [[ -r zerolength && ! -r unmodish ]]
+0:-r cond
+
+  [[ -s nonzerolength && ! -s zerolength ]]
+0:-s cond
+
+# no simple way of guaranteeing test for -t
+
+  [[ -u modish && ! -u zerolength ]]
+0:-u cond
+
+  [[ -x cmd.exe && ! -x zerolength ]]
+0:-x cond
+
+  [[ -z $bar && -z '' && ! -z $foo ]]
+0:-z cond
+
+  [[ -L link && ! -L zerolength ]]
+0:-L cond
+
+# hard to guarantee a file not owned by current uid
+  [[ -O zerolength ]]
+0:-O cond
+
+  [[ -G zerolength ]]
+0:-G cond
+
+# can't be bothered with -S
+
+  sleep 1
+  cat unmodified
+  touch newnewnew
+  if [[ $OSTYPE == "cygwin" ]]; then
+    print -u8 "Warning: not testing [[ -N file ]] (not supported on Cygwin)"
+    true
+  else
+    [[ -N newnewnew && ! -N unmodified ]]
+  fi
+0:-N cond
+
+  [[ newnewnew -nt zerolength && ! (unmodified -nt zerolength) ]]
+0:-nt cond
+
+  [[ zerolength -ot newnewnew && ! (zerolength -ot unmodified) ]]
+0:-ot cond
+
+  [[ link -ef zerolength && ! (link -ef nonzerolength) ]]
+0:-ef cond
+
+  [[ foo = foo && foo != bar && foo == foo && foo != '' ]]
+0:=, == and != conds
+
+  [[ bar < foo && foo > bar ]]
+0:< and > conds
+
+  [[ $(( 3 + 4 )) -eq 0x07 && $(( 5 * 2 )) -ne 0x10 ]]
+0:-eq and -ne conds
+
+  [[ 3 -lt 04 && 05 -gt 2 ]]
+0:-lt and -gt conds
+
+  [[ 3 -le 3 && ! (4 -le 3) ]]
+0:-le cond
+
+  [[ 3 -ge 3 && ! (3 -ge 4) ]]
+0:-ge cond
+
+  [[ 1 -lt 2 || 2 -lt 2 && 3 -gt 4 ]]
+0:|| and && in conds
+
+  if ! grep '#define PATH_DEV_FD' $ZTST_testdir/../config.h; then
+    print -u8 "Warning: not testing [[ -e /dev/fd/0 ]] (/dev/fd not supported)"
+    true
+  else
+    [[ -e /dev/fd/0 ]]
+  fi
+0dD:/dev/fd support in conds handled by access
+
+  if ! grep '#define PATH_DEV_FD' $ZTST_testdir/../config.h; then
+    print -u8 "Warning: not testing [[ -O /dev/fd/0 ]] (/dev/fd not supported)"
+    true
+  else
+    [[ -O /dev/fd/0 ]]
+  fi
+0dD:/dev/fd support in conds handled by stat
+
+  [[ ( -z foo && -z foo ) || -z foo ]]
+1:complex conds with skipping
+
+  [ '' != bar -a '' = '' ]
+0:strings with `[' builtin
+
+  [ `echo 0` -lt `echo 1` ]
+0:substituion in `[' builtin
+
+%clean
+  # This works around a bug in rm -f in some versions of Cygwin
+  chmod 644 unmodish
diff --git a/Test/comptest b/Test/comptest
index 012ad788c..d65ea351a 100644
--- a/Test/comptest
+++ b/Test/comptest
@@ -1,54 +1,54 @@
-#!/usr/local/bin/zsh -f
+comptestinit () {
+  setopt extendedglob
+  [[ -d $ZTST_testdir/Modules/zsh ]] && module_path=( $ZTST_testdir/Modules )
+  fpath=( $ZTST_srcdir/../Functions/*~*/CVS(/)
+          $ZTST_srcdir/../Completion
+          $ZTST_srcdir/../Completion/*/*~*/CVS(/) )
 
-[[ -d $ZTST_testdir/Modules/zsh ]] && module_path=( $ZTST_testdir/Modules )
+  zmodload -i zsh/zpty
 
-zmodload -i zsh/zpty
-setopt extendedglob
+  comptest_zsh=${ZSH:-zsh}
 
-fpath=( $ZTST_srcdir/../(Completion|Functions)/*~*/CVS(/) )
-
-debug=
-dump=(-D)
-code=
-zsh=${ZSH:-zsh}
-termcap_ce="$(echotc ce)"
-
-while getopts Dd:c:z: opt; do
-  case $opt in
-    D) debug=yes;;
-    d) dump=(-d "$OPTARG");;
-    c) code="$OPTARG";;
-    z) zsh="$OPTARG";;
-  esac
-done
-(( OPTIND > 1 )) && shift $(( OPTIND - 1 ))
+  while getopts z: opt; do
+    case $opt in
+      z) comptest_zsh="$OPTARG";;
+    esac
+  done
+  (( OPTIND > 1 )) && shift $(( OPTIND - 1 ))
 
-input="$*"
+  export PS1="<PROMPT>"
+  zpty zsh "$comptest_zsh -f +Z"
 
-tmp=/tmp/comptest.$$
+  zpty -r zsh log1 "*<PROMPT>*" || { 
+    print "first prompt hasn't appeared."
+    return 1
+  }
 
-cat <<End >$tmp
-module_path=( $module_path )
-fpath=( $fpath )
+  comptesteval \
+"export ZDOTDIR=$ZTST_testdir" \
+"module_path=( $module_path )" \
+"fpath=( $fpath )" \
+'LISTMAX=10000000
+TERM=vt100
 stty columns 80 rows 24
-LISTMAX=10000000
-ZLS_COLORS='no=<NO>:fi=<FI>:di=<DI>:ln=<LN>:pi=<PI>:so=<SO>:bd=<BD>:cd=<CD>:ex=<EX>:mi=<MI>:tc=<TC>:sp=<SP>:lc=<LC>:ec=<EC>\n:rc=<RC>'
+setopt zle
 bindkey -e
 autoload -U compinit
-compinit $dump
+compinit -u
+zstyle ":completion:*:default" list-colors "no=<NO>" "fi=<FI>" "di=<DI>" "ln=<LN>" "pi=<PI>" "so=<SO>" "bd=<BD>" "cd=<CD>" "ex=<EX>" "mi=<MI>" "tc=<TC>" "sp=<SP>" "lc=<LC>" "ec=<EC>\n" "rc=<RC>"
 zstyle ":completion:*" group-name ""
-zstyle ":completion*:messages" format "<MESSAGE>%d</MESSAGE>
+zstyle ":completion:*:messages" format "<MESSAGE>%d</MESSAGE>
 "
-zstyle ":completion*:descriptions" format "<DESCRIPTION>%d</DESCRIPTION>
+zstyle ":completion:*:descriptions" format "<DESCRIPTION>%d</DESCRIPTION>
 "
-zstyle ":completion*:options" verbose yes
-zstyle ":completion*:values" verbose yes
+zstyle ":completion:*:options" verbose yes
+zstyle ":completion:*:values" verbose yes
 setopt noalwayslastprompt listrowsfirst completeinword
 zmodload zsh/complist
 expand-or-complete-with-report () {
   print -lr "<WIDGET><expand-or-complete>"
   zle expand-or-complete
-  print -lr - "<LBUFFER>\$LBUFFER</LBUFFER>" "<RBUFFER>\$RBUFFER</RBUFFER>"
+  print -lr - "<LBUFFER>$LBUFFER</LBUFFER>" "<RBUFFER>$RBUFFER</RBUFFER>"
   zle clear-screen
   zle -R
 }
@@ -60,8 +60,9 @@ list-choices-with-report () {
 }
 finish () {
   print "<WIDGET><finish>"
-  sleep 1
-  exit 0
+  zle kill-whole-line
+  zle clear-screen
+  zle -R
 }
 zle -N expand-or-complete-with-report
 zle -N list-choices-with-report
@@ -69,51 +70,51 @@ zle -N finish
 bindkey "^I" expand-or-complete-with-report
 bindkey "^D" list-choices-with-report
 bindkey "^Z" finish
-$code
-End
-
-export PS1="<PROMPT>"
-zpty zsh "$zsh" -f
-
-zpty -r zsh log1 "*<PROMPT>*" || { 
-  print first prompt doesn\'t appered.
-  exit 1
+'
 }
 
-zpty -w zsh ". $tmp"
-zpty -r zsh log2 "*<PROMPT>*" || {
-  print second prompt doesn\'t appered.
-  exit 1
-}
-rm $tmp
+comptesteval () {
+  local tmp=/tmp/comptest.$$
 
-zpty -n -w zsh "$input"$'\C-Z'
-zpty -r zsh log "*<WIDGET><finish>*" || {
-  print finish widget doesn\'t invoked.
-  exit 1
+  print -lr - "$@" > $tmp
+  zpty -w zsh ". $tmp"
+  zpty -r zsh log_eval "*<PROMPT>*" || {
+    print "prompt hasn't appeared."
+    return 1
+  }
+  rm $tmp
 }
 
-if [[ -n "$debug" ]]; then
-  print -lr - "$log" > /tmp/comptest.debug
-fi
+comptest () {
+  input="$*"
+  zpty -n -w zsh "$input"$'\C-Z'
+  zpty -r zsh log "*<WIDGET><finish>*<PROMPT>*" || {
+    print "failed to invoke finish widget."
+    return 1
+  }
 
-logs=(${(s:<WIDGET>:)log})
-shift logs
+  logs=(${(s:<WIDGET>:)log})
+  shift logs
 
-for log in "$logs[@]"; do
-  if [[ "$log" = (#b)*$'<LBUFFER>'(*)$'</LBUFFER>\r\n<RBUFFER>'(*)$'</RBUFFER>'* ]]; then
-    print -lr "line: {$match[1]}{$match[2]}"
-  fi
-  while (( ${(N)log#*(#b)(<LC><(??)><RC>(*)<EC>|<DESCRIPTION>(*)</DESCRIPTION>|<MESSAGE>(*)</MESSAGE>)} )); do
-    log="${log[$mend[1]+1,-1]}"
-    if (( 0 <= $mbegin[2] )); then
-      if [[ $match[2] != TC && $match[3] != \ # ]]; then
-	print -lr "$match[2]:{${match[3]%$termcap_ce}}"
-      fi
-    elif (( 0 <= $mbegin[4] )); then
-      print -lr "DESCRIPTION:{$match[4]}"
-    elif (( 0 <= $mbegin[5] )); then
-      print -lr "MESSAGE:{$match[5]}"
+  for log in "$logs[@]"; do
+    if [[ "$log" = (#b)*$'<LBUFFER>'(*)$'</LBUFFER>\r\n<RBUFFER>'(*)$'</RBUFFER>'* ]]; then
+      print -lr "line: {$match[1]}{$match[2]}"
     fi
+    while (( ${(N)log#*(#b)(<LC><(??)><RC>(*)<EC>|<DESCRIPTION>(*)</DESCRIPTION>|<MESSAGE>(*)</MESSAGE>|<COMPADD>(*)</COMPADD>|<INSERT_POSITIONS>(*)</INSERT_POSITIONS>)} )); do
+      log="${log[$mend[1]+1,-1]}"
+      if (( 0 <= $mbegin[2] )); then
+	if [[ $match[2] != TC && $match[3] != \ # ]]; then
+	  print -lr "$match[2]:{${match[3]%${(%):-%E}}}"
+	fi
+      elif (( 0 <= $mbegin[4] )); then
+	print -lr "DESCRIPTION:{$match[4]}"
+      elif (( 0 <= $mbegin[5] )); then
+	print -lr "MESSAGE:{$match[5]}"
+      elif (( 0 <= $mbegin[6] )); then
+        print -lr "COMPADD:{${${match[6]}//[$'\r\n']/}}"
+      elif (( 0 <= $mbegin[7] )); then
+        print -lr "INSERT_POSITIONS:{${${match[7]}//[$'\r\n']/}}"
+      fi
+    done
   done
-done
+}