Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 1 | # Simple test harness infrastructurei for BusyBox |
| 2 | # |
| 3 | # Copyright 2005 by Rob Landley |
| 4 | # |
| 5 | # License is GPLv2, see LICENSE in the busybox tarball for full license text. |
| 6 | |
| 7 | # The "testing" function uses one environment variable: |
| 8 | # COMMAND = command to execute |
| 9 | # |
| 10 | # The function takes five arguments: |
| 11 | # $1) Description to display when running command |
| 12 | # $2) Command line arguments to command" |
| 13 | # $3) Expected result (on stdout)" |
| 14 | # $4) Data written to file "input" |
| 15 | # $5) Data written to stdin |
| 16 | # |
| 17 | # The exit value of testing is the exit value of the command it ran. |
| 18 | # |
| 19 | # The environment variable "FAILCOUNT" contains a cumulative total of the |
| 20 | # |
| 21 | |
| 22 | # The command line parsing is ugly and should be improved. |
| 23 | |
| 24 | if [ "$1" == "-v" ] |
| 25 | then |
| 26 | verbose=1 |
| 27 | fi |
| 28 | |
| 29 | export FAILCOUNT=0 |
| 30 | |
| 31 | # The testing function |
| 32 | |
| 33 | function testing() |
| 34 | { |
| 35 | if [ $# -ne 5 ] |
| 36 | then |
| 37 | echo "Test $1 has the wrong number of arguments" >&2 |
| 38 | exit |
| 39 | fi |
| 40 | |
| 41 | f=$FAILCOUNT |
| 42 | echo -ne "$3" > expected |
| 43 | echo -ne "$4" > input |
| 44 | echo -n -e "$5" | eval "$COMMAND $2" > actual |
| 45 | RETVAL=$? |
| 46 | |
| 47 | cmp expected actual > /dev/null |
| 48 | if [ $? -ne 0 ] |
| 49 | then |
| 50 | FAILCOUNT=$[$FAILCOUNT+1] |
Rob Landley | b766c39 | 2005-09-04 11:10:37 +0000 | [diff] [blame] | 51 | echo "FAIL: $1" |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 52 | if [ $verbose ] |
| 53 | then |
| 54 | diff -u expected actual |
| 55 | fi |
| 56 | else |
Rob Landley | b766c39 | 2005-09-04 11:10:37 +0000 | [diff] [blame] | 57 | echo "PASS: $1" |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 58 | fi |
| 59 | rm -f input expected actual |
| 60 | |
| 61 | return $RETVAL |
| 62 | } |