Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/testsuite/testing.sh
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/testsuite/testing.sh
r1765 r2725 1 # Simple test harness infrastructure ifor BusyBox1 # Simple test harness infrastructure for BusyBox 2 2 # 3 3 # Copyright 2005 by Rob Landley … … 5 5 # License is GPLv2, see LICENSE in the busybox tarball for full license text. 6 6 7 # This file defines two functions, "testing" and "optionflag" 7 # This file defines two functions, "testing" and "optional" 8 # and a couple more... 8 9 9 10 # The following environment variables may be set to enable optional behavior … … 11 12 # VERBOSE - Print the diff -u of each failed test case. 12 13 # DEBUG - Enable command tracing. 13 # SKIP - do not perform this test (this is set by "option flag")14 # SKIP - do not perform this test (this is set by "optional") 14 15 # 15 16 # The "testing" function takes five arguments: 16 # $1) Description to display when running command17 # $2) Command line arguments to command18 # $3) Expected result (on stdout)19 # $4) Data written to file "input"20 # $5) Data written to stdin17 # $1) Test description 18 # $2) Command(s) to run. May have pipes, redirects, etc 19 # $3) Expected result on stdout 20 # $4) Data to be written to file "input" 21 # $5) Data to be written to stdin 21 22 # 22 # The exit value of testing is the exit value of the commandit ran.23 # The exit value of testing is the exit value of $2 it ran. 23 24 # 24 25 # The environment variable "FAILCOUNT" contains a cumulative total of the … … 26 27 27 28 # The "optional" function is used to skip certain tests, ala: 28 # option flag CONFIG_FEATURE_THINGY29 # optional FEATURE_THINGY 29 30 # 30 31 # The "optional" function checks the environment variable "OPTIONFLAGS", … … 36 37 export SKIP= 37 38 39 # Helper for helpers. Oh my... 40 41 test x"$ECHO" != x"" || { 42 ECHO="echo" 43 test x"`echo -ne`" = x"" || { 44 # Compile and use a replacement 'echo' which understands -e -n 45 ECHO="$PWD/echo-ne" 46 test -x "$ECHO" || { 47 gcc -Os -o "$ECHO" ../scripts/echo.c || exit 1 48 } 49 } 50 export ECHO 51 } 52 38 53 # Helper functions 39 54 40 55 optional() 41 56 { 42 option=`echo "$OPTIONFLAGS" | egrep "(^|:)$1(:|\$)"` 43 # Not set? 44 if [ -z "$1" ] || [ -z "$OPTIONFLAGS" ] || [ ${#option} -ne 0 ] 45 then 46 SKIP="" 47 return 48 fi 49 SKIP=1 57 SKIP= 58 while test "$1"; do 59 if test x"${OPTIONFLAGS/*:$1:*/y}" != x"y"; then 60 SKIP=1 61 return 62 fi 63 shift 64 done 50 65 } 51 66 … … 55 70 { 56 71 NAME="$1" 57 [ - z "$1" ] && NAME=$272 [ -n "$1" ] || NAME="$2" 58 73 59 74 if [ $# -ne 5 ] 60 75 then 61 echo "Test $NAME has the wrong number of arguments ($# $*)" >&262 exit 76 echo "Test $NAME has wrong number of arguments: $# (must be 5)" >&2 77 exit 1 63 78 fi 64 79 65 [ - n "$DEBUG" ] &&set -x80 [ -z "$DEBUG" ] || set -x 66 81 67 82 if [ -n "$SKIP" ] … … 71 86 fi 72 87 73 echo -ne "$3" > expected 74 echo -ne "$4" > input 75 [ -z "$VERBOSE" ] || echo "echo '$5' | $2" 76 echo -ne "$5" | eval "$2" > actual 88 $ECHO -ne "$3" > expected 89 $ECHO -ne "$4" > input 90 [ -z "$VERBOSE" ] || echo "echo -ne '$4' >input" 91 [ -z "$VERBOSE" ] || echo "echo -ne '$5' | $2" 92 $ECHO -ne "$5" | eval "$2" > actual 77 93 RETVAL=$? 78 94 79 cmp expected actual >/dev/null 2>/dev/null 80 if [ $? -ne 0 ] 95 if cmp expected actual >/dev/null 2>/dev/null 81 96 then 82 FAILCOUNT=$[$FAILCOUNT+1] 97 echo "PASS: $NAME" 98 else 99 FAILCOUNT=$(($FAILCOUNT + 1)) 83 100 echo "FAIL: $NAME" 84 [ -n "$VERBOSE" ] && diff -u expected actual 85 else 86 echo "PASS: $NAME" 101 [ -z "$VERBOSE" ] || diff -u expected actual 87 102 fi 88 103 rm -f input expected actual 89 104 90 [ - n "$DEBUG" ] &&set +x105 [ -z "$DEBUG" ] || set +x 91 106 92 107 return $RETVAL … … 102 117 [ $# -lt 2 ] && return 103 118 104 echo-n .119 $ECHO -n . 105 120 106 121 dest=$1 … … 108 123 for i in "$@" 109 124 do 110 [ "${i:0:1}" == "/" ] || i=$(which $i) 125 #bashism: [ "${i:0:1}" == "/" ] || i=$(which $i) 126 i=$(which $i) # no-op for /bin/prog 111 127 [ -f "$dest/$i" ] && continue 112 128 if [ -e "$i" ] … … 136 152 # Copy utilities from command line arguments 137 153 138 echo-n "Setup chroot"154 $ECHO -n "Setup chroot" 139 155 mkchroot tmpdir4chroot $* 140 156 echo … … 152 168 rmdir tmpdir4chroot 153 169 } 154
Note:
See TracChangeset
for help on using the changeset viewer.