summary refs log tree commit diff
path: root/Test/ztst.zsh
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2011-12-01 21:52:55 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2011-12-01 21:52:55 +0000
commitae8e3ba86d675e13d70e9bf26bf88620bebb096d (patch)
treeaac40ec0598eab326572422461342bb997578a34 /Test/ztst.zsh
parentd6d0297b10fb1ad4143633140414f8c5631016d6 (diff)
downloadzsh-ae8e3ba86d675e13d70e9bf26bf88620bebb096d.tar.gz
zsh-ae8e3ba86d675e13d70e9bf26bf88620bebb096d.tar.xz
zsh-ae8e3ba86d675e13d70e9bf26bf88620bebb096d.zip
29924: add ability to match test output using patterns
Diffstat (limited to 'Test/ztst.zsh')
-rwxr-xr-xTest/ztst.zsh71
1 files changed, 62 insertions, 9 deletions
diff --git a/Test/ztst.zsh b/Test/ztst.zsh
index 4b583a5a8..745a13cff 100755
--- a/Test/ztst.zsh
+++ b/Test/ztst.zsh
@@ -285,12 +285,52 @@ $ZTST_code" && return 0
 
 # diff wrapper
 ZTST_diff() {
-  local diff_out diff_ret
+  emulate -L zsh
+  setopt extendedglob
+
+  local diff_out
+  integer diff_pat diff_ret
+
+  case $1 in
+    (p)
+    diff_pat=1
+    ;;
 
-  diff_out=$(diff "$@")
-  diff_ret="$?"
-  if [[ "$diff_ret" != "0" ]]; then
-    print -r "$diff_out"
+    (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