aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2006-03-16 15:20:45 +0000
committerRob Landley <rob@landley.net>2006-03-16 15:20:45 +0000
commit4bb1b04fd1d7d6fe410e1af14816d11da456aac5 (patch)
tree601a54598057fc267def41fce1acecfb8e5a2845
parentea9a471acd94f604f360ea16df5896e795361ac7 (diff)
downloadbusybox-w32-4bb1b04fd1d7d6fe410e1af14816d11da456aac5.tar.gz
busybox-w32-4bb1b04fd1d7d6fe410e1af14816d11da456aac5.tar.bz2
busybox-w32-4bb1b04fd1d7d6fe410e1af14816d11da456aac5.zip
Redo test suite to be able to test more than one command at a time. Eliminate
$COMMAND environment variable, instead put full command line (including command to run) in second argument. Modify $PATH to have test versions of commands at start of path. (Also more infrastructure for testing as root, work in progress...)
-rwxr-xr-xtestsuite/busybox.tests56
-rwxr-xr-xtestsuite/egrep.tests19
-rwxr-xr-xtestsuite/grep.tests42
-rwxr-xr-xtestsuite/pidof.tests18
-rwxr-xr-xtestsuite/sed.tests121
-rwxr-xr-xtestsuite/sort.tests19
-rwxr-xr-xtestsuite/testing.sh63
-rwxr-xr-xtestsuite/uniq.tests25
8 files changed, 189 insertions, 174 deletions
diff --git a/testsuite/busybox.tests b/testsuite/busybox.tests
index f31f38f06..30d96f946 100755
--- a/testsuite/busybox.tests
+++ b/testsuite/busybox.tests
@@ -4,57 +4,55 @@
4# Copyright 2005 by Rob Landley <rob@landley.net> 4# Copyright 2005 by Rob Landley <rob@landley.net>
5# Licensed under GPL v2, see file LICENSE for details. 5# Licensed under GPL v2, see file LICENSE for details.
6 6
7if [ ${#COMMAND} -eq 0 ]; then COMMAND=busybox; fi
8. testing.sh 7. testing.sh
9 8
10HELPDUMP=`$COMMAND` 9# verify the applet order is correct in applets.h, otherwise applets won't
10# be called properly.
11#sed -n -e '/^USE_^\tAPPLET/{s:.*(::;s:,.*::;s:"::g;p}'
12# ../include/applets.h > applet.order1
13#LC_ALL=C sort applet.order.current > applet.order.correct
14#diff -u applet.order.current applet.order.correct
15#FAILCOUNT=$[$FAILCOUNT+$?]
16#rm -f applet.order.current applet.order.correct
17
18
19
20
21HELPDUMP=`busybox`
11 22
12# We need to test under calling the binary under other names. 23# We need to test under calling the binary under other names.
13 24
14ln -s `which "$COMMAND"` busybox-suffix
15ln -s `which "$COMMAND"` unknown
16 25
17testing "busybox --help busybox" "--help busybox" "$HELPDUMP\n\n" "" "" 26testing "busybox --help busybox" "busybox --help busybox" "$HELPDUMP\n\n" "" ""
18 27
19for i in busybox busybox-suffix 28ln -s `which busybox` busybox-suffix
29for i in busybox ./busybox-suffix
20do 30do
21 # The gratuitous "\n"s are due to a shell idiosyncrasy: 31 # The gratuitous "\n"s are due to a shell idiosyncrasy:
22 # environment variables seem to strip trailing whitespace. 32 # environment variables seem to strip trailing whitespace.
23 33
24 testing "$i" "" "$HELPDUMP\n\n" "" "" 34 testing "" "$i" "$HELPDUMP\n\n" "" ""
25 35
26 testing "$i unknown" "unknown 2>&1" \ 36 testing "$i unknown" "$i unknown 2>&1" \
27 "unknown: applet not found\n" "" "" 37 "unknown: applet not found\n" "" ""
28 38
29 testing "$i --help" "--help 2>&1" "$HELPDUMP\n\n" "" "" 39 testing "$i --help" "$i --help 2>&1" "$HELPDUMP\n\n" "" ""
30 40
31 optional CAT 41 optional CAT
32 testing "$i cat" "cat" "moo" "" "moo" 42 testing "" "$i cat" "moo" "" "moo"
33 testing "$i --help cat" "--help cat 2>&1 | grep prints" \ 43 testing "$i --help cat" "$i --help cat 2>&1 | grep prints" \
34 "Concatenates FILE(s) and prints them to stdout.\n" "" "" 44 "Concatenates FILE(s) and prints them to stdout.\n" "" ""
35 optional "" 45 optional ""
36 46
37 testing "$i --help unknown" "--help unknown 2>&1" \ 47 testing "$i --help unknown" "$i --help unknown 2>&1" \
38 "unknown: applet not found\n" "" "" 48 "unknown: applet not found\n" "" ""
39
40 COMMAND=./busybox-suffix
41done 49done
50rm busybox-suffix
42 51
43COMMAND="./unknown" 52ln -s `which busybox` unknown
44testing "busybox as unknown name" "2>&1" "unknown: applet not found\n" "" ""
45
46rm -f busybox-suffix unknown
47
48
49# verify the applet order is correct in applets.h
50# otherwise applets wont be called properly
51sed -n \
52 -e '/^\tAPPLET/{s:.*(::;s:,.*::;s:"::g;p}' \
53 ../include/applets.h > applet.order.current
54LC_ALL=C sort applet.order.current > applet.order.correct
55diff -u applet.order.current applet.order.correct
56FAILCOUNT=$[$FAILCOUNT+$?]
57rm -f applet.order.current applet.order.correct
58 53
54testing "busybox as unknown name" "./unknown 2>&1" \
55 "unknown: applet not found\n" "" ""
56rm unknown
59 57
60exit $FAILCOUNT 58exit $FAILCOUNT
diff --git a/testsuite/egrep.tests b/testsuite/egrep.tests
deleted file mode 100755
index 61ce009d7..000000000
--- a/testsuite/egrep.tests
+++ /dev/null
@@ -1,19 +0,0 @@
1#!/bin/sh
2
3# egrep tests.
4# Copyright 2005 by Rob Landley <rob@landley.net>
5# Licensed under GPL v2, see file LICENSE for details.
6
7# AUDIT:
8
9[ ${#COMMAND} -eq 0 ] && COMMAND=egrep
10. testing.sh
11
12optional FEATURE_GREP_EGREP_ALIAS
13
14testing "grep is also egrep" "foo" "foo\n" "" "foo\nbar\n"
15testing "egrep is not case insensitive" "foo ; [ \$? -ne 0 ] && echo yes" \
16 "yes\n" "" "FOO\n"
17
18
19exit $FAILCOUNT
diff --git a/testsuite/grep.tests b/testsuite/grep.tests
index 2a7a7b901..cc9520e90 100755
--- a/testsuite/grep.tests
+++ b/testsuite/grep.tests
@@ -6,7 +6,6 @@
6 6
7# AUDIT: 7# AUDIT:
8 8
9[ ${#COMMAND} -eq 0 ] && COMMAND=grep
10. testing.sh 9. testing.sh
11 10
12# testing "test name" "options" "expected result" "file input" "stdin" 11# testing "test name" "options" "expected result" "file input" "stdin"
@@ -15,64 +14,69 @@
15 14
16# Test exit status 15# Test exit status
17 16
18testing "grep (exit with error)" "nonexistent 2> /dev/null ; echo \$?" \ 17testing "grep (exit with error)" "grep nonexistent 2> /dev/null ; echo \$?" \
19 "1\n" "" "" 18 "1\n" "" ""
20testing "grep (exit success)" "grep $0 > /dev/null 2>&1 ; echo \$?" "0\n" \ 19testing "grep (exit success)" "grep grep $0 > /dev/null 2>&1 ; echo \$?" "0\n" \
21 "" "" 20 "" ""
22# Test various data sources and destinations 21# Test various data sources and destinations
23 22
24testing "grep (default to stdin)" "two" "two\n" "" \ 23testing "grep (default to stdin)" "grep two" "two\n" "" \
25 "one\ntwo\nthree\nthree\nthree\n" 24 "one\ntwo\nthree\nthree\nthree\n"
26testing "grep - (specify stdin)" "two -" "two\n" "" \ 25testing "grep - (specify stdin)" "grep two -" "two\n" "" \
27 "one\ntwo\nthree\nthree\nthree\n" 26 "one\ntwo\nthree\nthree\nthree\n"
28testing "grep input (specify file)" "two input" "two\n" \ 27testing "grep input (specify file)" "grep two input" "two\n" \
29 "one\ntwo\nthree\nthree\nthree\n" "" 28 "one\ntwo\nthree\nthree\nthree\n" ""
30 29
31# Note that this assumes actual is empty. 30# Note that this assumes actual is empty.
32testing "grep input actual (two files)" "two input actual 2> /dev/null" \ 31testing "grep input actual (two files)" "grep two input actual 2> /dev/null" \
33 "input:two\n" "one\ntwo\nthree\nthree\nthree\n" "" 32 "input:two\n" "one\ntwo\nthree\nthree\nthree\n" ""
34 33
35testing "grep - infile (specify stdin and file)" "two - input" \ 34testing "grep - infile (specify stdin and file)" "grep two - input" \
36 "(standard input):two\ninput:two\n" "one\ntwo\nthree\n" \ 35 "(standard input):two\ninput:two\n" "one\ntwo\nthree\n" \
37 "one\ntwo\ntoo\nthree\nthree\n" 36 "one\ntwo\ntoo\nthree\nthree\n"
38 37
39# Check if we see the correct return value if both stdin and non-existing file 38# Check if we see the correct return value if both stdin and non-existing file
40# are given. 39# are given.
41testing "grep - nofile (specify stdin and nonexisting file)" \ 40testing "grep - nofile (specify stdin and nonexisting file)" \
42 "two - nonexistent 2> /dev/null ; echo \$?" \ 41 "grep two - nonexistent 2> /dev/null ; echo \$?" \
43 "(standard input):two\n(standard input):two\n2\n" \ 42 "(standard input):two\n(standard input):two\n2\n" \
44 "" "one\ntwo\ntwo\nthree\nthree\nthree\n" 43 "" "one\ntwo\ntwo\nthree\nthree\nthree\n"
45testing "grep -q - nofile (specify stdin and nonexisting file, no match)" \ 44testing "grep -q - nofile (specify stdin and nonexisting file, no match)" \
46 "-q nomatch - nonexistent 2> /dev/null ; echo \$?" \ 45 "grep -q nomatch - nonexistent 2> /dev/null ; echo \$?" \
47 "2\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n" 46 "2\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n"
48# SUSv3: If the -q option is specified, the exit status shall be zero 47# SUSv3: If the -q option is specified, the exit status shall be zero
49# if an input line is selected, even if an error was detected. 48# if an input line is selected, even if an error was detected.
50testing "grep -q - nofile (specify stdin and nonexisting file, match)" \ 49testing "grep -q - nofile (specify stdin and nonexisting file, match)" \
51 "-q two - nonexistent ; echo \$?" \ 50 "grep -q two - nonexistent ; echo \$?" \
52 "0\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n" 51 "0\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n"
53 52
54# Test various command line options 53# Test various command line options
55# -s no error messages 54# -s no error messages
56testing "grep -s nofile (nonexisting file, no match)" \ 55testing "grep -s nofile (nonexisting file, no match)" \
57 "-s nomatch nonexistent ; echo \$?" "2\n" "" "" 56 "grep -s nomatch nonexistent ; echo \$?" "2\n" "" ""
58testing "grep -s nofile - (stdin and nonexisting file, match)" \ 57testing "grep -s nofile - (stdin and nonexisting file, match)" \
59 "-s domatch nonexistent - ; echo \$?" "(standard input):domatch\n2\n" \ 58 "grep -s domatch nonexistent - ; echo \$?" \
60 "" "nomatch\ndomatch\nend\n" 59 "(standard input):domatch\n2\n" "" "nomatch\ndomatch\nend\n"
61 60
62# This doesn't match GNU behaviour (Binary file input matches) 61# This doesn't match GNU behaviour (Binary file input matches)
63# acts like GNU grep -a 62# acts like GNU grep -a
64testing "grep handles binary files" "foo input" "foo\n" "\0foo\n\n" "" 63testing "grep handles binary files" "grep foo input" "foo\n" "\0foo\n\n" ""
65# This doesn't match GNU behaviour (Binary file (standard input) matches) 64# This doesn't match GNU behaviour (Binary file (standard input) matches)
66# acts like GNU grep -a 65# acts like GNU grep -a
67testing "grep handles binary stdin" "foo" "foo\n" "" "\0foo\n\n" 66testing "grep handles binary stdin" "grep foo" "foo\n" "" "\0foo\n\n"
68 67
69testing "grep matches NUL" ". input > /dev/null 2>&1 ; echo \$?" "0\n" "\0\n" "" 68testing "grep matches NUL" "grep . input > /dev/null 2>&1 ; echo \$?" \
69 "0\n" "\0\n" ""
70 70
71# -e regex 71# -e regex
72testing "grep handles multiple regexps" "-e one -e two input ; echo \$?" \ 72testing "grep handles multiple regexps" "grep -e one -e two input ; echo \$?" \
73 "one\ntwo\n0\n" "one\ntwo\n" "" 73 "one\ntwo\n0\n" "one\ntwo\n" ""
74 74
75optional FEATURE_GREP_EGREP_ALIAS 75optional FEATURE_GREP_EGREP_ALIAS
76testing "grep -E supports extended regexps" "-E fo+" "foo\n" "" "b\ar\nfoo\nbaz" 76testing "grep -E supports extended regexps" "grep -E fo+" "foo\n" "" \
77 "b\ar\nfoo\nbaz"
78testing "grep is also egrep" "egrep foo" "foo\n" "" "foo\nbar\n"
79testing "egrep is not case insensitive" \
80 "egrep foo ; [ \$? -ne 0 ] && echo yes" "yes\n" "" "FOO\n"
77 81
78exit $FAILCOUNT 82exit $FAILCOUNT
diff --git a/testsuite/pidof.tests b/testsuite/pidof.tests
index 0515522f8..831dd2483 100755
--- a/testsuite/pidof.tests
+++ b/testsuite/pidof.tests
@@ -6,22 +6,24 @@
6 6
7# AUDIT: 7# AUDIT:
8 8
9[ ${#COMMAND} -eq 0 ] && COMMAND=pidof
10. testing.sh 9. testing.sh
11 10
12# testing "test name" "options" "expected result" "file input" "stdin" 11# testing "test name" "options" "expected result" "file input" "stdin"
13 12
14testing "pidof (exit with error)" "veryunlikelyoccuringbinaryname ; echo \$?" \ 13testing "pidof (exit with error)" \
15 "\n1\n" "" "" 14 "pidof veryunlikelyoccuringbinaryname ; echo \$?" "1\n" "" ""
16testing "pidof (exit with success)" "pidof > /dev/null; echo \$?" "0\n" "" "" 15testing "pidof (exit with success)" "pidof pidof > /dev/null; echo \$?" \
16 "0\n" "" ""
17# We can get away with this because it says #!/bin/sh up top.
17 18
19testing "pidof this" "pidof pidof.tests | grep -o -w $$" "$$\n" "" ""
18 20
19optional FEATURE_PIDOF_SINGLE 21optional FEATURE_PIDOF_SINGLE
20testing "pidof -s" "-s $(basename $0) ; echo -n \$?" \ 22testing "pidof -s" "pidof -s init" "1\n" "" ""
21 "$(pidof -s $(basename $0) ; echo -n $?)" "" ""
22 23
23optional FEATURE_PIDOF_OMIT 24optional FEATURE_PIDOF_OMIT
24testing "pidof -o %PPID" "$(basename $0) -o %PPID ; echo -n \$?" \ 25testing "pidof -o %PPID" "pidof -o %PPID pidof.tests | grep -o -w $$" "" "" ""
25 "$(pidof $(basename $0) -o %PPID ; echo -n $?)" "" "" 26testing "pidof -o %PPID NOP" "pidof -o %PPID -s init" "1\n" "" ""
27testing "pidof -o init" "pidof -o 1 init | grep -o -w 1" "" "" ""
26 28
27exit $FAILCOUNT 29exit $FAILCOUNT
diff --git a/testsuite/sed.tests b/testsuite/sed.tests
index 6fcaa19df..4d6e2e67e 100755
--- a/testsuite/sed.tests
+++ b/testsuite/sed.tests
@@ -4,16 +4,15 @@
4# Copyright 2005 by Rob Landley <rob@landley.net> 4# Copyright 2005 by Rob Landley <rob@landley.net>
5# Licensed under GPL v2, see file LICENSE for details. 5# Licensed under GPL v2, see file LICENSE for details.
6 6
7[ -z "$COMMAND" ] && COMMAND=sed
8. testing.sh 7. testing.sh
9 8
10# testing "description" "arguments" "result" "infile" "stdin" 9# testing "description" "arguments" "result" "infile" "stdin"
11 10
12# Corner cases 11# Corner cases
13testing "sed no files (stdin)" '""' "hello\n" "" "hello\n" 12testing "sed no files (stdin)" 'sed ""' "hello\n" "" "hello\n"
14testing "sed explicit stdin" '"" -' "hello\n" "" "hello\n" 13testing "sed explicit stdin" 'sed "" -' "hello\n" "" "hello\n"
15testing "sed handles empty lines" "-e 's/\$/@/'" "@\n" "" "\n" 14testing "sed handles empty lines" "sed -e 's/\$/@/'" "@\n" "" "\n"
16testing "sed stdin twice" '"" - -' "hello" "" "hello" 15testing "sed stdin twice" 'sed "" - -' "hello" "" "hello"
17 16
18# Trailing EOF. 17# Trailing EOF.
19# Match $, at end of each file or all files? 18# Match $, at end of each file or all files?
@@ -39,139 +38,145 @@ testing "sed stdin twice" '"" - -' "hello" "" "hello"
39# End of script with trailing \ 38# End of script with trailing \
40 39
41# command list 40# command list
42testing "sed accepts blanks before command" "-e '1 d'" "" "" "" 41testing "sed accepts blanks before command" "sed -e '1 d'" "" "" ""
43testing "sed accepts newlines in -e" "-e 'i\ 42testing "sed accepts newlines in -e" "sed -e 'i\
441 431
45a\ 44a\
463'" "1\n2\n3\n" "" "2\n" 453'" "1\n2\n3\n" "" "2\n"
47testing "sed accepts multiple -e" "-e 'i\' -e '1' -e 'a\' -e '3'" \ 46testing "sed accepts multiple -e" "sed -e 'i\' -e '1' -e 'a\' -e '3'" \
48 "1\n2\n3\n" "" "2\n" 47 "1\n2\n3\n" "" "2\n"
49 48
50# substitutions 49# substitutions
51testing "sed -n" "-n -e s/foo/bar/ -e s/bar/baz/" "" "" "foo\n" 50testing "sed -n" "sed -n -e s/foo/bar/ -e s/bar/baz/" "" "" "foo\n"
52testing "sed s//p" "-e s/foo/bar/p -e s/bar/baz/p" "bar\nbaz\nbaz\n" \ 51testing "sed s//p" "sed -e s/foo/bar/p -e s/bar/baz/p" "bar\nbaz\nbaz\n" \
53 "" "foo\n" 52 "" "foo\n"
54testing "sed -n s//p" "-ne s/abc/def/p" "def\n" "" "abc\n" 53testing "sed -n s//p" "sed -ne s/abc/def/p" "def\n" "" "abc\n"
55testing "sed s//g (exhaustive)" "-e 's/[[:space:]]*/,/g'" ",1,2,3,4,5,\n" \ 54testing "sed s//g (exhaustive)" "sed -e 's/[[:space:]]*/,/g'" ",1,2,3,4,5,\n" \
56 "" "12345\n" 55 "" "12345\n"
57testing "sed s arbitrary delimiter" "-e 's woo boing '" "boing\n" "" "woo\n" 56testing "sed s arbitrary delimiter" "sed -e 's woo boing '" "boing\n" "" "woo\n"
58testing "sed s chains" "-e s/foo/bar/ -e s/bar/baz/" "baz\n" "" "foo\n" 57testing "sed s chains" "sed -e s/foo/bar/ -e s/bar/baz/" "baz\n" "" "foo\n"
59testing "sed s chains2" "-e s/foo/bar/ -e s/baz/nee/" "bar\n" "" "foo\n" 58testing "sed s chains2" "sed -e s/foo/bar/ -e s/baz/nee/" "bar\n" "" "foo\n"
60testing "sed s [delimiter]" "-e 's@[@]@@'" "onetwo" "" "one@two" 59testing "sed s [delimiter]" "sed -e 's@[@]@@'" "onetwo" "" "one@two"
61 60
62# branch 61# branch
63testing "sed b (branch)" "-e 'b one;p;: one'" "foo\n" "" "foo\n" 62testing "sed b (branch)" "sed -e 'b one;p;: one'" "foo\n" "" "foo\n"
64testing "sed b (branch with no label jumps to end)" "-e 'b;p'" \ 63testing "sed b (branch with no label jumps to end)" "sed -e 'b;p'" \
65 "foo\n" "" "foo\n" 64 "foo\n" "" "foo\n"
66 65
67# test and branch 66# test and branch
68testing "sed t (test/branch)" "-e 's/a/1/;t one;p;: one;p'" \ 67testing "sed t (test/branch)" "sed -e 's/a/1/;t one;p;: one;p'" \
69 "1\n1\nb\nb\nb\nc\nc\nc\n" "" "a\nb\nc\n" 68 "1\n1\nb\nb\nb\nc\nc\nc\n" "" "a\nb\nc\n"
70testing "sed t (test/branch clears test bit)" "-e 's/a/b/;:loop;t loop'" \ 69testing "sed t (test/branch clears test bit)" "sed -e 's/a/b/;:loop;t loop'" \
71 "b\nb\nc\n" "" "a\nb\nc\n" 70 "b\nb\nc\n" "" "a\nb\nc\n"
72testing "sed T (!test/branch)" "-e 's/a/1/;T notone;p;: notone;p'" \ 71testing "sed T (!test/branch)" "sed -e 's/a/1/;T notone;p;: notone;p'" \
73 "1\n1\n1\nb\nb\nc\nc\n" "" "a\nb\nc\n" 72 "1\n1\n1\nb\nb\nc\nc\n" "" "a\nb\nc\n"
74 73
75# Normal sed end-of-script doesn't print "c" because n flushed the pattern 74# Normal sed end-of-script doesn't print "c" because n flushed the pattern
76# space. If n hits EOF, pattern space is empty when script ends. 75# space. If n hits EOF, pattern space is empty when script ends.
77# Query: how does this interact with no newline at EOF? 76# Query: how does this interact with no newline at EOF?
78testing "sed n (flushes pattern space, terminates early)" "-e 'n;p'" \ 77testing "sed n (flushes pattern space, terminates early)" "sed -e 'n;p'" \
79 "a\nb\nb\nc\n" "" "a\nb\nc\n" 78 "a\nb\nb\nc\n" "" "a\nb\nc\n"
80# N does _not_ flush pattern space, therefore c is still in there @ script end. 79# N does _not_ flush pattern space, therefore c is still in there @ script end.
81testing "sed N (doesn't flush pattern space when terminating)" "-e 'N;p'" \ 80testing "sed N (doesn't flush pattern space when terminating)" "sed -e 'N;p'" \
82 "a\nb\na\nb\nc\n" "" "a\nb\nc\n" 81 "a\nb\na\nb\nc\n" "" "a\nb\nc\n"
83testing "sed address match newline" '"/b/N;/b\\nc/i woo"' "a\nwoo\nb\nc\nd\n" \ 82testing "sed address match newline" 'sed "/b/N;/b\\nc/i woo"' \
84 "" "a\nb\nc\nd\n" 83 "a\nwoo\nb\nc\nd\n" "" "a\nb\nc\nd\n"
85 84
86# Multiple lines in pattern space 85# Multiple lines in pattern space
87testing "sed N (stops at end of input) and P (prints to first newline only)" \ 86testing "sed N (stops at end of input) and P (prints to first newline only)" \
88 "-n 'N;P;p'" "a\na\nb\n" "" "a\nb\nc\n" 87 "sed -n 'N;P;p'" "a\na\nb\n" "" "a\nb\nc\n"
89 88
90# Hold space 89# Hold space
91testing "sed G (append hold space to pattern space)" 'G' "a\n\nb\n\nc\n\n" \ 90testing "sed G (append hold space to pattern space)" 'sed G' "a\n\nb\n\nc\n\n" \
92 "" "a\nb\nc\n" 91 "" "a\nb\nc\n"
93#testing "sed g/G (swap/append hold and patter space)" 92#testing "sed g/G (swap/append hold and patter space)"
94#testing "sed g (swap hold/pattern space)" 93#testing "sed g (swap hold/pattern space)"
95 94
96testing "sed d ends script iteration" \ 95testing "sed d ends script iteration" \
97 "-e '/ook/d;s/ook/ping/p;i woot'" "" "" "ook\n" 96 "sed -e '/ook/d;s/ook/ping/p;i woot'" "" "" "ook\n"
98testing "sed d ends script iteration (2)" \ 97testing "sed d ends script iteration (2)" \
99 "-e '/ook/d;a\' -e 'bang'" "woot\nbang\n" "" "ook\nwoot\n" 98 "sed -e '/ook/d;a\' -e 'bang'" "woot\nbang\n" "" "ook\nwoot\n"
100 99
101# Multiple files, with varying newlines and NUL bytes 100# Multiple files, with varying newlines and NUL bytes
102testing "sed embedded NUL" "-e 's/woo/bang/'" "\0bang\0woo\0" "" "\0woo\0woo\0" 101testing "sed embedded NUL" "sed -e 's/woo/bang/'" "\0bang\0woo\0" "" \
103testing "sed embedded NUL g" "-e 's/woo/bang/g'" "bang\0bang\0" "" "woo\0woo\0" 102 "\0woo\0woo\0"
103testing "sed embedded NUL g" "sed -e 's/woo/bang/g'" "bang\0bang\0" "" \
104 "woo\0woo\0"
104echo -e "/woo/a he\0llo" > sed.commands 105echo -e "/woo/a he\0llo" > sed.commands
105testing "sed NUL in command" "-f sed.commands" "woo\nhe\0llo\n" "" "woo" 106testing "sed NUL in command" "sed -f sed.commands" "woo\nhe\0llo\n" "" "woo"
106rm sed.commands 107rm sed.commands
107 108
108# sed has funky behavior with newlines at the end of file. Test lots of 109# sed has funky behavior with newlines at the end of file. Test lots of
109# corner cases with the optional newline appending behavior. 110# corner cases with the optional newline appending behavior.
110 111
111testing "sed normal newlines" "-e 's/woo/bang/' input -" "bang\nbang\n" \ 112testing "sed normal newlines" "sed -e 's/woo/bang/' input -" "bang\nbang\n" \
112 "woo\n" "woo\n" 113 "woo\n" "woo\n"
113testing "sed leave off trailing newline" "-e 's/woo/bang/' input -" \ 114testing "sed leave off trailing newline" "sed -e 's/woo/bang/' input -" \
114 "bang\nbang" "woo\n" "woo" 115 "bang\nbang" "woo\n" "woo"
115testing "sed autoinsert newline" "-e 's/woo/bang/' input -" "bang\nbang" \ 116testing "sed autoinsert newline" "sed -e 's/woo/bang/' input -" "bang\nbang" \
116 "woo" "woo" 117 "woo" "woo"
117testing "sed empty file plus cat" "-e 's/nohit//' input -" "one\ntwo" \ 118testing "sed empty file plus cat" "sed -e 's/nohit//' input -" "one\ntwo" \
118 "" "one\ntwo" 119 "" "one\ntwo"
119testing "sed cat plus empty file" "-e 's/nohit//' input -" "one\ntwo" \ 120testing "sed cat plus empty file" "sed -e 's/nohit//' input -" "one\ntwo" \
120 "one\ntwo" "" 121 "one\ntwo" ""
121testing "sed append autoinserts newline" "-e '/woot/a woo' -" "woot\nwoo\n" \ 122testing "sed append autoinserts newline" "sed -e '/woot/a woo' -" \
122 "" "woot" 123 "woot\nwoo\n" "" "woot"
123testing "sed insert doesn't autoinsert newline" "-e '/woot/i woo' -" \ 124testing "sed insert doesn't autoinsert newline" "sed -e '/woot/i woo' -" \
124 "woo\nwoot" "" "woot" 125 "woo\nwoot" "" "woot"
125testing "sed print autoinsert newlines" "-e 'p' -" "one\none" "" "one" 126testing "sed print autoinsert newlines" "sed -e 'p' -" "one\none" "" "one"
126testing "sed print autoinsert newlines two files" "-e 'p' input -" \ 127testing "sed print autoinsert newlines two files" "sed -e 'p' input -" \
127 "one\none\ntwo\ntwo" "one" "two" 128 "one\none\ntwo\ntwo" "one" "two"
128testing "sed noprint, no match, no newline" "-ne 's/woo/bang/' input" \ 129testing "sed noprint, no match, no newline" "sed -ne 's/woo/bang/' input" \
129 "" "no\n" "" 130 "" "no\n" ""
130testing "sed selective matches with one nl" "-ne 's/woo/bang/p' input -" \ 131testing "sed selective matches with one nl" "sed -ne 's/woo/bang/p' input -" \
131 "a bang\nc bang\n" "a woo\nb no" "c woo\nd no" 132 "a bang\nc bang\n" "a woo\nb no" "c woo\nd no"
132testing "sed selective matches insert newline" "-ne 's/woo/bang/p' input -" \ 133testing "sed selective matches insert newline" \
133 "a bang\nb bang\nd bang" "a woo\nb woo" "c no\nd woo" 134 "sed -ne 's/woo/bang/p' input -" "a bang\nb bang\nd bang" \
134testing "sed selective matches noinsert newline" "-ne 's/woo/bang/p' input -" \ 135 "a woo\nb woo" "c no\nd woo"
135 "a bang\nb bang" "a woo\nb woo" "c no\nd no" 136testing "sed selective matches noinsert newline" \
136testing "sed clusternewline" "-e '/one/a 111' -e '/two/i 222' -e p input -" \ 137 "sed -ne 's/woo/bang/p' input -" "a bang\nb bang" "a woo\nb woo" \
138 "c no\nd no"
139testing "sed clusternewline" \
140 "sed -e '/one/a 111' -e '/two/i 222' -e p input -" \
137 "one\none\n111\n222\ntwo\ntwo" "one" "two" 141 "one\none\n111\n222\ntwo\ntwo" "one" "two"
138 142
139# Test end-of-file matching behavior 143# Test end-of-file matching behavior
140 144
141testing "sed match EOF" " -e '"'$p'"'" "hello\nthere\nthere" "" "hello\nthere" 145testing "sed match EOF" "sed -e '"'$p'"'" "hello\nthere\nthere" "" \
142testing "sed match EOF two files" " -e '"'$p'"' input -" \ 146 "hello\nthere"
147testing "sed match EOF two files" "sed -e '"'$p'"' input -" \
143 "one\ntwo\nthree\nfour\nfour" "one\ntwo" "three\nfour" 148 "one\ntwo\nthree\nfour\nfour" "one\ntwo" "three\nfour"
144echo -ne "three\nfour" > input2 149echo -ne "three\nfour" > input2
145testing "sed match EOF inline" \ 150testing "sed match EOF inline" \
146 " -e '"'$i ook'"' -i input input2 && cat input input2" \ 151 "sed -e '"'$i ook'"' -i input input2 && cat input input2" \
147 "one\nook\ntwothree\nook\nfour" "one\ntwo" "" 152 "one\nook\ntwothree\nook\nfour" "one\ntwo" ""
148rm input2 153rm input2
149 154
150# Test lie-to-autoconf 155# Test lie-to-autoconf
151 156
152testing "sed lie-to-autoconf" "--version | grep -o 'GNU sed version '" \ 157testing "sed lie-to-autoconf" "sed --version | grep -o 'GNU sed version '" \
153 "GNU sed version \n" "" "" 158 "GNU sed version \n" "" ""
154 159
155# Jump to nonexistent label 160# Jump to nonexistent label
156testing "sed nonexistent label" "-e 'b walrus' 2> /dev/null || echo yes" \ 161testing "sed nonexistent label" "sed -e 'b walrus' 2> /dev/null || echo yes" \
157 "yes\n" "" "" 162 "yes\n" "" ""
158 163
159testing "sed backref from empty s uses range regex" \ 164testing "sed backref from empty s uses range regex" \
160 "-e '/woot/s//eep \0 eep/'" "eep woot eep" "" "woot" 165 "sed -e '/woot/s//eep \0 eep/'" "eep woot eep" "" "woot"
161 166
162testing "sed backref from empty s uses range regex with newline" \ 167testing "sed backref from empty s uses range regex with newline" \
163 "-e '/woot/s//eep \0 eep/'" "eep woot eep\n" "" "woot\n" 168 "sed -e '/woot/s//eep \0 eep/'" "eep woot eep\n" "" "woot\n"
164 169
165# -i with no filename 170# -i with no filename
166 171
167touch ./- # Detect gnu failure mode here. 172touch ./- # Detect gnu failure mode here.
168testing "sed -i with no arg [GNUFAIL]" "-e '' -i 2> /dev/null || echo yes" \ 173testing "sed -i with no arg [GNUFAIL]" "sed -e '' -i 2> /dev/null || echo yes" \
169 "yes\n" "" "" 174 "yes\n" "" ""
170rm ./- # Clean up 175rm ./- # Clean up
171 176
172# Ponder this a bit more, why "woo not found" from gnu version? 177# Ponder this a bit more, why "woo not found" from gnu version?
173#testing "sed doesn't substitute in deleted line" \ 178#testing "sed doesn't substitute in deleted line" \
174# "-e '/ook/d;s/ook//;t woo;a bang;'" "bang" "" "ook\n" 179# "sed -e '/ook/d;s/ook//;t woo;a bang;'" "bang" "" "ook\n"
175 180
176# This makes both seds very unhappy. Why? 181# This makes both seds very unhappy. Why?
177#testing "sed -g (exhaustive)" "sed -e 's/[[:space:]]*/,/g'" ",1,2,3,4,5," \ 182#testing "sed -g (exhaustive)" "sed -e 's/[[:space:]]*/,/g'" ",1,2,3,4,5," \
diff --git a/testsuite/sort.tests b/testsuite/sort.tests
index 294530988..d1b42532d 100755
--- a/testsuite/sort.tests
+++ b/testsuite/sort.tests
@@ -4,16 +4,15 @@
4# Copyright 2005 by Rob Landley <rob@landley.net> 4# Copyright 2005 by Rob Landley <rob@landley.net>
5# Licensed under GPL v2, see file LICENSE for details. 5# Licensed under GPL v2, see file LICENSE for details.
6 6
7if [ ${#COMMAND} -eq 0 ]; then COMMAND=sort; fi
8. testing.sh 7. testing.sh
9 8
10# The basic tests. These should work even with the small busybox. 9# The basic tests. These should work even with the small busybox.
11 10
12testing "sort" "input" "a\nb\nc\n" "c\na\nb\n" "" 11testing "sort" "sort input" "a\nb\nc\n" "c\na\nb\n" ""
13testing "sort #2" "input" "010\n1\n3\n" "3\n1\n010\n" "" 12testing "sort #2" "sort input" "010\n1\n3\n" "3\n1\n010\n" ""
14testing "sort stdin" "" "a\nb\nc\n" "" "b\na\nc\n" 13testing "sort stdin" "sort" "a\nb\nc\n" "" "b\na\nc\n"
15testing "sort numeric" "-n input" "1\n3\n010\n" "3\n1\n010\n" "" 14testing "sort numeric" "sort -n input" "1\n3\n010\n" "3\n1\n010\n" ""
16testing "sort reverse" "-r input" "wook\nwalrus\npoint\npabst\naargh\n" \ 15testing "sort reverse" "sort -r input" "wook\nwalrus\npoint\npabst\naargh\n" \
17 "point\nwook\npabst\naargh\nwalrus\n" "" 16 "point\nwook\npabst\naargh\nwalrus\n" ""
18 17
19# These tests require the full option set. 18# These tests require the full option set.
@@ -30,7 +29,7 @@ egg 1 2 papyrus
30 29
31# Sorting with keys 30# Sorting with keys
32 31
33testing "sort one key" "-k4,4 input" \ 32testing "sort one key" "sort -k4,4 input" \
34"999 3 0 algebra 33"999 3 0 algebra
35egg 1 2 papyrus 34egg 1 2 papyrus
367 3 42 soup 357 3 42 soup
@@ -38,7 +37,7 @@ egg 1 2 papyrus
3842 1 010 zoology 3742 1 010 zoology
39" "$data" "" 38" "$data" ""
40 39
41testing "sort key range with numeric option" "-k2,3n input" \ 40testing "sort key range with numeric option" "sort -k2,3n input" \
42"42 1 010 zoology 41"42 1 010 zoology
4342 1 3 woot 4242 1 3 woot
44egg 1 2 papyrus 43egg 1 2 papyrus
@@ -49,7 +48,7 @@ egg 1 2 papyrus
49# Busybox is definitely doing this one wrong just now. FIXME 48# Busybox is definitely doing this one wrong just now. FIXME
50 49
51testing "sort key range with numeric option and global reverse" \ 50testing "sort key range with numeric option and global reverse" \
52"-k2,3n -r input" \ 51"sort -k2,3n -r input" \
53"egg 1 2 papyrus 52"egg 1 2 papyrus
5442 1 3 woot 5342 1 3 woot
5542 1 010 zoology 5442 1 010 zoology
@@ -59,7 +58,7 @@ testing "sort key range with numeric option and global reverse" \
59 58
60# 59#
61 60
62testing "sort key range with multiple options" "-k2,3rn input" \ 61testing "sort key range with multiple options" "sort -k2,3rn input" \
63"7 3 42 soup 62"7 3 42 soup
64999 3 0 algebra 63999 3 0 algebra
6542 1 010 zoology 6442 1 010 zoology
diff --git a/testsuite/testing.sh b/testsuite/testing.sh
index 08f4200c5..bec5976e1 100755
--- a/testsuite/testing.sh
+++ b/testsuite/testing.sh
@@ -56,45 +56,41 @@ optional()
56 56
57testing () 57testing ()
58{ 58{
59 NAME="$1"
60 [ -z "$1" ] && NAME=$2
61
59 if [ $# -ne 5 ] 62 if [ $# -ne 5 ]
60 then 63 then
61 echo "Test $1 has the wrong number of arguments ($# $*)" >&2 64 echo "Test $NAME has the wrong number of arguments ($# $*)" >&2
62 exit 65 exit
63 fi 66 fi
64 67
65 if [ -n "$DEBUG" ] ; then 68 [ -n "$DEBUG" ] && set -x
66 set -x
67 fi
68 69
69 if [ -n "$SKIP" ] 70 if [ -n "$SKIP" ]
70 then 71 then
71 echo "SKIPPED: $1" 72 echo "SKIPPED: $NAME"
72 return 0 73 return 0
73 fi 74 fi
74 75
75 echo -ne "$3" > expected 76 echo -ne "$3" > expected
76 echo -ne "$4" > input 77 echo -ne "$4" > input
77 echo -ne "$5" | eval "$COMMAND $2" > actual 78 [ -z "$VERBOSE" ] || echo "echo '$5' | $COMMAND $2"
79 echo -ne "$5" | eval "$2" > actual
78 RETVAL=$? 80 RETVAL=$?
79 81
80 cmp expected actual > /dev/null 82 cmp expected actual > /dev/null
81 if [ $? -ne 0 ] 83 if [ $? -ne 0 ]
82 then 84 then
83 FAILCOUNT=$[$FAILCOUNT+1] 85 FAILCOUNT=$[$FAILCOUNT+1]
84 echo "FAIL: $1" 86 echo "FAIL: $NAME"
85 if [ -n "$VERBOSE" ] 87 [ -n "$VERBOSE" ] && diff -u expected actual
86 then
87 diff -u expected actual
88 fi
89 else 88 else
90 echo "PASS: $1" 89 echo "PASS: $NAME"
91 fi 90 fi
92 rm -f input expected actual 91 rm -f input expected actual
93 92
94 if [ -n "$DEBUG" ] 93 [ -n "$DEBUG" ] && set +x
95 then
96 set +x
97 fi
98 94
99 return $RETVAL 95 return $RETVAL
100} 96}
@@ -108,6 +104,8 @@ function mkchroot
108{ 104{
109 [ $# -lt 2 ] && return 105 [ $# -lt 2 ] && return
110 106
107 echo -n .
108
111 dest=$1 109 dest=$1
112 shift 110 shift
113 for i in "$@" 111 for i in "$@"
@@ -119,9 +117,38 @@ function mkchroot
119 mkdir -p "$dest/$d" && 117 mkdir -p "$dest/$d" &&
120 cat "$i" > "$dest/$i" && 118 cat "$i" > "$dest/$i" &&
121 chmod +x "$dest/$i" 119 chmod +x "$dest/$i"
122 else
123 i="$dest/$i"
124 fi 120 fi
125 mkchroot "$dest" $(ldd "$i" | egrep -o '/.* ') 121 mkchroot "$dest" $(ldd "$i" | egrep -o '/.* ')
126 done 122 done
127} 123}
124
125# Set up a chroot environment and run commands within it.
126# Needed commands listed on command line
127# Script fed to stdin.
128
129function dochroot
130{
131 mkdir tmpdir4chroot
132 mount -t ramfs tmpdir4chroot tmpdir4chroot
133 mkdir -p tmpdir4chroot/{etc,sys,proc,tmp,dev}
134 cp -L testing.sh tmpdir4chroot
135
136 # Copy utilities from command line arguments
137
138 echo -n "Setup chroot"
139 mkchroot tmpdir4chroot $*
140 echo
141
142 mknod tmpdir4chroot/dev/tty c 5 0
143 mknod tmpdir4chroot/dev/null c 1 3
144 mknod tmpdir4chroot/dev/zero c 1 5
145
146 # Copy script from stdin
147
148 cat > tmpdir4chroot/test.sh
149 chmod +x tmpdir4chroot/test.sh
150 chroot tmpdir4chroot /test.sh
151 umount -l tmpdir4chroot
152 rmdir tmpdir4chroot
153}
154
diff --git a/testsuite/uniq.tests b/testsuite/uniq.tests
index 95764740b..a1b69c2e5 100755
--- a/testsuite/uniq.tests
+++ b/testsuite/uniq.tests
@@ -6,7 +6,6 @@
6 6
7# AUDIT: Full SUSv3 coverage (except internationalization). 7# AUDIT: Full SUSv3 coverage (except internationalization).
8 8
9if [ ${#COMMAND} -eq 0 ]; then COMMAND=uniq; fi
10. testing.sh 9. testing.sh
11 10
12# testing "test name" "options" "expected result" "file input" "stdin" 11# testing "test name" "options" "expected result" "file input" "stdin"
@@ -15,25 +14,25 @@ if [ ${#COMMAND} -eq 0 ]; then COMMAND=uniq; fi
15 14
16# Test exit status 15# Test exit status
17 16
18testing "uniq (exit with error)" "nonexistent 2> /dev/null || echo yes" \ 17testing "uniq (exit with error)" "uniq nonexistent 2> /dev/null || echo yes" \
19 "yes\n" "" "" 18 "yes\n" "" ""
20testing "uniq (exit success)" "/dev/null && echo yes" "yes\n" "" "" 19testing "uniq (exit success)" "uniq /dev/null && echo yes" "yes\n" "" ""
21 20
22# Test various data sources and destinations 21# Test various data sources and destinations
23 22
24testing "uniq (default to stdin)" "" "one\ntwo\nthree\n" "" \ 23testing "uniq (default to stdin)" "uniq" "one\ntwo\nthree\n" "" \
25 "one\ntwo\ntwo\nthree\nthree\nthree\n" 24 "one\ntwo\ntwo\nthree\nthree\nthree\n"
26testing "uniq - (specify stdin)" "-" "one\ntwo\nthree\n" "" \ 25testing "uniq - (specify stdin)" "uniq -" "one\ntwo\nthree\n" "" \
27 "one\ntwo\ntwo\nthree\nthree\nthree\n" 26 "one\ntwo\ntwo\nthree\nthree\nthree\n"
28testing "uniq input (specify file)" "input" "one\ntwo\nthree\n" \ 27testing "uniq input (specify file)" "uniq input" "one\ntwo\nthree\n" \
29 "one\ntwo\ntwo\nthree\nthree\nthree\n" "" 28 "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
30 29
31testing "uniq input outfile (two files)" "input actual > /dev/null" \ 30testing "uniq input outfile (two files)" "uniq input actual > /dev/null" \
32 "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" "" 31 "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
33testing "uniq (stdin) outfile" "- actual" \ 32testing "uniq (stdin) outfile" "uniq - actual" \
34 "one\ntwo\nthree\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n" 33 "one\ntwo\nthree\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n"
35# Note: SUSv3 doesn't seem to require support for "-" output, but we do anyway. 34# Note: SUSv3 doesn't seem to require support for "-" output, but we do anyway.
36testing "uniq input - (specify stdout)" "input -" \ 35testing "uniq input - (specify stdout)" "uniq input -" \
37 "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" "" 36 "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
38 37
39 38
@@ -47,13 +46,13 @@ testing "uniq input - (specify stdout)" "input -" \
47 46
48# Leading whitespace is a minor technical violation of the spec, 47# Leading whitespace is a minor technical violation of the spec,
49# but since gnu does it... 48# but since gnu does it...
50testing "uniq -c (occurrence count)" "-c | sed 's/^[ \t]*//'" \ 49testing "uniq -c (occurrence count)" "uniq -c | sed 's/^[ \t]*//'" \
51 "1 one\n2 two\n3 three\n" "" \ 50 "1 one\n2 two\n3 three\n" "" \
52 "one\ntwo\ntwo\nthree\nthree\nthree\n" 51 "one\ntwo\ntwo\nthree\nthree\nthree\n"
53testing "uniq -d (dups only) " "-d" "two\nthree\n" "" \ 52testing "uniq -d (dups only) " "uniq -d" "two\nthree\n" "" \
54 "one\ntwo\ntwo\nthree\nthree\nthree\n" 53 "one\ntwo\ntwo\nthree\nthree\nthree\n"
55 54
56testing "uniq -f -s (skip fields and chars)" "-f2 -s 3" \ 55testing "uniq -f -s (skip fields and chars)" "uniq -f2 -s 3" \
57"cc dd ee8 56"cc dd ee8
58aa bb cc9 57aa bb cc9
59" "" \ 58" "" \
@@ -65,7 +64,7 @@ aa bb cc9
65# -d is "Suppress the writing fo lines that are not repeated in the input." 64# -d is "Suppress the writing fo lines that are not repeated in the input."
66# -u is "Suppress the writing of lines that are repeated in the input." 65# -u is "Suppress the writing of lines that are repeated in the input."
67# Therefore, together this means they should produce no output. 66# Therefore, together this means they should produce no output.
68testing "uniq -u and -d produce no output" "-d -u" "" "" \ 67testing "uniq -u and -d produce no output" "uniq -d -u" "" "" \
69 "one\ntwo\ntwo\nthree\nthree\nthree\n" 68 "one\ntwo\ntwo\nthree\nthree\nthree\n"
70 69
71exit $FAILCOUNT 70exit $FAILCOUNT