summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley2006-03-16 15:20:45 +0000
committerRob Landley2006-03-16 15:20:45 +0000
commit4bb1b04fd1d7d6fe410e1af14816d11da456aac5 (patch)
tree601a54598057fc267def41fce1acecfb8e5a2845
parentea9a471acd94f604f360ea16df5896e795361ac7 (diff)
downloadbusybox-4bb1b04fd1d7d6fe410e1af14816d11da456aac5.zip
busybox-4bb1b04fd1d7d6fe410e1af14816d11da456aac5.tar.gz
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 f31f38f..30d96f9 100755
--- a/testsuite/busybox.tests
+++ b/testsuite/busybox.tests
@@ -4,57 +4,55 @@
# Copyright 2005 by Rob Landley <rob@landley.net>
# Licensed under GPL v2, see file LICENSE for details.
-if [ ${#COMMAND} -eq 0 ]; then COMMAND=busybox; fi
. testing.sh
-HELPDUMP=`$COMMAND`
+# verify the applet order is correct in applets.h, otherwise applets won't
+# be called properly.
+#sed -n -e '/^USE_^\tAPPLET/{s:.*(::;s:,.*::;s:"::g;p}'
+# ../include/applets.h > applet.order1
+#LC_ALL=C sort applet.order.current > applet.order.correct
+#diff -u applet.order.current applet.order.correct
+#FAILCOUNT=$[$FAILCOUNT+$?]
+#rm -f applet.order.current applet.order.correct
+
+
+
+
+HELPDUMP=`busybox`
# We need to test under calling the binary under other names.
-ln -s `which "$COMMAND"` busybox-suffix
-ln -s `which "$COMMAND"` unknown
-testing "busybox --help busybox" "--help busybox" "$HELPDUMP\n\n" "" ""
+testing "busybox --help busybox" "busybox --help busybox" "$HELPDUMP\n\n" "" ""
-for i in busybox busybox-suffix
+ln -s `which busybox` busybox-suffix
+for i in busybox ./busybox-suffix
do
# The gratuitous "\n"s are due to a shell idiosyncrasy:
# environment variables seem to strip trailing whitespace.
- testing "$i" "" "$HELPDUMP\n\n" "" ""
+ testing "" "$i" "$HELPDUMP\n\n" "" ""
- testing "$i unknown" "unknown 2>&1" \
+ testing "$i unknown" "$i unknown 2>&1" \
"unknown: applet not found\n" "" ""
- testing "$i --help" "--help 2>&1" "$HELPDUMP\n\n" "" ""
+ testing "$i --help" "$i --help 2>&1" "$HELPDUMP\n\n" "" ""
optional CAT
- testing "$i cat" "cat" "moo" "" "moo"
- testing "$i --help cat" "--help cat 2>&1 | grep prints" \
+ testing "" "$i cat" "moo" "" "moo"
+ testing "$i --help cat" "$i --help cat 2>&1 | grep prints" \
"Concatenates FILE(s) and prints them to stdout.\n" "" ""
optional ""
- testing "$i --help unknown" "--help unknown 2>&1" \
+ testing "$i --help unknown" "$i --help unknown 2>&1" \
"unknown: applet not found\n" "" ""
-
- COMMAND=./busybox-suffix
done
+rm busybox-suffix
-COMMAND="./unknown"
-testing "busybox as unknown name" "2>&1" "unknown: applet not found\n" "" ""
-
-rm -f busybox-suffix unknown
-
-
-# verify the applet order is correct in applets.h
-# otherwise applets wont be called properly
-sed -n \
- -e '/^\tAPPLET/{s:.*(::;s:,.*::;s:"::g;p}' \
- ../include/applets.h > applet.order.current
-LC_ALL=C sort applet.order.current > applet.order.correct
-diff -u applet.order.current applet.order.correct
-FAILCOUNT=$[$FAILCOUNT+$?]
-rm -f applet.order.current applet.order.correct
+ln -s `which busybox` unknown
+testing "busybox as unknown name" "./unknown 2>&1" \
+ "unknown: applet not found\n" "" ""
+rm unknown
exit $FAILCOUNT
diff --git a/testsuite/egrep.tests b/testsuite/egrep.tests
deleted file mode 100755
index 61ce009..0000000
--- a/testsuite/egrep.tests
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/bin/sh
-
-# egrep tests.
-# Copyright 2005 by Rob Landley <rob@landley.net>
-# Licensed under GPL v2, see file LICENSE for details.
-
-# AUDIT:
-
-[ ${#COMMAND} -eq 0 ] && COMMAND=egrep
-. testing.sh
-
-optional FEATURE_GREP_EGREP_ALIAS
-
-testing "grep is also egrep" "foo" "foo\n" "" "foo\nbar\n"
-testing "egrep is not case insensitive" "foo ; [ \$? -ne 0 ] && echo yes" \
- "yes\n" "" "FOO\n"
-
-
-exit $FAILCOUNT
diff --git a/testsuite/grep.tests b/testsuite/grep.tests
index 2a7a7b9..cc9520e 100755
--- a/testsuite/grep.tests
+++ b/testsuite/grep.tests
@@ -6,7 +6,6 @@
# AUDIT:
-[ ${#COMMAND} -eq 0 ] && COMMAND=grep
. testing.sh
# testing "test name" "options" "expected result" "file input" "stdin"
@@ -15,64 +14,69 @@
# Test exit status
-testing "grep (exit with error)" "nonexistent 2> /dev/null ; echo \$?" \
+testing "grep (exit with error)" "grep nonexistent 2> /dev/null ; echo \$?" \
"1\n" "" ""
-testing "grep (exit success)" "grep $0 > /dev/null 2>&1 ; echo \$?" "0\n" \
+testing "grep (exit success)" "grep grep $0 > /dev/null 2>&1 ; echo \$?" "0\n" \
"" ""
# Test various data sources and destinations
-testing "grep (default to stdin)" "two" "two\n" "" \
+testing "grep (default to stdin)" "grep two" "two\n" "" \
"one\ntwo\nthree\nthree\nthree\n"
-testing "grep - (specify stdin)" "two -" "two\n" "" \
+testing "grep - (specify stdin)" "grep two -" "two\n" "" \
"one\ntwo\nthree\nthree\nthree\n"
-testing "grep input (specify file)" "two input" "two\n" \
+testing "grep input (specify file)" "grep two input" "two\n" \
"one\ntwo\nthree\nthree\nthree\n" ""
# Note that this assumes actual is empty.
-testing "grep input actual (two files)" "two input actual 2> /dev/null" \
+testing "grep input actual (two files)" "grep two input actual 2> /dev/null" \
"input:two\n" "one\ntwo\nthree\nthree\nthree\n" ""
-testing "grep - infile (specify stdin and file)" "two - input" \
+testing "grep - infile (specify stdin and file)" "grep two - input" \
"(standard input):two\ninput:two\n" "one\ntwo\nthree\n" \
"one\ntwo\ntoo\nthree\nthree\n"
# Check if we see the correct return value if both stdin and non-existing file
# are given.
testing "grep - nofile (specify stdin and nonexisting file)" \
- "two - nonexistent 2> /dev/null ; echo \$?" \
+ "grep two - nonexistent 2> /dev/null ; echo \$?" \
"(standard input):two\n(standard input):two\n2\n" \
"" "one\ntwo\ntwo\nthree\nthree\nthree\n"
testing "grep -q - nofile (specify stdin and nonexisting file, no match)" \
- "-q nomatch - nonexistent 2> /dev/null ; echo \$?" \
+ "grep -q nomatch - nonexistent 2> /dev/null ; echo \$?" \
"2\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n"
# SUSv3: If the -q option is specified, the exit status shall be zero
# if an input line is selected, even if an error was detected.
testing "grep -q - nofile (specify stdin and nonexisting file, match)" \
- "-q two - nonexistent ; echo \$?" \
+ "grep -q two - nonexistent ; echo \$?" \
"0\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n"
# Test various command line options
# -s no error messages
testing "grep -s nofile (nonexisting file, no match)" \
- "-s nomatch nonexistent ; echo \$?" "2\n" "" ""
+ "grep -s nomatch nonexistent ; echo \$?" "2\n" "" ""
testing "grep -s nofile - (stdin and nonexisting file, match)" \
- "-s domatch nonexistent - ; echo \$?" "(standard input):domatch\n2\n" \
- "" "nomatch\ndomatch\nend\n"
+ "grep -s domatch nonexistent - ; echo \$?" \
+ "(standard input):domatch\n2\n" "" "nomatch\ndomatch\nend\n"
# This doesn't match GNU behaviour (Binary file input matches)
# acts like GNU grep -a
-testing "grep handles binary files" "foo input" "foo\n" "\0foo\n\n" ""
+testing "grep handles binary files" "grep foo input" "foo\n" "\0foo\n\n" ""
# This doesn't match GNU behaviour (Binary file (standard input) matches)
# acts like GNU grep -a
-testing "grep handles binary stdin" "foo" "foo\n" "" "\0foo\n\n"
+testing "grep handles binary stdin" "grep foo" "foo\n" "" "\0foo\n\n"
-testing "grep matches NUL" ". input > /dev/null 2>&1 ; echo \$?" "0\n" "\0\n" ""
+testing "grep matches NUL" "grep . input > /dev/null 2>&1 ; echo \$?" \
+ "0\n" "\0\n" ""
# -e regex
-testing "grep handles multiple regexps" "-e one -e two input ; echo \$?" \
+testing "grep handles multiple regexps" "grep -e one -e two input ; echo \$?" \
"one\ntwo\n0\n" "one\ntwo\n" ""
optional FEATURE_GREP_EGREP_ALIAS
-testing "grep -E supports extended regexps" "-E fo+" "foo\n" "" "b\ar\nfoo\nbaz"
+testing "grep -E supports extended regexps" "grep -E fo+" "foo\n" "" \
+ "b\ar\nfoo\nbaz"
+testing "grep is also egrep" "egrep foo" "foo\n" "" "foo\nbar\n"
+testing "egrep is not case insensitive" \
+ "egrep foo ; [ \$? -ne 0 ] && echo yes" "yes\n" "" "FOO\n"
exit $FAILCOUNT
diff --git a/testsuite/pidof.tests b/testsuite/pidof.tests
index 0515522..831dd24 100755
--- a/testsuite/pidof.tests
+++ b/testsuite/pidof.tests
@@ -6,22 +6,24 @@
# AUDIT:
-[ ${#COMMAND} -eq 0 ] && COMMAND=pidof
. testing.sh
# testing "test name" "options" "expected result" "file input" "stdin"
-testing "pidof (exit with error)" "veryunlikelyoccuringbinaryname ; echo \$?" \
- "\n1\n" "" ""
-testing "pidof (exit with success)" "pidof > /dev/null; echo \$?" "0\n" "" ""
+testing "pidof (exit with error)" \
+ "pidof veryunlikelyoccuringbinaryname ; echo \$?" "1\n" "" ""
+testing "pidof (exit with success)" "pidof pidof > /dev/null; echo \$?" \
+ "0\n" "" ""
+# We can get away with this because it says #!/bin/sh up top.
+testing "pidof this" "pidof pidof.tests | grep -o -w $$" "$$\n" "" ""
optional FEATURE_PIDOF_SINGLE
-testing "pidof -s" "-s $(basename $0) ; echo -n \$?" \
- "$(pidof -s $(basename $0) ; echo -n $?)" "" ""
+testing "pidof -s" "pidof -s init" "1\n" "" ""
optional FEATURE_PIDOF_OMIT
-testing "pidof -o %PPID" "$(basename $0) -o %PPID ; echo -n \$?" \
- "$(pidof $(basename $0) -o %PPID ; echo -n $?)" "" ""
+testing "pidof -o %PPID" "pidof -o %PPID pidof.tests | grep -o -w $$" "" "" ""
+testing "pidof -o %PPID NOP" "pidof -o %PPID -s init" "1\n" "" ""
+testing "pidof -o init" "pidof -o 1 init | grep -o -w 1" "" "" ""
exit $FAILCOUNT
diff --git a/testsuite/sed.tests b/testsuite/sed.tests
index 6fcaa19..4d6e2e6 100755
--- a/testsuite/sed.tests
+++ b/testsuite/sed.tests
@@ -4,16 +4,15 @@
# Copyright 2005 by Rob Landley <rob@landley.net>
# Licensed under GPL v2, see file LICENSE for details.
-[ -z "$COMMAND" ] && COMMAND=sed
. testing.sh
# testing "description" "arguments" "result" "infile" "stdin"
# Corner cases
-testing "sed no files (stdin)" '""' "hello\n" "" "hello\n"
-testing "sed explicit stdin" '"" -' "hello\n" "" "hello\n"
-testing "sed handles empty lines" "-e 's/\$/@/'" "@\n" "" "\n"
-testing "sed stdin twice" '"" - -' "hello" "" "hello"
+testing "sed no files (stdin)" 'sed ""' "hello\n" "" "hello\n"
+testing "sed explicit stdin" 'sed "" -' "hello\n" "" "hello\n"
+testing "sed handles empty lines" "sed -e 's/\$/@/'" "@\n" "" "\n"
+testing "sed stdin twice" 'sed "" - -' "hello" "" "hello"
# Trailing EOF.
# Match $, at end of each file or all files?
@@ -39,139 +38,145 @@ testing "sed stdin twice" '"" - -' "hello" "" "hello"
# End of script with trailing \
# command list
-testing "sed accepts blanks before command" "-e '1 d'" "" "" ""
-testing "sed accepts newlines in -e" "-e 'i\
+testing "sed accepts blanks before command" "sed -e '1 d'" "" "" ""
+testing "sed accepts newlines in -e" "sed -e 'i\
1
a\
3'" "1\n2\n3\n" "" "2\n"
-testing "sed accepts multiple -e" "-e 'i\' -e '1' -e 'a\' -e '3'" \
+testing "sed accepts multiple -e" "sed -e 'i\' -e '1' -e 'a\' -e '3'" \
"1\n2\n3\n" "" "2\n"
# substitutions
-testing "sed -n" "-n -e s/foo/bar/ -e s/bar/baz/" "" "" "foo\n"
-testing "sed s//p" "-e s/foo/bar/p -e s/bar/baz/p" "bar\nbaz\nbaz\n" \
+testing "sed -n" "sed -n -e s/foo/bar/ -e s/bar/baz/" "" "" "foo\n"
+testing "sed s//p" "sed -e s/foo/bar/p -e s/bar/baz/p" "bar\nbaz\nbaz\n" \
"" "foo\n"
-testing "sed -n s//p" "-ne s/abc/def/p" "def\n" "" "abc\n"
-testing "sed s//g (exhaustive)" "-e 's/[[:space:]]*/,/g'" ",1,2,3,4,5,\n" \
+testing "sed -n s//p" "sed -ne s/abc/def/p" "def\n" "" "abc\n"
+testing "sed s//g (exhaustive)" "sed -e 's/[[:space:]]*/,/g'" ",1,2,3,4,5,\n" \
"" "12345\n"
-testing "sed s arbitrary delimiter" "-e 's woo boing '" "boing\n" "" "woo\n"
-testing "sed s chains" "-e s/foo/bar/ -e s/bar/baz/" "baz\n" "" "foo\n"
-testing "sed s chains2" "-e s/foo/bar/ -e s/baz/nee/" "bar\n" "" "foo\n"
-testing "sed s [delimiter]" "-e 's@[@]@@'" "onetwo" "" "one@two"
+testing "sed s arbitrary delimiter" "sed -e 's woo boing '" "boing\n" "" "woo\n"
+testing "sed s chains" "sed -e s/foo/bar/ -e s/bar/baz/" "baz\n" "" "foo\n"
+testing "sed s chains2" "sed -e s/foo/bar/ -e s/baz/nee/" "bar\n" "" "foo\n"
+testing "sed s [delimiter]" "sed -e 's@[@]@@'" "onetwo" "" "one@two"
# branch
-testing "sed b (branch)" "-e 'b one;p;: one'" "foo\n" "" "foo\n"
-testing "sed b (branch with no label jumps to end)" "-e 'b;p'" \
+testing "sed b (branch)" "sed -e 'b one;p;: one'" "foo\n" "" "foo\n"
+testing "sed b (branch with no label jumps to end)" "sed -e 'b;p'" \
"foo\n" "" "foo\n"
# test and branch
-testing "sed t (test/branch)" "-e 's/a/1/;t one;p;: one;p'" \
+testing "sed t (test/branch)" "sed -e 's/a/1/;t one;p;: one;p'" \
"1\n1\nb\nb\nb\nc\nc\nc\n" "" "a\nb\nc\n"
-testing "sed t (test/branch clears test bit)" "-e 's/a/b/;:loop;t loop'" \
+testing "sed t (test/branch clears test bit)" "sed -e 's/a/b/;:loop;t loop'" \
"b\nb\nc\n" "" "a\nb\nc\n"
-testing "sed T (!test/branch)" "-e 's/a/1/;T notone;p;: notone;p'" \
+testing "sed T (!test/branch)" "sed -e 's/a/1/;T notone;p;: notone;p'" \
"1\n1\n1\nb\nb\nc\nc\n" "" "a\nb\nc\n"
# Normal sed end-of-script doesn't print "c" because n flushed the pattern
# space. If n hits EOF, pattern space is empty when script ends.
# Query: how does this interact with no newline at EOF?
-testing "sed n (flushes pattern space, terminates early)" "-e 'n;p'" \
+testing "sed n (flushes pattern space, terminates early)" "sed -e 'n;p'" \
"a\nb\nb\nc\n" "" "a\nb\nc\n"
# N does _not_ flush pattern space, therefore c is still in there @ script end.
-testing "sed N (doesn't flush pattern space when terminating)" "-e 'N;p'" \
+testing "sed N (doesn't flush pattern space when terminating)" "sed -e 'N;p'" \
"a\nb\na\nb\nc\n" "" "a\nb\nc\n"
-testing "sed address match newline" '"/b/N;/b\\nc/i woo"' "a\nwoo\nb\nc\nd\n" \
- "" "a\nb\nc\nd\n"
+testing "sed address match newline" 'sed "/b/N;/b\\nc/i woo"' \
+ "a\nwoo\nb\nc\nd\n" "" "a\nb\nc\nd\n"
# Multiple lines in pattern space
testing "sed N (stops at end of input) and P (prints to first newline only)" \
- "-n 'N;P;p'" "a\na\nb\n" "" "a\nb\nc\n"
+ "sed -n 'N;P;p'" "a\na\nb\n" "" "a\nb\nc\n"
# Hold space
-testing "sed G (append hold space to pattern space)" 'G' "a\n\nb\n\nc\n\n" \
+testing "sed G (append hold space to pattern space)" 'sed G' "a\n\nb\n\nc\n\n" \
"" "a\nb\nc\n"
#testing "sed g/G (swap/append hold and patter space)"
#testing "sed g (swap hold/pattern space)"
testing "sed d ends script iteration" \
- "-e '/ook/d;s/ook/ping/p;i woot'" "" "" "ook\n"
+ "sed -e '/ook/d;s/ook/ping/p;i woot'" "" "" "ook\n"
testing "sed d ends script iteration (2)" \
- "-e '/ook/d;a\' -e 'bang'" "woot\nbang\n" "" "ook\nwoot\n"
+ "sed -e '/ook/d;a\' -e 'bang'" "woot\nbang\n" "" "ook\nwoot\n"
# Multiple files, with varying newlines and NUL bytes
-testing "sed embedded NUL" "-e 's/woo/bang/'" "\0bang\0woo\0" "" "\0woo\0woo\0"
-testing "sed embedded NUL g" "-e 's/woo/bang/g'" "bang\0bang\0" "" "woo\0woo\0"
+testing "sed embedded NUL" "sed -e 's/woo/bang/'" "\0bang\0woo\0" "" \
+ "\0woo\0woo\0"
+testing "sed embedded NUL g" "sed -e 's/woo/bang/g'" "bang\0bang\0" "" \
+ "woo\0woo\0"
echo -e "/woo/a he\0llo" > sed.commands
-testing "sed NUL in command" "-f sed.commands" "woo\nhe\0llo\n" "" "woo"
+testing "sed NUL in command" "sed -f sed.commands" "woo\nhe\0llo\n" "" "woo"
rm sed.commands
# sed has funky behavior with newlines at the end of file. Test lots of
# corner cases with the optional newline appending behavior.
-testing "sed normal newlines" "-e 's/woo/bang/' input -" "bang\nbang\n" \
+testing "sed normal newlines" "sed -e 's/woo/bang/' input -" "bang\nbang\n" \
"woo\n" "woo\n"
-testing "sed leave off trailing newline" "-e 's/woo/bang/' input -" \
+testing "sed leave off trailing newline" "sed -e 's/woo/bang/' input -" \
"bang\nbang" "woo\n" "woo"
-testing "sed autoinsert newline" "-e 's/woo/bang/' input -" "bang\nbang" \
+testing "sed autoinsert newline" "sed -e 's/woo/bang/' input -" "bang\nbang" \
"woo" "woo"
-testing "sed empty file plus cat" "-e 's/nohit//' input -" "one\ntwo" \
+testing "sed empty file plus cat" "sed -e 's/nohit//' input -" "one\ntwo" \
"" "one\ntwo"
-testing "sed cat plus empty file" "-e 's/nohit//' input -" "one\ntwo" \
+testing "sed cat plus empty file" "sed -e 's/nohit//' input -" "one\ntwo" \
"one\ntwo" ""
-testing "sed append autoinserts newline" "-e '/woot/a woo' -" "woot\nwoo\n" \
- "" "woot"
-testing "sed insert doesn't autoinsert newline" "-e '/woot/i woo' -" \
+testing "sed append autoinserts newline" "sed -e '/woot/a woo' -" \
+ "woot\nwoo\n" "" "woot"
+testing "sed insert doesn't autoinsert newline" "sed -e '/woot/i woo' -" \
"woo\nwoot" "" "woot"
-testing "sed print autoinsert newlines" "-e 'p' -" "one\none" "" "one"
-testing "sed print autoinsert newlines two files" "-e 'p' input -" \
+testing "sed print autoinsert newlines" "sed -e 'p' -" "one\none" "" "one"
+testing "sed print autoinsert newlines two files" "sed -e 'p' input -" \
"one\none\ntwo\ntwo" "one" "two"
-testing "sed noprint, no match, no newline" "-ne 's/woo/bang/' input" \
+testing "sed noprint, no match, no newline" "sed -ne 's/woo/bang/' input" \
"" "no\n" ""
-testing "sed selective matches with one nl" "-ne 's/woo/bang/p' input -" \
+testing "sed selective matches with one nl" "sed -ne 's/woo/bang/p' input -" \
"a bang\nc bang\n" "a woo\nb no" "c woo\nd no"
-testing "sed selective matches insert newline" "-ne 's/woo/bang/p' input -" \
- "a bang\nb bang\nd bang" "a woo\nb woo" "c no\nd woo"
-testing "sed selective matches noinsert newline" "-ne 's/woo/bang/p' input -" \
- "a bang\nb bang" "a woo\nb woo" "c no\nd no"
-testing "sed clusternewline" "-e '/one/a 111' -e '/two/i 222' -e p input -" \
+testing "sed selective matches insert newline" \
+ "sed -ne 's/woo/bang/p' input -" "a bang\nb bang\nd bang" \
+ "a woo\nb woo" "c no\nd woo"
+testing "sed selective matches noinsert newline" \
+ "sed -ne 's/woo/bang/p' input -" "a bang\nb bang" "a woo\nb woo" \
+ "c no\nd no"
+testing "sed clusternewline" \
+ "sed -e '/one/a 111' -e '/two/i 222' -e p input -" \
"one\none\n111\n222\ntwo\ntwo" "one" "two"
# Test end-of-file matching behavior
-testing "sed match EOF" " -e '"'$p'"'" "hello\nthere\nthere" "" "hello\nthere"
-testing "sed match EOF two files" " -e '"'$p'"' input -" \
+testing "sed match EOF" "sed -e '"'$p'"'" "hello\nthere\nthere" "" \
+ "hello\nthere"
+testing "sed match EOF two files" "sed -e '"'$p'"' input -" \
"one\ntwo\nthree\nfour\nfour" "one\ntwo" "three\nfour"
echo -ne "three\nfour" > input2
testing "sed match EOF inline" \
- " -e '"'$i ook'"' -i input input2 && cat input input2" \
+ "sed -e '"'$i ook'"' -i input input2 && cat input input2" \
"one\nook\ntwothree\nook\nfour" "one\ntwo" ""
rm input2
# Test lie-to-autoconf
-testing "sed lie-to-autoconf" "--version | grep -o 'GNU sed version '" \
+testing "sed lie-to-autoconf" "sed --version | grep -o 'GNU sed version '" \
"GNU sed version \n" "" ""
# Jump to nonexistent label
-testing "sed nonexistent label" "-e 'b walrus' 2> /dev/null || echo yes" \
+testing "sed nonexistent label" "sed -e 'b walrus' 2> /dev/null || echo yes" \
"yes\n" "" ""
testing "sed backref from empty s uses range regex" \
- "-e '/woot/s//eep \0 eep/'" "eep woot eep" "" "woot"
+ "sed -e '/woot/s//eep \0 eep/'" "eep woot eep" "" "woot"
testing "sed backref from empty s uses range regex with newline" \
- "-e '/woot/s//eep \0 eep/'" "eep woot eep\n" "" "woot\n"
+ "sed -e '/woot/s//eep \0 eep/'" "eep woot eep\n" "" "woot\n"
# -i with no filename
touch ./- # Detect gnu failure mode here.
-testing "sed -i with no arg [GNUFAIL]" "-e '' -i 2> /dev/null || echo yes" \
+testing "sed -i with no arg [GNUFAIL]" "sed -e '' -i 2> /dev/null || echo yes" \
"yes\n" "" ""
rm ./- # Clean up
# Ponder this a bit more, why "woo not found" from gnu version?
#testing "sed doesn't substitute in deleted line" \
-# "-e '/ook/d;s/ook//;t woo;a bang;'" "bang" "" "ook\n"
+# "sed -e '/ook/d;s/ook//;t woo;a bang;'" "bang" "" "ook\n"
# This makes both seds very unhappy. Why?
#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 2945309..d1b4253 100755
--- a/testsuite/sort.tests
+++ b/testsuite/sort.tests
@@ -4,16 +4,15 @@
# Copyright 2005 by Rob Landley <rob@landley.net>
# Licensed under GPL v2, see file LICENSE for details.
-if [ ${#COMMAND} -eq 0 ]; then COMMAND=sort; fi
. testing.sh
# The basic tests. These should work even with the small busybox.
-testing "sort" "input" "a\nb\nc\n" "c\na\nb\n" ""
-testing "sort #2" "input" "010\n1\n3\n" "3\n1\n010\n" ""
-testing "sort stdin" "" "a\nb\nc\n" "" "b\na\nc\n"
-testing "sort numeric" "-n input" "1\n3\n010\n" "3\n1\n010\n" ""
-testing "sort reverse" "-r input" "wook\nwalrus\npoint\npabst\naargh\n" \
+testing "sort" "sort input" "a\nb\nc\n" "c\na\nb\n" ""
+testing "sort #2" "sort input" "010\n1\n3\n" "3\n1\n010\n" ""
+testing "sort stdin" "sort" "a\nb\nc\n" "" "b\na\nc\n"
+testing "sort numeric" "sort -n input" "1\n3\n010\n" "3\n1\n010\n" ""
+testing "sort reverse" "sort -r input" "wook\nwalrus\npoint\npabst\naargh\n" \
"point\nwook\npabst\naargh\nwalrus\n" ""
# These tests require the full option set.
@@ -30,7 +29,7 @@ egg 1 2 papyrus
# Sorting with keys
-testing "sort one key" "-k4,4 input" \
+testing "sort one key" "sort -k4,4 input" \
"999 3 0 algebra
egg 1 2 papyrus
7 3 42 soup
@@ -38,7 +37,7 @@ egg 1 2 papyrus
42 1 010 zoology
" "$data" ""
-testing "sort key range with numeric option" "-k2,3n input" \
+testing "sort key range with numeric option" "sort -k2,3n input" \
"42 1 010 zoology
42 1 3 woot
egg 1 2 papyrus
@@ -49,7 +48,7 @@ egg 1 2 papyrus
# Busybox is definitely doing this one wrong just now. FIXME
testing "sort key range with numeric option and global reverse" \
-"-k2,3n -r input" \
+"sort -k2,3n -r input" \
"egg 1 2 papyrus
42 1 3 woot
42 1 010 zoology
@@ -59,7 +58,7 @@ testing "sort key range with numeric option and global reverse" \
#
-testing "sort key range with multiple options" "-k2,3rn input" \
+testing "sort key range with multiple options" "sort -k2,3rn input" \
"7 3 42 soup
999 3 0 algebra
42 1 010 zoology
diff --git a/testsuite/testing.sh b/testsuite/testing.sh
index 08f4200..bec5976 100755
--- a/testsuite/testing.sh
+++ b/testsuite/testing.sh
@@ -56,45 +56,41 @@ optional()
testing ()
{
+ NAME="$1"
+ [ -z "$1" ] && NAME=$2
+
if [ $# -ne 5 ]
then
- echo "Test $1 has the wrong number of arguments ($# $*)" >&2
+ echo "Test $NAME has the wrong number of arguments ($# $*)" >&2
exit
fi
- if [ -n "$DEBUG" ] ; then
- set -x
- fi
+ [ -n "$DEBUG" ] && set -x
if [ -n "$SKIP" ]
then
- echo "SKIPPED: $1"
+ echo "SKIPPED: $NAME"
return 0
fi
echo -ne "$3" > expected
echo -ne "$4" > input
- echo -ne "$5" | eval "$COMMAND $2" > actual
+ [ -z "$VERBOSE" ] || echo "echo '$5' | $COMMAND $2"
+ echo -ne "$5" | eval "$2" > actual
RETVAL=$?
cmp expected actual > /dev/null
if [ $? -ne 0 ]
then
FAILCOUNT=$[$FAILCOUNT+1]
- echo "FAIL: $1"
- if [ -n "$VERBOSE" ]
- then
- diff -u expected actual
- fi
+ echo "FAIL: $NAME"
+ [ -n "$VERBOSE" ] && diff -u expected actual
else
- echo "PASS: $1"
+ echo "PASS: $NAME"
fi
rm -f input expected actual
- if [ -n "$DEBUG" ]
- then
- set +x
- fi
+ [ -n "$DEBUG" ] && set +x
return $RETVAL
}
@@ -108,6 +104,8 @@ function mkchroot
{
[ $# -lt 2 ] && return
+ echo -n .
+
dest=$1
shift
for i in "$@"
@@ -119,9 +117,38 @@ function mkchroot
mkdir -p "$dest/$d" &&
cat "$i" > "$dest/$i" &&
chmod +x "$dest/$i"
- else
- i="$dest/$i"
fi
mkchroot "$dest" $(ldd "$i" | egrep -o '/.* ')
done
}
+
+# Set up a chroot environment and run commands within it.
+# Needed commands listed on command line
+# Script fed to stdin.
+
+function dochroot
+{
+ mkdir tmpdir4chroot
+ mount -t ramfs tmpdir4chroot tmpdir4chroot
+ mkdir -p tmpdir4chroot/{etc,sys,proc,tmp,dev}
+ cp -L testing.sh tmpdir4chroot
+
+ # Copy utilities from command line arguments
+
+ echo -n "Setup chroot"
+ mkchroot tmpdir4chroot $*
+ echo
+
+ mknod tmpdir4chroot/dev/tty c 5 0
+ mknod tmpdir4chroot/dev/null c 1 3
+ mknod tmpdir4chroot/dev/zero c 1 5
+
+ # Copy script from stdin
+
+ cat > tmpdir4chroot/test.sh
+ chmod +x tmpdir4chroot/test.sh
+ chroot tmpdir4chroot /test.sh
+ umount -l tmpdir4chroot
+ rmdir tmpdir4chroot
+}
+
diff --git a/testsuite/uniq.tests b/testsuite/uniq.tests
index 9576474..a1b69c2 100755
--- a/testsuite/uniq.tests
+++ b/testsuite/uniq.tests
@@ -6,7 +6,6 @@
# AUDIT: Full SUSv3 coverage (except internationalization).
-if [ ${#COMMAND} -eq 0 ]; then COMMAND=uniq; fi
. testing.sh
# testing "test name" "options" "expected result" "file input" "stdin"
@@ -15,25 +14,25 @@ if [ ${#COMMAND} -eq 0 ]; then COMMAND=uniq; fi
# Test exit status
-testing "uniq (exit with error)" "nonexistent 2> /dev/null || echo yes" \
+testing "uniq (exit with error)" "uniq nonexistent 2> /dev/null || echo yes" \
"yes\n" "" ""
-testing "uniq (exit success)" "/dev/null && echo yes" "yes\n" "" ""
+testing "uniq (exit success)" "uniq /dev/null && echo yes" "yes\n" "" ""
# Test various data sources and destinations
-testing "uniq (default to stdin)" "" "one\ntwo\nthree\n" "" \
+testing "uniq (default to stdin)" "uniq" "one\ntwo\nthree\n" "" \
"one\ntwo\ntwo\nthree\nthree\nthree\n"
-testing "uniq - (specify stdin)" "-" "one\ntwo\nthree\n" "" \
+testing "uniq - (specify stdin)" "uniq -" "one\ntwo\nthree\n" "" \
"one\ntwo\ntwo\nthree\nthree\nthree\n"
-testing "uniq input (specify file)" "input" "one\ntwo\nthree\n" \
+testing "uniq input (specify file)" "uniq input" "one\ntwo\nthree\n" \
"one\ntwo\ntwo\nthree\nthree\nthree\n" ""
-testing "uniq input outfile (two files)" "input actual > /dev/null" \
+testing "uniq input outfile (two files)" "uniq input actual > /dev/null" \
"one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
-testing "uniq (stdin) outfile" "- actual" \
+testing "uniq (stdin) outfile" "uniq - actual" \
"one\ntwo\nthree\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n"
# Note: SUSv3 doesn't seem to require support for "-" output, but we do anyway.
-testing "uniq input - (specify stdout)" "input -" \
+testing "uniq input - (specify stdout)" "uniq input -" \
"one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
@@ -47,13 +46,13 @@ testing "uniq input - (specify stdout)" "input -" \
# Leading whitespace is a minor technical violation of the spec,
# but since gnu does it...
-testing "uniq -c (occurrence count)" "-c | sed 's/^[ \t]*//'" \
+testing "uniq -c (occurrence count)" "uniq -c | sed 's/^[ \t]*//'" \
"1 one\n2 two\n3 three\n" "" \
"one\ntwo\ntwo\nthree\nthree\nthree\n"
-testing "uniq -d (dups only) " "-d" "two\nthree\n" "" \
+testing "uniq -d (dups only) " "uniq -d" "two\nthree\n" "" \
"one\ntwo\ntwo\nthree\nthree\nthree\n"
-testing "uniq -f -s (skip fields and chars)" "-f2 -s 3" \
+testing "uniq -f -s (skip fields and chars)" "uniq -f2 -s 3" \
"cc dd ee8
aa bb cc9
" "" \
@@ -65,7 +64,7 @@ aa bb cc9
# -d is "Suppress the writing fo lines that are not repeated in the input."
# -u is "Suppress the writing of lines that are repeated in the input."
# Therefore, together this means they should produce no output.
-testing "uniq -u and -d produce no output" "-d -u" "" "" \
+testing "uniq -u and -d produce no output" "uniq -d -u" "" "" \
"one\ntwo\ntwo\nthree\nthree\nthree\n"
exit $FAILCOUNT