1 # Simple test harness infrastructurei for BusyBox
3 # Copyright 2005 by Rob Landley
5 # License is GPLv2, see LICENSE in the busybox tarball for full license text.
7 # This file defines two functions, "testing" and "optionflag"
9 # The "testing" function must have the following environment variable set:
10 # COMMAND = command to execute
12 # The following environment variables may be set to enable optional behavior
14 # VERBOSE - Print the diff -u of each failed test case.
15 # DEBUG - Enable command tracing.
16 # SKIP - do not perform this test (this is set by "optionflag")
18 # The "testing" function takes five arguments:
19 # $1) Description to display when running command
20 # $2) Command line arguments to command"
21 # $3) Expected result (on stdout)"
22 # $4) Data written to file "input"
23 # $5) Data written to stdin
25 # The exit value of testing is the exit value of the command it ran.
27 # The environment variable "FAILCOUNT" contains a cumulative total of the
28 # number of failed tests.
30 # The "optional" function is used to skip certain tests, ala:
31 # optionflag CONFIG_FEATURE_THINGY
33 # The "optional" function checks the environment variable "OPTIONFLAGS",
34 # which is either empty (in which case it always clears SKIP) or
35 # else contains a colon-separated list of features (in which case the function
36 # clears SKIP if the flag was found, or sets it to 1 if the flag was not found).
45 option="$OPTIONFLAGS" | egrep "(^|:)$1(:|\$)"
47 if [[ -z "$1" || -z "$OPTIONFLAGS" || ${#option} -ne 0 ]]
55 # The testing function
61 echo "Test $1 has the wrong number of arguments" >&2
65 if [ -n "$DEBUG" ] ; then
75 echo -ne "$3" > expected
77 echo -n -e "$5" | eval "$COMMAND $2" > actual
80 cmp expected actual > /dev/null
83 FAILCOUNT=$[$FAILCOUNT+1]
87 diff -u expected actual
92 rm -f input expected actual