diff options
author | Rob Landley <rob@landley.net> | 2005-09-02 00:41:53 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2005-09-02 00:41:53 +0000 |
commit | 1689075c992a45a4a50f1aaad8aaf1d2983060c8 (patch) | |
tree | 679fa07497ea54120459a76464d3257862537b2e /testsuite | |
parent | babd3fbba668e04841cbe683ca49097fb871fca8 (diff) | |
download | busybox-w32-1689075c992a45a4a50f1aaad8aaf1d2983060c8.tar.gz busybox-w32-1689075c992a45a4a50f1aaad8aaf1d2983060c8.tar.bz2 busybox-w32-1689075c992a45a4a50f1aaad8aaf1d2983060c8.zip |
Working on a new test harness. Moved the sort tests into it.
Diffstat (limited to 'testsuite')
-rwxr-xr-x | testsuite/runtest | 10 | ||||
-rwxr-xr-x | testsuite/sort.tests | 69 | ||||
-rwxr-xr-x | testsuite/testing.sh | 62 |
3 files changed, 141 insertions, 0 deletions
diff --git a/testsuite/runtest b/testsuite/runtest index 6ba334bce..91b794317 100755 --- a/testsuite/runtest +++ b/testsuite/runtest | |||
@@ -97,6 +97,16 @@ for applet in $applets; do | |||
97 | status=1 | 97 | status=1 |
98 | fi | 98 | fi |
99 | fi | 99 | fi |
100 | |||
101 | if [ -f "$applet".tests ] | ||
102 | then | ||
103 | rm -f links/"$applet" | ||
104 | ln -s ../../busybox links/"$applet" | ||
105 | PATH=links:$PATH ./"$applet".tests | ||
106 | if [ $? -ne 0 ]; then status=1; fi | ||
107 | fi | ||
108 | |||
109 | |||
100 | done | 110 | done |
101 | 111 | ||
102 | exit $status | 112 | exit $status |
diff --git a/testsuite/sort.tests b/testsuite/sort.tests new file mode 100755 index 000000000..b23cf4312 --- /dev/null +++ b/testsuite/sort.tests | |||
@@ -0,0 +1,69 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | # SUSv3 compliant sort tests. | ||
4 | # Copyright 2005 by Rob Landley <rob@landley.net> | ||
5 | # Licensed under GPL v2, see file LICENSE for details. | ||
6 | |||
7 | if [ ${#COMMAND} -eq 0 ]; then COMMAND=sort; fi | ||
8 | . testing.sh | ||
9 | |||
10 | # The basic tests. These should work even with the small busybox. | ||
11 | |||
12 | testing "sort" "input" "a\nb\nc\n" "c\na\nb\n" "" | ||
13 | testing "sort #2" "input" "010\n1\n3\n" "3\n1\n010\n" "" | ||
14 | testing "sort stdin" "" "a\nb\nc\n" "" "b\na\nc\n" | ||
15 | testing "sort numeric" "-n input" "1\n3\n010\n" "3\n1\n010\n" "" | ||
16 | testing "sort reverse" "-r input" "wook\nwalrus\npoint\npabst\naargh\n" \ | ||
17 | "point\nwook\npabst\naargh\nwalrus\n" "" | ||
18 | |||
19 | # These tests require the full option set. | ||
20 | |||
21 | # Longish chunk of data re-used by the next few tests | ||
22 | |||
23 | data="42 1 3 woot | ||
24 | 42 1 010 zoology | ||
25 | egg 1 2 papyrus | ||
26 | 7 3 42 soup | ||
27 | 999 3 0 algebra | ||
28 | " | ||
29 | |||
30 | # Sorting with keys | ||
31 | |||
32 | testing "sort one key" "-k4,4 input" \ | ||
33 | "999 3 0 algebra | ||
34 | egg 1 2 papyrus | ||
35 | 7 3 42 soup | ||
36 | 42 1 3 woot | ||
37 | 42 1 010 zoology | ||
38 | " "$data" "" | ||
39 | |||
40 | testing "sort key range with numeric option" "-k2,3n input" \ | ||
41 | "42 1 010 zoology | ||
42 | 42 1 3 woot | ||
43 | egg 1 2 papyrus | ||
44 | 7 3 42 soup | ||
45 | 999 3 0 algebra | ||
46 | " "$data" "" | ||
47 | |||
48 | # Busybox is definitely doing this one wrong just now... | ||
49 | |||
50 | testing "sort key range with numeric option and global reverse" \ | ||
51 | "-k2,3n -r input" \ | ||
52 | "egg 1 2 papyrus | ||
53 | 42 1 3 woot | ||
54 | 42 1 010 zoology | ||
55 | 999 3 0 algebra | ||
56 | 7 3 42 soup | ||
57 | " "$data" "" | ||
58 | |||
59 | # | ||
60 | |||
61 | testing "sort key range with multiple options" "-k2,3rn input" \ | ||
62 | "7 3 42 soup | ||
63 | 999 3 0 algebra | ||
64 | 42 1 010 zoology | ||
65 | 42 1 3 woot | ||
66 | egg 1 2 papyrus | ||
67 | " "$data" "" | ||
68 | |||
69 | exit $FAILCOUNT | ||
diff --git a/testsuite/testing.sh b/testsuite/testing.sh new file mode 100755 index 000000000..d516f722a --- /dev/null +++ b/testsuite/testing.sh | |||
@@ -0,0 +1,62 @@ | |||
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] | ||
51 | echo FAIL:"$1" | ||
52 | if [ $verbose ] | ||
53 | then | ||
54 | diff -u expected actual | ||
55 | fi | ||
56 | else | ||
57 | echo PASS:"$1" | ||
58 | fi | ||
59 | rm -f input expected actual | ||
60 | |||
61 | return $RETVAL | ||
62 | } | ||