aboutsummaryrefslogtreecommitdiff
path: root/testsuite/testing.sh
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2005-11-07 08:50:53 +0000
committerRob Landley <rob@landley.net>2005-11-07 08:50:53 +0000
commit48c6157eb9c10bdca89af2792177afc0380ef9c5 (patch)
treecdc8aa6b83e2370c00f38dca9b93722736bcff32 /testsuite/testing.sh
parent7ad4b30ed4ba2542bebcfc5fda9e9af24fb67969 (diff)
downloadbusybox-w32-48c6157eb9c10bdca89af2792177afc0380ef9c5.tar.gz
busybox-w32-48c6157eb9c10bdca89af2792177afc0380ef9c5.tar.bz2
busybox-w32-48c6157eb9c10bdca89af2792177afc0380ef9c5.zip
Fix the test suite so that individual *.tests files can be run ala
COMMAND=sort ./sort.tests So we can compare against non-busybox versions, and possibly our testsuite will be useful to somebody like the Linux Test Project someday. Redid testing.sh to add new command, "optional", to skip tests that require certain features. (use: `optional FEATURE_SORT_BIG`, or `optional ""` to stop skipping.) Note that optional is a NOP if the environment variable "OPTIONFLAGS" is blank, so although we're marking up the tests with busybox specific knowledge, it doesn't interfere with running the tests without busybox. Moved setting the "OPTIONFLAGS" environment variable to runtest. Philosophy: busybox-specific stuff belongs in runtest; both testing.sh and the tests themselves should be as busybox-agnostic as possible. Moved detecting that a command isn't in busybox at all (hence skipping the entire command.tests file) to runtests. Rationale: optional can't currently test for more than one feature at a time, so if we clear anything with optional "" we might perform tests we don't want to. Marked up busybox.tests to know which tests need CAT enabled. Fixed up other tests to be happy with new notation. I suspect egrep should be appended to grep. It's a sub-feature, really...
Diffstat (limited to 'testsuite/testing.sh')
-rwxr-xr-xtestsuite/testing.sh86
1 files changed, 42 insertions, 44 deletions
diff --git a/testsuite/testing.sh b/testsuite/testing.sh
index 83727f6d3..c1002a6aa 100755
--- a/testsuite/testing.sh
+++ b/testsuite/testing.sh
@@ -4,10 +4,18 @@
4# 4#
5# License is GPLv2, see LICENSE in the busybox tarball for full license text. 5# License is GPLv2, see LICENSE in the busybox tarball for full license text.
6 6
7# The "testing" function uses one environment variable: 7# This file defines two functions, "testing" and "optionflag"
8# COMMAND = command to execute 8
9# The "testing" function must have the following environment variable set:
10# COMMAND = command to execute
11#
12# The following environment variables may be set to enable optional behavior
13# in "testing":
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")
9# 17#
10# The function takes five arguments: 18# The "testing" function takes five arguments:
11# $1) Description to display when running command 19# $1) Description to display when running command
12# $2) Command line arguments to command" 20# $2) Command line arguments to command"
13# $3) Expected result (on stdout)" 21# $3) Expected result (on stdout)"
@@ -17,39 +25,31 @@
17# The exit value of testing is the exit value of the command it ran. 25# The exit value of testing is the exit value of the command it ran.
18# 26#
19# The environment variable "FAILCOUNT" contains a cumulative total of the 27# The environment variable "FAILCOUNT" contains a cumulative total of the
20# 28# number of failed tests.
21
22verbose=0
23debug=0
24force=0
25for x in "$@" ; do
26 case "$x" in
27 -v|--verbose) verbose=1; shift;;
28 -d|--debug) debug=1; shift;;
29 -f|--force) force=1; shift;;
30 --) break;;
31 -*) echo "Unknown option '$x'"; exit 1;;
32 *) break;;
33 esac
34done
35 29
36if [ -n "$VERBOSE" ] ; then 30# The "optional" function is used to skip certain tests, ala:
37 verbose=1 31# optionflag CONFIG_FEATURE_THINGY
38fi 32#
39if [ -n "$DEBUG" ] ; then 33# The "optional" function checks the environment variable "OPTIONFLAGS",
40 debug=1 34# which is either empty (in which case it always clears SKIP) or
41fi 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).
42 37
43export FAILCOUNT=0 38export FAILCOUNT=0
39export SKIP=
44 40
45# Helper functions 41# Helper functions
46 42
47config_is_set () 43optional()
48{ 44{
49 local uc_what=$(echo ${1?} | tr a-z A-Z) 45 option="$OPTIONFLAGS" | egrep "(^|:)$1(:|\$)"
50 grep -q "^[ ]*CONFIG_${uc_what}" ${bindir:-..}/.config || \ 46 # Not set?
51 grep -q "^[ ]*BB_CONFIG_${uc_what}" ${bindir:-..}/.config 47 if [[ -z "$1" || -z "$OPTIONFLAGS" || ${#option} -ne 0 ]]
52 return $? 48 then
49 SKIP=""
50 return
51 fi
52 SKIP=1
53} 53}
54 54
55# The testing function 55# The testing function
@@ -62,17 +62,14 @@ testing ()
62 exit 62 exit
63 fi 63 fi
64 64
65 if [ $debug -eq 1 ] ; then 65 if [ -n "$DEBUG" ] ; then
66 set -x 66 set -x
67 fi 67 fi
68 68
69 if [ -n "$_BB_CONFIG_DEP" ] && [ ${force} -eq 0 ] 69 if [ -n "$SKIP" ]
70 then 70 then
71 if ! config_is_set "$_BB_CONFIG_DEP" 71 echo "SKIPPED: $1"
72 then 72 return 0
73 echo "SKIPPED: $1"
74 return 0
75 fi
76 fi 73 fi
77 74
78 echo -ne "$3" > expected 75 echo -ne "$3" > expected
@@ -83,18 +80,19 @@ testing ()
83 cmp expected actual > /dev/null 80 cmp expected actual > /dev/null
84 if [ $? -ne 0 ] 81 if [ $? -ne 0 ]
85 then 82 then
86 ((FAILCOUNT++)) 83 FAILCOUNT=$[$FAILCOUNT+1]
87 echo "FAIL: $1" 84 echo "FAIL: $1"
88 if [ $verbose -eq 1 ] 85 if [ -n "$VERBOSE" ]
89 then 86 then
90 diff -u expected actual 87 diff -u expected actual
91 fi 88 fi
92 else 89 else
93 echo "PASS: $1" 90 echo "PASS: $1"
94 fi 91 fi
95 rm -f input expected actual 92 rm -f input expected actual
96 93
97 if [ $debug -eq 1 ] ; then 94 if [ -n "$DEBUG" ]
95 then
98 set +x 96 set +x
99 fi 97 fi
100 98