diff options
author | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2005-11-07 08:50:53 +0000 |
---|---|---|
committer | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2005-11-07 08:50:53 +0000 |
commit | 9c6e894573366c7293159047c143a89b1032c626 (patch) | |
tree | cdc8aa6b83e2370c00f38dca9b93722736bcff32 | |
parent | c8b221f03a3dc71b2aceac2dcb0f2877e7ba9bb3 (diff) | |
download | busybox-w32-9c6e894573366c7293159047c143a89b1032c626.tar.gz busybox-w32-9c6e894573366c7293159047c143a89b1032c626.tar.bz2 busybox-w32-9c6e894573366c7293159047c143a89b1032c626.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...
git-svn-id: svn://busybox.net/trunk/busybox@12176 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rwxr-xr-x | testsuite/busybox.tests | 13 | ||||
-rwxr-xr-x | testsuite/egrep.tests | 3 | ||||
-rwxr-xr-x | testsuite/grep.tests | 6 | ||||
-rwxr-xr-x | testsuite/pidof.tests | 6 | ||||
-rwxr-xr-x | testsuite/runtest | 14 | ||||
-rwxr-xr-x | testsuite/sort.tests | 6 | ||||
-rwxr-xr-x | testsuite/testing.sh | 86 | ||||
-rwxr-xr-x | testsuite/uniq.tests | 3 |
8 files changed, 66 insertions, 71 deletions
diff --git a/testsuite/busybox.tests b/testsuite/busybox.tests index 7595d061f..b69272593 100755 --- a/testsuite/busybox.tests +++ b/testsuite/busybox.tests | |||
@@ -7,15 +7,9 @@ | |||
7 | if [ ${#COMMAND} -eq 0 ]; then COMMAND=busybox; fi | 7 | if [ ${#COMMAND} -eq 0 ]; then COMMAND=busybox; fi |
8 | . testing.sh | 8 | . testing.sh |
9 | 9 | ||
10 | # Depends on nothing | ||
11 | _BB_CONFIG_DEP="" | ||
12 | |||
13 | # We'll assume "cat" is built in, because we need some other command to test. | ||
14 | |||
15 | HELPDUMP=`$COMMAND` | 10 | HELPDUMP=`$COMMAND` |
16 | 11 | ||
17 | # The gratuitous "\n"s are due to a shell idiosyncrasy: environment variables | 12 | # We need to test under calling the binary under other names. |
18 | # seem to strip trailing whitespace, which makes cmp and diff unhappy. | ||
19 | 13 | ||
20 | ln -s `which "$COMMAND"` busybox-suffix | 14 | ln -s `which "$COMMAND"` busybox-suffix |
21 | ln -s `which "$COMMAND"` unknown | 15 | ln -s `which "$COMMAND"` unknown |
@@ -29,15 +23,16 @@ do | |||
29 | 23 | ||
30 | testing "$i" "" "$HELPDUMP\n\n" "" "" | 24 | testing "$i" "" "$HELPDUMP\n\n" "" "" |
31 | 25 | ||
32 | testing "$i cat" "cat" "moo" "" "moo" | ||
33 | |||
34 | testing "$i unknown" "unknown 2>&1" \ | 26 | testing "$i unknown" "unknown 2>&1" \ |
35 | "unknown: applet not found\n" "" "" | 27 | "unknown: applet not found\n" "" "" |
36 | 28 | ||
37 | testing "$i --help" "--help 2>&1" "$HELPDUMP\n\n" "" "" | 29 | testing "$i --help" "--help 2>&1" "$HELPDUMP\n\n" "" "" |
38 | 30 | ||
31 | optional CAT | ||
32 | testing "$i cat" "cat" "moo" "" "moo" | ||
39 | testing "$i --help cat" "--help cat 2>&1 | grep prints" \ | 33 | testing "$i --help cat" "--help cat 2>&1 | grep prints" \ |
40 | "Concatenates FILE(s) and prints them to stdout.\n" "" "" | 34 | "Concatenates FILE(s) and prints them to stdout.\n" "" "" |
35 | optional "" | ||
41 | 36 | ||
42 | testing "$i --help unknown" "--help unknown 2>&1" \ | 37 | testing "$i --help unknown" "--help unknown 2>&1" \ |
43 | "unknown: applet not found\n" "" "" | 38 | "unknown: applet not found\n" "" "" |
diff --git a/testsuite/egrep.tests b/testsuite/egrep.tests index b634649bb..61ce009d7 100755 --- a/testsuite/egrep.tests +++ b/testsuite/egrep.tests | |||
@@ -9,8 +9,7 @@ | |||
9 | [ ${#COMMAND} -eq 0 ] && COMMAND=egrep | 9 | [ ${#COMMAND} -eq 0 ] && COMMAND=egrep |
10 | . testing.sh | 10 | . testing.sh |
11 | 11 | ||
12 | # Depends on FEATURE_GREP_EGREP_ALIAS | 12 | optional FEATURE_GREP_EGREP_ALIAS |
13 | _BB_CONFIG_DEP=FEATURE_GREP_EGREP_ALIAS | ||
14 | 13 | ||
15 | testing "grep is also egrep" "foo" "foo\n" "" "foo\nbar\n" | 14 | testing "grep is also egrep" "foo" "foo\n" "" "foo\nbar\n" |
16 | testing "egrep is not case insensitive" "foo ; [ \$? -ne 0 ] && echo yes" \ | 15 | testing "egrep is not case insensitive" "foo ; [ \$? -ne 0 ] && echo yes" \ |
diff --git a/testsuite/grep.tests b/testsuite/grep.tests index c4f534d1a..2a7a7b901 100755 --- a/testsuite/grep.tests +++ b/testsuite/grep.tests | |||
@@ -9,9 +9,6 @@ | |||
9 | [ ${#COMMAND} -eq 0 ] && COMMAND=grep | 9 | [ ${#COMMAND} -eq 0 ] && COMMAND=grep |
10 | . testing.sh | 10 | . testing.sh |
11 | 11 | ||
12 | # Depends on grep | ||
13 | _BB_CONFIG_DEP=grep | ||
14 | |||
15 | # testing "test name" "options" "expected result" "file input" "stdin" | 12 | # testing "test name" "options" "expected result" "file input" "stdin" |
16 | # file input will be file called "input" | 13 | # file input will be file called "input" |
17 | # test can create a file "actual" instead of writing to stdout | 14 | # test can create a file "actual" instead of writing to stdout |
@@ -75,8 +72,7 @@ testing "grep matches NUL" ". input > /dev/null 2>&1 ; echo \$?" "0\n" "\0\n" "" | |||
75 | testing "grep handles multiple regexps" "-e one -e two input ; echo \$?" \ | 72 | testing "grep handles multiple regexps" "-e one -e two input ; echo \$?" \ |
76 | "one\ntwo\n0\n" "one\ntwo\n" "" | 73 | "one\ntwo\n0\n" "one\ntwo\n" "" |
77 | 74 | ||
78 | # Depends on FEATURE_GREP_EGREP_ALIAS | 75 | optional FEATURE_GREP_EGREP_ALIAS |
79 | _BB_CONFIG_DEP=FEATURE_GREP_EGREP_ALIAS | ||
80 | testing "grep -E supports extended regexps" "-E fo+" "foo\n" "" "b\ar\nfoo\nbaz" | 76 | testing "grep -E supports extended regexps" "-E fo+" "foo\n" "" "b\ar\nfoo\nbaz" |
81 | 77 | ||
82 | exit $FAILCOUNT | 78 | exit $FAILCOUNT |
diff --git a/testsuite/pidof.tests b/testsuite/pidof.tests index 0c303cf22..0515522f8 100755 --- a/testsuite/pidof.tests +++ b/testsuite/pidof.tests | |||
@@ -16,13 +16,11 @@ testing "pidof (exit with error)" "veryunlikelyoccuringbinaryname ; echo \$?" \ | |||
16 | testing "pidof (exit with success)" "pidof > /dev/null; echo \$?" "0\n" "" "" | 16 | testing "pidof (exit with success)" "pidof > /dev/null; echo \$?" "0\n" "" "" |
17 | 17 | ||
18 | 18 | ||
19 | # Depends on FEATURE_PIDOF_SINGLE | 19 | optional FEATURE_PIDOF_SINGLE |
20 | _BB_CONFIG_DEP=FEATURE_PIDOF_SINGLE | ||
21 | testing "pidof -s" "-s $(basename $0) ; echo -n \$?" \ | 20 | testing "pidof -s" "-s $(basename $0) ; echo -n \$?" \ |
22 | "$(pidof -s $(basename $0) ; echo -n $?)" "" "" | 21 | "$(pidof -s $(basename $0) ; echo -n $?)" "" "" |
23 | 22 | ||
24 | # Depends on FEATURE_PIDOF_OMIT | 23 | optional FEATURE_PIDOF_OMIT |
25 | _BB_CONFIG_DEP=FEATURE_PIDOF_OMIT | ||
26 | testing "pidof -o %PPID" "$(basename $0) -o %PPID ; echo -n \$?" \ | 24 | testing "pidof -o %PPID" "$(basename $0) -o %PPID ; echo -n \$?" \ |
27 | "$(pidof $(basename $0) -o %PPID ; echo -n $?)" "" "" | 25 | "$(pidof $(basename $0) -o %PPID ; echo -n $?)" "" "" |
28 | 26 | ||
diff --git a/testsuite/runtest b/testsuite/runtest index 9fd2d0f13..c1b1ec2f4 100755 --- a/testsuite/runtest +++ b/testsuite/runtest | |||
@@ -91,6 +91,11 @@ else | |||
91 | applets=$(ls $srcdir) | 91 | applets=$(ls $srcdir) |
92 | fi | 92 | fi |
93 | 93 | ||
94 | # Set up option flags so tests can be selective. | ||
95 | |||
96 | configfile=${bindir:-../../}/.config | ||
97 | export OPTIONFLAGS=:$(echo $(sed -nr 's/^CONFIG_(.*)=.*/\1/p' $configfile) | sed 's/ /:/') | ||
98 | |||
94 | for applet in $applets; do | 99 | for applet in $applets; do |
95 | if [ "$applet" = "links" ]; then continue; fi | 100 | if [ "$applet" = "links" ]; then continue; fi |
96 | if [ "$applet" != "CVS" -a -d "$srcdir/$applet" ]; then | 101 | if [ "$applet" != "CVS" -a -d "$srcdir/$applet" ]; then |
@@ -100,9 +105,18 @@ for applet in $applets; do | |||
100 | status=1 | 105 | status=1 |
101 | fi | 106 | fi |
102 | fi | 107 | fi |
108 | |||
109 | # Is this a new-style test? | ||
103 | applet=$(echo "$applet" | sed -n 's/\.tests$//p') | 110 | applet=$(echo "$applet" | sed -n 's/\.tests$//p') |
104 | if [ ${#applet} -ne 0 ] | 111 | if [ ${#applet} -ne 0 ] |
105 | then | 112 | then |
113 | appcfg=`grep -i "^# CONFIG_$applet" $configfile` | ||
114 | if [ -n "$appcfg" ] | ||
115 | then | ||
116 | echo "SKIPPED: $applet (is configured out)" | ||
117 | continue | ||
118 | fi | ||
119 | # Setup environment for test. | ||
106 | if [ -d links ]; then | 120 | if [ -d links ]; then |
107 | rm -f links/"$applet" | 121 | rm -f links/"$applet" |
108 | else | 122 | else |
diff --git a/testsuite/sort.tests b/testsuite/sort.tests index 04d75cfe2..294530988 100755 --- a/testsuite/sort.tests +++ b/testsuite/sort.tests | |||
@@ -7,9 +7,6 @@ | |||
7 | if [ ${#COMMAND} -eq 0 ]; then COMMAND=sort; fi | 7 | if [ ${#COMMAND} -eq 0 ]; then COMMAND=sort; fi |
8 | . testing.sh | 8 | . testing.sh |
9 | 9 | ||
10 | # Depends on sort | ||
11 | _BB_CONFIG_DEP=sort | ||
12 | |||
13 | # The basic tests. These should work even with the small busybox. | 10 | # The basic tests. These should work even with the small busybox. |
14 | 11 | ||
15 | testing "sort" "input" "a\nb\nc\n" "c\na\nb\n" "" | 12 | testing "sort" "input" "a\nb\nc\n" "c\na\nb\n" "" |
@@ -21,6 +18,7 @@ testing "sort reverse" "-r input" "wook\nwalrus\npoint\npabst\naargh\n" \ | |||
21 | 18 | ||
22 | # These tests require the full option set. | 19 | # These tests require the full option set. |
23 | 20 | ||
21 | optional FEATURE_SORT_BIG | ||
24 | # Longish chunk of data re-used by the next few tests | 22 | # Longish chunk of data re-used by the next few tests |
25 | 23 | ||
26 | data="42 1 3 woot | 24 | data="42 1 3 woot |
@@ -48,7 +46,7 @@ egg 1 2 papyrus | |||
48 | 999 3 0 algebra | 46 | 999 3 0 algebra |
49 | " "$data" "" | 47 | " "$data" "" |
50 | 48 | ||
51 | # Busybox is definitely doing this one wrong just now... | 49 | # Busybox is definitely doing this one wrong just now. FIXME |
52 | 50 | ||
53 | testing "sort key range with numeric option and global reverse" \ | 51 | testing "sort key range with numeric option and global reverse" \ |
54 | "-k2,3n -r input" \ | 52 | "-k2,3n -r input" \ |
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 | |||
22 | verbose=0 | ||
23 | debug=0 | ||
24 | force=0 | ||
25 | for 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 | ||
34 | done | ||
35 | 29 | ||
36 | if [ -n "$VERBOSE" ] ; then | 30 | # The "optional" function is used to skip certain tests, ala: |
37 | verbose=1 | 31 | # optionflag CONFIG_FEATURE_THINGY |
38 | fi | 32 | # |
39 | if [ -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 |
41 | fi | 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 | ||
43 | export FAILCOUNT=0 | 38 | export FAILCOUNT=0 |
39 | export SKIP= | ||
44 | 40 | ||
45 | # Helper functions | 41 | # Helper functions |
46 | 42 | ||
47 | config_is_set () | 43 | optional() |
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 | ||
diff --git a/testsuite/uniq.tests b/testsuite/uniq.tests index 27d9561e1..95764740b 100755 --- a/testsuite/uniq.tests +++ b/testsuite/uniq.tests | |||
@@ -9,9 +9,6 @@ | |||
9 | if [ ${#COMMAND} -eq 0 ]; then COMMAND=uniq; fi | 9 | if [ ${#COMMAND} -eq 0 ]; then COMMAND=uniq; fi |
10 | . testing.sh | 10 | . testing.sh |
11 | 11 | ||
12 | # Depends on uniq | ||
13 | _BB_CONFIG_DEP=uniq | ||
14 | |||
15 | # testing "test name" "options" "expected result" "file input" "stdin" | 12 | # testing "test name" "options" "expected result" "file input" "stdin" |
16 | # file input will be file called "input" | 13 | # file input will be file called "input" |
17 | # test can create a file "actual" instead of writing to stdout | 14 | # test can create a file "actual" instead of writing to stdout |