diff options
Diffstat (limited to 'testsuite')
157 files changed, 1848 insertions, 0 deletions
diff --git a/testsuite/README b/testsuite/README new file mode 100644 index 000000000..377f20ef8 --- /dev/null +++ b/testsuite/README @@ -0,0 +1,34 @@ +Update: doesn't work as described. Try "make check" from parent dir... +* * * + +To run the test suite, change to this directory and run "./runtest". It will +run all of the test cases, and list those with unexpected outcomes. Adding the +-v option will cause it to show expected outcomes as well. To only run the test +cases for particular applets, specify them as parameters to runtest. + +The test cases for an applet reside in the subdirectory of the applet name. The +name of the test case should be the assertion that is tested. The test case +should be a shell fragment that returns successfully if the test case passes, +and unsuccessfully otherwise. + +If the test case relies on a certain feature, it should include the string +"FEATURE: " followed by the name of the feature in a comment. If it is always +expected to fail, it should include the string "XFAIL" in a comment. + +For the entire testsuite, the copyright is as follows: + +Copyright (C) 2001, 2002 Matt Kraai + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. diff --git a/testsuite/TODO b/testsuite/TODO new file mode 100644 index 000000000..b8957f488 --- /dev/null +++ b/testsuite/TODO @@ -0,0 +1,26 @@ +This testsuite is quite obviously a work in progress. As such, +there are a number of good extensions. If you are looking for +something to do, feel free to tackle one or more of the following: + +Moving to the new format. + The old way was "lots of little tests files in a directory", which + doesn't interact well with source control systems. The new test + format is command.tests files that use testing.sh. + +Every busybox applet needs a corresponding applet.tests. + +Full SUSv3 test suite. + Let's make the Linux Test Project jealous, shall we? Don't just + audit programs for standards compliance, _prove_ it with a regression + test harness. + + http://www.opengroup.org/onlinepubs/009695399/utilities/ + +Some tests need root access. + It's hard to test things like mount or init as a normal user. + Possibly User Mode Linux could be used for this, or perhaps + Erik's buildroot. + +libbb unit testing + Being able to test the functions of libbb individually may + help to prevent regressions. diff --git a/testsuite/all_sourcecode.tests b/testsuite/all_sourcecode.tests new file mode 100755 index 000000000..c115878fe --- /dev/null +++ b/testsuite/all_sourcecode.tests @@ -0,0 +1,78 @@ +#!/bin/sh + +# Tests for the sourcecode base itself. +# Copyright 2006 by Mike Frysinger <vapier@gentoo.org> +# Licensed under GPL v2, see file LICENSE for details. + +[ -n "$srcdir" ] || srcdir=$(pwd) +. testing.sh + + +# +# if we don't have the sourcecode available, let's just bail +# +[ -s "$srcdir/../Makefile" ] || exit 0 +[ -s "$srcdir/../include/applets.h" ] || exit 0 + + +# +# verify the applet order is correct in applets.h, otherwise +# applets won't be called properly. +# +sed -n -e '/^USE_[A-Z]*(APPLET(/{s:.*(::;s:,.*::;s:"::g;p}' \ + $srcdir/../include/applets.h > applet.order.current +LC_ALL=C sort applet.order.current > applet.order.correct +testing "Applet order" "diff -u applet.order.current applet.order.correct" "" "" "" +rm -f applet.order.current applet.order.correct + + +# +# check for misc common typos +# +find $srcdir/../ \ + '(' -type d -a '(' -name .svn -o -name testsuite ')' -prune ')' \ + -o '(' -type f -a -print0 ')' | xargs -0 \ + grep -I \ + -e '\<compatability\>' \ + -e '\<compatable\>' \ + -e '\<fordeground\>' \ + -e '\<depency\>' -e '\<dependancy\>' -e '\<dependancies\>' \ + -e '\<defalt\>' \ + -e '\<remaing\>' \ + -e '\<queueing\>' \ + -e '\<detatch\>' \ + -e '\<sempahore\>' \ + -e '\<reprenstative\>' \ + -e '\<overriden\>' \ + -e '\<readed\>' \ + -e '\<formated\>' \ + -e '\<algorithic\>' \ + -e '\<deamon\>' \ + -e '\<derefernce\>' \ + -e '\<acomadate\>' \ + | sed -e "s:^$srcdir/\.\./::g" > src.typos +testing "Common typos" "cat src.typos" "" "" "" +rm -f src.typos + + +# +# don't allow obsolete functions +# +find $srcdir/.. '(' -name '*.c' -o -name '*.h' ')' -print0 | xargs -0 \ + grep -E -e '\<(bcmp|bcopy|bzero|getwd|index|mktemp|rindex|utimes)\>[[:space:]]*\(' \ + | sed -e "s:^$srcdir/\.\./::g" > src.obsolete.funcs +testing "Obsolete function usage" "cat src.obsolete.funcs" "" "" "" +rm -f src.obsolete.funcs + + +# +# don't allow obsolete headers +# +find $srcdir/.. '(' -name '*.c' -o -name '*.h' ')' -print0 | xargs -0 \ + grep -E -e '\<(malloc|memory|sys/(errno|fcntl|signal|stropts|termios|unistd))\.h\>' \ + | sed -e "s:^$srcdir/\.\./::g" > src.obsolete.headers +testing "Obsolete headers" "cat src.obsolete.headers" "" "" "" +rm -f src.obsolete.headers + + +exit $FAILCOUNT diff --git a/testsuite/basename/basename-does-not-remove-identical-extension b/testsuite/basename/basename-does-not-remove-identical-extension new file mode 100644 index 000000000..4448fdec4 --- /dev/null +++ b/testsuite/basename/basename-does-not-remove-identical-extension @@ -0,0 +1 @@ +test xfoo = x`busybox basename foo foo` diff --git a/testsuite/basename/basename-works b/testsuite/basename/basename-works new file mode 100644 index 000000000..38907d4c1 --- /dev/null +++ b/testsuite/basename/basename-works @@ -0,0 +1,2 @@ +test x$(basename $(pwd)) = x$(busybox basename $(pwd)) + diff --git a/testsuite/bunzip2/bunzip2-reads-from-standard-input b/testsuite/bunzip2/bunzip2-reads-from-standard-input new file mode 100644 index 000000000..e212a1207 --- /dev/null +++ b/testsuite/bunzip2/bunzip2-reads-from-standard-input @@ -0,0 +1,2 @@ +echo foo | bzip2 | busybox bunzip2 > output +echo foo | cmp - output diff --git a/testsuite/bunzip2/bunzip2-removes-compressed-file b/testsuite/bunzip2/bunzip2-removes-compressed-file new file mode 100644 index 000000000..f1d15503e --- /dev/null +++ b/testsuite/bunzip2/bunzip2-removes-compressed-file @@ -0,0 +1,3 @@ +echo foo | bzip2 >foo.bz2 +busybox bunzip2 foo.bz2 +test ! -f foo.bz2 diff --git a/testsuite/bunzip2/bzcat-does-not-remove-compressed-file b/testsuite/bunzip2/bzcat-does-not-remove-compressed-file new file mode 100644 index 000000000..7d4016ec5 --- /dev/null +++ b/testsuite/bunzip2/bzcat-does-not-remove-compressed-file @@ -0,0 +1,3 @@ +echo foo | bzip2 >foo.bz2 +busybox bzcat foo.bz2 +test -f foo.bz2 diff --git a/testsuite/busybox.tests b/testsuite/busybox.tests new file mode 100755 index 000000000..26536c656 --- /dev/null +++ b/testsuite/busybox.tests @@ -0,0 +1,46 @@ +#!/bin/sh + +# Tests for busybox applet itself. +# Copyright 2005 by Rob Landley <rob@landley.net> +# Licensed under GPL v2, see file LICENSE for details. + +. testing.sh + +HELPDUMP=`busybox` + +# We need to test under calling the binary under other names. + + +testing "busybox --help busybox" "busybox --help busybox" "$HELPDUMP\n\n" "" "" + +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 unknown" "$i unknown 2>&1" \ + "unknown: applet not found\n" "" "" + + testing "$i --help" "$i --help 2>&1" "$HELPDUMP\n\n" "" "" + + optional CAT + 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" "$i --help unknown 2>&1" \ + "unknown: applet not found\n" "" "" +done +rm busybox-suffix + +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/cat/cat-prints-a-file b/testsuite/cat/cat-prints-a-file new file mode 100644 index 000000000..e3f35a86e --- /dev/null +++ b/testsuite/cat/cat-prints-a-file @@ -0,0 +1,3 @@ +echo I WANT > foo +busybox cat foo >bar +cmp foo bar diff --git a/testsuite/cat/cat-prints-a-file-and-standard-input b/testsuite/cat/cat-prints-a-file-and-standard-input new file mode 100644 index 000000000..bc9231882 --- /dev/null +++ b/testsuite/cat/cat-prints-a-file-and-standard-input @@ -0,0 +1,7 @@ +echo I WANT > foo +echo SOMETHING | busybox cat foo - >bar +cat >baz <<EOF +I WANT +SOMETHING +EOF +cmp bar baz diff --git a/testsuite/cmp/cmp-detects-difference b/testsuite/cmp/cmp-detects-difference new file mode 100644 index 000000000..b9bb628f1 --- /dev/null +++ b/testsuite/cmp/cmp-detects-difference @@ -0,0 +1,9 @@ +echo foo >foo +echo bar >bar +set +e +busybox cmp -s foo bar +if [ $? != 0 ] ; then + exit 0; +fi + +exit 1; diff --git a/testsuite/cp/cp-a-files-to-dir b/testsuite/cp/cp-a-files-to-dir new file mode 100644 index 000000000..39f8f8103 --- /dev/null +++ b/testsuite/cp/cp-a-files-to-dir @@ -0,0 +1,14 @@ +echo file number one > file1 +echo file number two > file2 +ln -s file2 link1 +mkdir dir1 +touch --date='Sat Jan 29 21:24:08 PST 2000' dir1/file3 +mkdir there +busybox cp -a file1 file2 link1 dir1 there +test -f there/file1 +test -f there/file2 +test ! -s there/dir1/file3 +test -L there/link1 +test xfile2 = x`readlink there/link1` +test ! dir1/file3 -ot there/dir1/file3 +test ! dir1/file3 -nt there/dir1/file3 diff --git a/testsuite/cp/cp-a-preserves-links b/testsuite/cp/cp-a-preserves-links new file mode 100644 index 000000000..0c0cd9653 --- /dev/null +++ b/testsuite/cp/cp-a-preserves-links @@ -0,0 +1,5 @@ +touch foo +ln -s foo bar +busybox cp -a bar baz +test -L baz +test xfoo = x`readlink baz` diff --git a/testsuite/cp/cp-copies-empty-file b/testsuite/cp/cp-copies-empty-file new file mode 100644 index 000000000..ad25aa12e --- /dev/null +++ b/testsuite/cp/cp-copies-empty-file @@ -0,0 +1,3 @@ +touch foo +busybox cp foo bar +cmp foo bar diff --git a/testsuite/cp/cp-copies-large-file b/testsuite/cp/cp-copies-large-file new file mode 100644 index 000000000..c2225c6d8 --- /dev/null +++ b/testsuite/cp/cp-copies-large-file @@ -0,0 +1,3 @@ +dd if=/dev/zero of=foo seek=10k count=1 2>/dev/null +busybox cp foo bar +cmp foo bar diff --git a/testsuite/cp/cp-copies-small-file b/testsuite/cp/cp-copies-small-file new file mode 100644 index 000000000..d52a887c0 --- /dev/null +++ b/testsuite/cp/cp-copies-small-file @@ -0,0 +1,3 @@ +echo I WANT > foo +busybox cp foo bar +cmp foo bar diff --git a/testsuite/cp/cp-d-files-to-dir b/testsuite/cp/cp-d-files-to-dir new file mode 100644 index 000000000..9571a567e --- /dev/null +++ b/testsuite/cp/cp-d-files-to-dir @@ -0,0 +1,11 @@ +echo file number one > file1 +echo file number two > file2 +touch file3 +ln -s file2 link1 +mkdir there +busybox cp -d file1 file2 file3 link1 there +test -f there/file1 +test -f there/file2 +test ! -s there/file3 +test -L there/link1 +test xfile2 = x`readlink there/link1` diff --git a/testsuite/cp/cp-dir-create-dir b/testsuite/cp/cp-dir-create-dir new file mode 100644 index 000000000..a8d7b50a5 --- /dev/null +++ b/testsuite/cp/cp-dir-create-dir @@ -0,0 +1,4 @@ +mkdir bar +touch bar/baz +busybox cp -R bar foo +test -f foo/baz diff --git a/testsuite/cp/cp-dir-existing-dir b/testsuite/cp/cp-dir-existing-dir new file mode 100644 index 000000000..4c788ba73 --- /dev/null +++ b/testsuite/cp/cp-dir-existing-dir @@ -0,0 +1,5 @@ +mkdir bar +touch bar/baz +mkdir foo +busybox cp -R bar foo +test -f foo/bar/baz diff --git a/testsuite/cp/cp-does-not-copy-unreadable-file b/testsuite/cp/cp-does-not-copy-unreadable-file new file mode 100644 index 000000000..ce11bfab0 --- /dev/null +++ b/testsuite/cp/cp-does-not-copy-unreadable-file @@ -0,0 +1,6 @@ +touch foo +chmod a-r foo +set +e +busybox cp foo bar +set -e +test ! -f bar diff --git a/testsuite/cp/cp-files-to-dir b/testsuite/cp/cp-files-to-dir new file mode 100644 index 000000000..fdb81916f --- /dev/null +++ b/testsuite/cp/cp-files-to-dir @@ -0,0 +1,11 @@ +echo file number one > file1 +echo file number two > file2 +touch file3 +ln -s file2 link1 +mkdir there +busybox cp file1 file2 file3 link1 there +test -f there/file1 +test -f there/file2 +test ! -s there/file3 +test -f there/link1 +cmp there/file2 there/link1 diff --git a/testsuite/cp/cp-follows-links b/testsuite/cp/cp-follows-links new file mode 100644 index 000000000..2d9f05e9f --- /dev/null +++ b/testsuite/cp/cp-follows-links @@ -0,0 +1,4 @@ +touch foo +ln -s foo bar +busybox cp bar baz +test -f baz diff --git a/testsuite/cp/cp-preserves-hard-links b/testsuite/cp/cp-preserves-hard-links new file mode 100644 index 000000000..4de7b85db --- /dev/null +++ b/testsuite/cp/cp-preserves-hard-links @@ -0,0 +1,6 @@ +# FEATURE: CONFIG_FEATURE_PRESERVE_HARDLINKS +touch foo +ln foo bar +mkdir baz +busybox cp -d foo bar baz +test baz/foo -ef baz/bar diff --git a/testsuite/cp/cp-preserves-links b/testsuite/cp/cp-preserves-links new file mode 100644 index 000000000..301dc5fd8 --- /dev/null +++ b/testsuite/cp/cp-preserves-links @@ -0,0 +1,5 @@ +touch foo +ln -s foo bar +busybox cp -d bar baz +test -L baz +test xfoo = x`readlink baz` diff --git a/testsuite/cp/cp-preserves-source-file b/testsuite/cp/cp-preserves-source-file new file mode 100644 index 000000000..f0f5065f4 --- /dev/null +++ b/testsuite/cp/cp-preserves-source-file @@ -0,0 +1,3 @@ +touch foo +busybox cp foo bar +test -f foo diff --git a/testsuite/cut/cut-cuts-a-character b/testsuite/cut/cut-cuts-a-character new file mode 100644 index 000000000..d6c5efa3a --- /dev/null +++ b/testsuite/cut/cut-cuts-a-character @@ -0,0 +1 @@ +test $(echo abcd | busybox cut -c 3) = c diff --git a/testsuite/cut/cut-cuts-a-closed-range b/testsuite/cut/cut-cuts-a-closed-range new file mode 100644 index 000000000..9680b7650 --- /dev/null +++ b/testsuite/cut/cut-cuts-a-closed-range @@ -0,0 +1 @@ +test $(echo abcd | busybox cut -c 1-2) = ab diff --git a/testsuite/cut/cut-cuts-a-field b/testsuite/cut/cut-cuts-a-field new file mode 100644 index 000000000..4c7f44007 --- /dev/null +++ b/testsuite/cut/cut-cuts-a-field @@ -0,0 +1 @@ +test $(echo -e "f1\tf2\tf3" | busybox cut -f 2) = f2 diff --git a/testsuite/cut/cut-cuts-an-open-range b/testsuite/cut/cut-cuts-an-open-range new file mode 100644 index 000000000..1fbf27742 --- /dev/null +++ b/testsuite/cut/cut-cuts-an-open-range @@ -0,0 +1 @@ +test $(echo abcd | busybox cut -c -3) = abc diff --git a/testsuite/cut/cut-cuts-an-unclosed-range b/testsuite/cut/cut-cuts-an-unclosed-range new file mode 100644 index 000000000..a2b0cdb03 --- /dev/null +++ b/testsuite/cut/cut-cuts-an-unclosed-range @@ -0,0 +1 @@ +test $(echo abcd | busybox cut -c 3-) = cd diff --git a/testsuite/date/date-R-works b/testsuite/date/date-R-works new file mode 100644 index 000000000..ec3a06751 --- /dev/null +++ b/testsuite/date/date-R-works @@ -0,0 +1,2 @@ +test x"`date -R`" = x"`busybox date -R`" + diff --git a/testsuite/date/date-format-works b/testsuite/date/date-format-works new file mode 100644 index 000000000..f28d06cfc --- /dev/null +++ b/testsuite/date/date-format-works @@ -0,0 +1 @@ +test x"`date +%d/%m/%y`" = x"`busybox date +%d/%m/%y`" diff --git a/testsuite/date/date-u-works b/testsuite/date/date-u-works new file mode 100644 index 000000000..7d9902a3f --- /dev/null +++ b/testsuite/date/date-u-works @@ -0,0 +1,2 @@ +test x"`date -u`" = x"`busybox date -u`" + diff --git a/testsuite/date/date-works b/testsuite/date/date-works new file mode 100644 index 000000000..2f6dd1eca --- /dev/null +++ b/testsuite/date/date-works @@ -0,0 +1,2 @@ +test x"`date`" = x"`busybox date`" + diff --git a/testsuite/dd/dd-accepts-if b/testsuite/dd/dd-accepts-if new file mode 100644 index 000000000..03d1af853 --- /dev/null +++ b/testsuite/dd/dd-accepts-if @@ -0,0 +1,2 @@ +echo I WANT >foo +test "$(busybox dd if=foo 2>/dev/null)" = "I WANT" diff --git a/testsuite/dd/dd-accepts-of b/testsuite/dd/dd-accepts-of new file mode 100644 index 000000000..84405e622 --- /dev/null +++ b/testsuite/dd/dd-accepts-of @@ -0,0 +1,2 @@ +echo I WANT | busybox dd of=foo 2>/dev/null +echo I WANT | cmp foo - diff --git a/testsuite/dd/dd-copies-from-standard-input-to-standard-output b/testsuite/dd/dd-copies-from-standard-input-to-standard-output new file mode 100644 index 000000000..d890eb04c --- /dev/null +++ b/testsuite/dd/dd-copies-from-standard-input-to-standard-output @@ -0,0 +1 @@ +test "$(echo I WANT | busybox dd 2>/dev/null)" = "I WANT" diff --git a/testsuite/dd/dd-prints-count-to-standard-error b/testsuite/dd/dd-prints-count-to-standard-error new file mode 100644 index 000000000..2187dc027 --- /dev/null +++ b/testsuite/dd/dd-prints-count-to-standard-error @@ -0,0 +1,2 @@ +echo I WANT | busybox dd of=foo >/dev/null 2>bar +grep -q records bar diff --git a/testsuite/dirname/dirname-handles-absolute-path b/testsuite/dirname/dirname-handles-absolute-path new file mode 100644 index 000000000..ca1a51b3a --- /dev/null +++ b/testsuite/dirname/dirname-handles-absolute-path @@ -0,0 +1 @@ +test $(busybox dirname /foo/bar/baz) = /foo/bar diff --git a/testsuite/dirname/dirname-handles-empty-path b/testsuite/dirname/dirname-handles-empty-path new file mode 100644 index 000000000..04134a58f --- /dev/null +++ b/testsuite/dirname/dirname-handles-empty-path @@ -0,0 +1 @@ +test $(busybox dirname '') = . diff --git a/testsuite/dirname/dirname-handles-multiple-slashes b/testsuite/dirname/dirname-handles-multiple-slashes new file mode 100644 index 000000000..286f25361 --- /dev/null +++ b/testsuite/dirname/dirname-handles-multiple-slashes @@ -0,0 +1 @@ +test $(busybox dirname foo/bar///baz) = foo/bar diff --git a/testsuite/dirname/dirname-handles-relative-path b/testsuite/dirname/dirname-handles-relative-path new file mode 100644 index 000000000..ffe4ab459 --- /dev/null +++ b/testsuite/dirname/dirname-handles-relative-path @@ -0,0 +1 @@ +test $(busybox dirname foo/bar/baz) = foo/bar diff --git a/testsuite/dirname/dirname-handles-root b/testsuite/dirname/dirname-handles-root new file mode 100644 index 000000000..6bd62b8a1 --- /dev/null +++ b/testsuite/dirname/dirname-handles-root @@ -0,0 +1 @@ +test $(busybox dirname /) = / diff --git a/testsuite/dirname/dirname-handles-single-component b/testsuite/dirname/dirname-handles-single-component new file mode 100644 index 000000000..24f9ae163 --- /dev/null +++ b/testsuite/dirname/dirname-handles-single-component @@ -0,0 +1 @@ +test $(busybox dirname foo) = . diff --git a/testsuite/dirname/dirname-works b/testsuite/dirname/dirname-works new file mode 100644 index 000000000..f339c8f73 --- /dev/null +++ b/testsuite/dirname/dirname-works @@ -0,0 +1,2 @@ +test x$(dirname $(pwd)) = x$(busybox dirname $(pwd)) + diff --git a/testsuite/du/du-h-works b/testsuite/du/du-h-works new file mode 100644 index 000000000..82041ab33 --- /dev/null +++ b/testsuite/du/du-h-works @@ -0,0 +1,4 @@ +[ -n "$d" ] || d=.. +du -h "$d" > logfile.gnu +busybox du -h "$d" > logfile.bb +cmp logfile.gnu logfile.bb diff --git a/testsuite/du/du-k-works b/testsuite/du/du-k-works new file mode 100644 index 000000000..177a1a2cd --- /dev/null +++ b/testsuite/du/du-k-works @@ -0,0 +1,4 @@ +[ -n "$d" ] || d=.. +du -k "$d" > logfile.gnu +busybox du -k "$d" > logfile.bb +cmp logfile.gnu logfile.bb diff --git a/testsuite/du/du-l-works b/testsuite/du/du-l-works new file mode 100644 index 000000000..61e91400c --- /dev/null +++ b/testsuite/du/du-l-works @@ -0,0 +1,4 @@ +[ -n "$d" ] || d=.. +du -l "$d" > logfile.gnu +busybox du -l "$d" > logfile.bb +cmp logfile.gnu logfile.bb diff --git a/testsuite/du/du-m-works b/testsuite/du/du-m-works new file mode 100644 index 000000000..bc9707350 --- /dev/null +++ b/testsuite/du/du-m-works @@ -0,0 +1,4 @@ +[ -n "$d" ] || d=.. +du -m "$d" > logfile.gnu +busybox du -m "$d" > logfile.bb +cmp logfile.gnu logfile.bb diff --git a/testsuite/du/du-s-works b/testsuite/du/du-s-works new file mode 100644 index 000000000..f0b3bf0ae --- /dev/null +++ b/testsuite/du/du-s-works @@ -0,0 +1,4 @@ +[ -n "$d" ] || d=.. +du -s "$d" > logfile.gnu +busybox du -s "$d" > logfile.bb +cmp logfile.gnu logfile.bb diff --git a/testsuite/du/du-works b/testsuite/du/du-works new file mode 100644 index 000000000..47949c694 --- /dev/null +++ b/testsuite/du/du-works @@ -0,0 +1,4 @@ +[ -n "$d" ] || d=.. +du "$d" > logfile.gnu +busybox du "$d" > logfile.bb +cmp logfile.gnu logfile.bb diff --git a/testsuite/echo/echo-does-not-print-newline b/testsuite/echo/echo-does-not-print-newline new file mode 100644 index 000000000..2ed03caf5 --- /dev/null +++ b/testsuite/echo/echo-does-not-print-newline @@ -0,0 +1 @@ +test `busybox echo -n word | wc -c` -eq 4 diff --git a/testsuite/echo/echo-prints-argument b/testsuite/echo/echo-prints-argument new file mode 100644 index 000000000..479dac89c --- /dev/null +++ b/testsuite/echo/echo-prints-argument @@ -0,0 +1 @@ +test xfubar = x`busybox echo fubar` diff --git a/testsuite/echo/echo-prints-arguments b/testsuite/echo/echo-prints-arguments new file mode 100644 index 000000000..4e4e3b434 --- /dev/null +++ b/testsuite/echo/echo-prints-arguments @@ -0,0 +1 @@ +test "`busybox echo foo bar`" = "foo bar" diff --git a/testsuite/echo/echo-prints-newline b/testsuite/echo/echo-prints-newline new file mode 100644 index 000000000..838671efe --- /dev/null +++ b/testsuite/echo/echo-prints-newline @@ -0,0 +1 @@ +test `busybox echo word | wc -c` -eq 5 diff --git a/testsuite/expr/expr-works b/testsuite/expr/expr-works new file mode 100644 index 000000000..af49ac4d5 --- /dev/null +++ b/testsuite/expr/expr-works @@ -0,0 +1,59 @@ +# busybox expr +busybox expr 1 \| 1 +busybox expr 1 \| 0 +busybox expr 0 \| 1 +busybox expr 1 \& 1 +busybox expr 0 \< 1 +busybox expr 1 \> 0 +busybox expr 0 \<= 1 +busybox expr 1 \<= 1 +busybox expr 1 \>= 0 +busybox expr 1 \>= 1 +busybox expr 1 + 2 +busybox expr 2 - 1 +busybox expr 2 \* 3 +busybox expr 12 / 2 +busybox expr 12 % 5 + + +set +e +busybox expr 0 \| 0 +if [ $? != 1 ] ; then + exit 1; +fi; + +busybox expr 1 \& 0 +if [ $? != 1 ] ; then + exit 1; +fi; + +busybox expr 0 \& 1 +if [ $? != 1 ] ; then + exit 1; +fi; + +busybox expr 0 \& 0 +if [ $? != 1 ] ; then + exit 1; +fi; + +busybox expr 1 \< 0 +if [ $? != 1 ] ; then + exit 1; +fi; + +busybox expr 0 \> 1 +if [ $? != 1 ] ; then + exit 1; +fi; + +busybox expr 1 \<= 0 +if [ $? != 1 ] ; then + exit 1; +fi; + +busybox expr 0 \>= 1 +if [ $? != 1 ] ; then + exit 1; +fi; + diff --git a/testsuite/false/false-is-silent b/testsuite/false/false-is-silent new file mode 100644 index 000000000..8a9aa0c7f --- /dev/null +++ b/testsuite/false/false-is-silent @@ -0,0 +1 @@ +busybox false 2>&1 | cmp - /dev/null diff --git a/testsuite/false/false-returns-failure b/testsuite/false/false-returns-failure new file mode 100644 index 000000000..1a061f286 --- /dev/null +++ b/testsuite/false/false-returns-failure @@ -0,0 +1 @@ +! busybox false diff --git a/testsuite/find/find-supports-minus-xdev b/testsuite/find/find-supports-minus-xdev new file mode 100644 index 000000000..4c559a1f4 --- /dev/null +++ b/testsuite/find/find-supports-minus-xdev @@ -0,0 +1 @@ +busybox find . -xdev >/dev/null 2>&1 diff --git a/testsuite/grep.tests b/testsuite/grep.tests new file mode 100755 index 000000000..ef0de482b --- /dev/null +++ b/testsuite/grep.tests @@ -0,0 +1,84 @@ +#!/bin/sh + +# grep tests. +# Copyright 2005 by Rob Landley <rob@landley.net> +# Licensed under GPL v2, see file LICENSE for details. + +# AUDIT: + +. testing.sh + +# testing "test name" "options" "expected result" "file input" "stdin" +# file input will be file called "input" +# test can create a file "actual" instead of writing to stdout + +# Test exit status + +testing "grep (exit with error)" "grep nonexistent 2> /dev/null ; echo \$?" \ + "1\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)" "grep two" "two\n" "" \ + "one\ntwo\nthree\nthree\nthree\n" +testing "grep - (specify stdin)" "grep two -" "two\n" "" \ + "one\ntwo\nthree\nthree\nthree\n" +testing "grep input (specify file)" "grep two input" "two\n" \ + "one\ntwo\nthree\nthree\nthree\n" "" + +testing "grep (no newline at EOL)" "grep bug" "bug" "bug" "" + +# Note that this assumes actual is empty. +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)" "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)" \ + "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)" \ + "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)" \ + "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)" \ + "grep -s nomatch nonexistent ; echo \$?" "2\n" "" "" +testing "grep -s nofile - (stdin and nonexisting file, match)" \ + "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" "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" "grep foo" "foo\n" "" "\0foo\n\n" + +testing "grep matches NUL" "grep . input > /dev/null 2>&1 ; echo \$?" \ + "0\n" "\0\n" "" + +# -e regex +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" "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/gunzip/gunzip-reads-from-standard-input b/testsuite/gunzip/gunzip-reads-from-standard-input new file mode 100644 index 000000000..7c498c0ce --- /dev/null +++ b/testsuite/gunzip/gunzip-reads-from-standard-input @@ -0,0 +1,2 @@ +echo foo | gzip | busybox gunzip > output +echo foo | cmp - output diff --git a/testsuite/gzip/gzip-accepts-multiple-files b/testsuite/gzip/gzip-accepts-multiple-files new file mode 100644 index 000000000..8f0d9c845 --- /dev/null +++ b/testsuite/gzip/gzip-accepts-multiple-files @@ -0,0 +1,3 @@ +touch foo bar +busybox gzip foo bar +test -f foo.gz -a -f bar.gz diff --git a/testsuite/gzip/gzip-accepts-single-minus b/testsuite/gzip/gzip-accepts-single-minus new file mode 100644 index 000000000..8b51fdfed --- /dev/null +++ b/testsuite/gzip/gzip-accepts-single-minus @@ -0,0 +1 @@ +echo foo | busybox gzip - >/dev/null diff --git a/testsuite/gzip/gzip-removes-original-file b/testsuite/gzip/gzip-removes-original-file new file mode 100644 index 000000000..b9cb995bc --- /dev/null +++ b/testsuite/gzip/gzip-removes-original-file @@ -0,0 +1,3 @@ +touch foo +busybox gzip foo +test ! -f foo diff --git a/testsuite/head/head-n-works b/testsuite/head/head-n-works new file mode 100644 index 000000000..db4325556 --- /dev/null +++ b/testsuite/head/head-n-works @@ -0,0 +1,4 @@ +[ -n "$d" ] || d=.. +head -n 2 "$d/README" > logfile.gnu +busybox head -n 2 "$d/README" > logfile.bb +cmp logfile.gnu logfile.bb diff --git a/testsuite/head/head-works b/testsuite/head/head-works new file mode 100644 index 000000000..56ad3e36b --- /dev/null +++ b/testsuite/head/head-works @@ -0,0 +1,4 @@ +[ -n "$d" ] || d=.. +head "$d/README" > logfile.gnu +busybox head "$d/README" > logfile.bb +cmp logfile.gnu logfile.bb diff --git a/testsuite/hostid/hostid-works b/testsuite/hostid/hostid-works new file mode 100644 index 000000000..e85698e66 --- /dev/null +++ b/testsuite/hostid/hostid-works @@ -0,0 +1,2 @@ +test x$(hostid) = x$(busybox hostid) + diff --git a/testsuite/hostname/hostname-d-works b/testsuite/hostname/hostname-d-works new file mode 100644 index 000000000..a9aeb92cb --- /dev/null +++ b/testsuite/hostname/hostname-d-works @@ -0,0 +1,2 @@ +test x$(hostname -d) = x$(busybox hostname -d) + diff --git a/testsuite/hostname/hostname-i-works b/testsuite/hostname/hostname-i-works new file mode 100644 index 000000000..68a3e6789 --- /dev/null +++ b/testsuite/hostname/hostname-i-works @@ -0,0 +1,2 @@ +test x$(hostname -i) = x$(busybox hostname -i) + diff --git a/testsuite/hostname/hostname-s-works b/testsuite/hostname/hostname-s-works new file mode 100644 index 000000000..172b94409 --- /dev/null +++ b/testsuite/hostname/hostname-s-works @@ -0,0 +1 @@ +test x$(hostname -s) = x$(busybox hostname -s) diff --git a/testsuite/hostname/hostname-works b/testsuite/hostname/hostname-works new file mode 100644 index 000000000..f51a406ea --- /dev/null +++ b/testsuite/hostname/hostname-works @@ -0,0 +1 @@ +test x$(hostname) = x$(busybox hostname) diff --git a/testsuite/id/id-g-works b/testsuite/id/id-g-works new file mode 100644 index 000000000..671fc5361 --- /dev/null +++ b/testsuite/id/id-g-works @@ -0,0 +1 @@ +test x$(id -g) = x$(busybox id -g) diff --git a/testsuite/id/id-u-works b/testsuite/id/id-u-works new file mode 100644 index 000000000..2358cb0d7 --- /dev/null +++ b/testsuite/id/id-u-works @@ -0,0 +1 @@ +test x$(id -u) = x$(busybox id -u) diff --git a/testsuite/id/id-un-works b/testsuite/id/id-un-works new file mode 100644 index 000000000..db390e733 --- /dev/null +++ b/testsuite/id/id-un-works @@ -0,0 +1 @@ +test x$(id -un) = x$(busybox id -un) diff --git a/testsuite/id/id-ur-works b/testsuite/id/id-ur-works new file mode 100644 index 000000000..6b0fcb038 --- /dev/null +++ b/testsuite/id/id-ur-works @@ -0,0 +1 @@ +test x$(id -ur) = x$(busybox id -ur) diff --git a/testsuite/ln/ln-creates-hard-links b/testsuite/ln/ln-creates-hard-links new file mode 100644 index 000000000..2f6e23f9a --- /dev/null +++ b/testsuite/ln/ln-creates-hard-links @@ -0,0 +1,4 @@ +echo file number one > file1 +busybox ln file1 link1 +test -f file1 +test -f link1 diff --git a/testsuite/ln/ln-creates-soft-links b/testsuite/ln/ln-creates-soft-links new file mode 100644 index 000000000..e875e4c8a --- /dev/null +++ b/testsuite/ln/ln-creates-soft-links @@ -0,0 +1,4 @@ +echo file number one > file1 +busybox ln -s file1 link1 +test -L link1 +test xfile1 = x`readlink link1` diff --git a/testsuite/ln/ln-force-creates-hard-links b/testsuite/ln/ln-force-creates-hard-links new file mode 100644 index 000000000..c96b7d6cf --- /dev/null +++ b/testsuite/ln/ln-force-creates-hard-links @@ -0,0 +1,5 @@ +echo file number one > file1 +echo file number two > link1 +busybox ln -f file1 link1 +test -f file1 +test -f link1 diff --git a/testsuite/ln/ln-force-creates-soft-links b/testsuite/ln/ln-force-creates-soft-links new file mode 100644 index 000000000..cab8d1db7 --- /dev/null +++ b/testsuite/ln/ln-force-creates-soft-links @@ -0,0 +1,5 @@ +echo file number one > file1 +echo file number two > link1 +busybox ln -f -s file1 link1 +test -L link1 +test xfile1 = x`readlink link1` diff --git a/testsuite/ln/ln-preserves-hard-links b/testsuite/ln/ln-preserves-hard-links new file mode 100644 index 000000000..47fb98961 --- /dev/null +++ b/testsuite/ln/ln-preserves-hard-links @@ -0,0 +1,8 @@ +echo file number one > file1 +echo file number two > link1 +set +e +busybox ln file1 link1 +if [ $? != 0 ] ; then + exit 0; +fi +exit 1; diff --git a/testsuite/ln/ln-preserves-soft-links b/testsuite/ln/ln-preserves-soft-links new file mode 100644 index 000000000..a8123ece3 --- /dev/null +++ b/testsuite/ln/ln-preserves-soft-links @@ -0,0 +1,9 @@ +echo file number one > file1 +echo file number two > link1 +set +e +busybox ln -s file1 link1 +if [ $? != 0 ] ; then + exit 0; +fi +exit 1; + diff --git a/testsuite/ls/ls-1-works b/testsuite/ls/ls-1-works new file mode 100644 index 000000000..8ad484fc3 --- /dev/null +++ b/testsuite/ls/ls-1-works @@ -0,0 +1,4 @@ +[ -n "$d" ] || d=.. +ls -1 "$d" > logfile.gnu +busybox ls -1 "$d" > logfile.bb +cmp logfile.gnu logfile.bb diff --git a/testsuite/ls/ls-h-works b/testsuite/ls/ls-h-works new file mode 100644 index 000000000..7331262c9 --- /dev/null +++ b/testsuite/ls/ls-h-works @@ -0,0 +1,4 @@ +[ -n "$d" ] || d=.. +ls -h "$d" > logfile.gnu +busybox ls -h "$d" > logfile.bb +cmp logfile.gnu logfile.bb diff --git a/testsuite/ls/ls-l-works b/testsuite/ls/ls-l-works new file mode 100644 index 000000000..efc2b196e --- /dev/null +++ b/testsuite/ls/ls-l-works @@ -0,0 +1,4 @@ +[ -n "$d" ] || d=.. +LC_ALL=C ls -l "$d" > logfile.gnu +busybox ls -l "$d" > logfile.bb +diff -w logfile.gnu logfile.bb diff --git a/testsuite/ls/ls-s-works b/testsuite/ls/ls-s-works new file mode 100644 index 000000000..6c8bf3627 --- /dev/null +++ b/testsuite/ls/ls-s-works @@ -0,0 +1,4 @@ +[ -n "$d" ] || d=.. +LC_ALL=C ls -1s "$d" > logfile.gnu +busybox ls -1s "$d" > logfile.bb +cmp logfile.gnu logfile.bb diff --git a/testsuite/md5sum/md5sum-verifies-non-binary-file b/testsuite/md5sum/md5sum-verifies-non-binary-file new file mode 100644 index 000000000..8566a234d --- /dev/null +++ b/testsuite/md5sum/md5sum-verifies-non-binary-file @@ -0,0 +1,3 @@ +touch foo +md5sum foo > bar +busybox md5sum -c bar diff --git a/testsuite/mkdir/mkdir-makes-a-directory b/testsuite/mkdir/mkdir-makes-a-directory new file mode 100644 index 000000000..6ca5c4d52 --- /dev/null +++ b/testsuite/mkdir/mkdir-makes-a-directory @@ -0,0 +1,2 @@ +busybox mkdir foo +test -d foo diff --git a/testsuite/mkdir/mkdir-makes-parent-directories b/testsuite/mkdir/mkdir-makes-parent-directories new file mode 100644 index 000000000..992facb46 --- /dev/null +++ b/testsuite/mkdir/mkdir-makes-parent-directories @@ -0,0 +1,2 @@ +busybox mkdir -p foo/bar +test -d foo -a -d foo/bar diff --git a/testsuite/mount.testroot b/testsuite/mount.testroot new file mode 100755 index 000000000..e18d0461d --- /dev/null +++ b/testsuite/mount.testroot @@ -0,0 +1,183 @@ +#!/bin/sh + +# SUSv3 compliant mount and umount tests. +# Copyright 2005 by Rob Landley <rob@landley.net> +# Licensed under GPL v2, see file LICENSE for details. + +if [ -z "$TESTDIR" ] +then + echo 'Need $TESTDIR' + exit 1 +fi + +cd "$TESTDIR" + +. testing.sh + +# If we aren't PID 1, barf. + +#if [ $$ -ne 1 ] +#then +# echo "SKIPPED: mount test requires emulation environment" +# exit 0 +#fi + +# Run tests within the chroot environment. +dochroot bash rm ls ln cat ps mknod mkdir dd grep cmp diff tail \ + mkfs.ext2 mkfs.vfat mount umount losetup wc << EOF +#!/bin/bash + +. /testing.sh + +mknod /dev/loop0 b 7 0 +mknod /dev/loop1 b 7 1 + +# We need /proc to do much. Make sure we can mount it explicitly. + +testing "mount no proc [GNUFAIL]" "mount 2> /dev/null || echo yes" "yes\n" "" "" +testing "mount /proc" "mount -t proc /proc /proc && ls -d /proc/1" \ + "/proc/1\n" "" "" + +# Make sure the last thing in the list is /proc + +testing "mount list1" "mount | tail -n 1" "/proc on /proc type proc (rw)\n" \ + "" "" + + +# Create an ext2 image + +mkdir -p images/{ext2.dir,vfat.dir,test1,test2,test3} +dd if=/dev/zero of=images/ext2.img bs=1M count=1 2> /dev/null +mkfs.ext2 -F -b 1024 images/ext2.img > /dev/null 2> /dev/null +dd if=/dev/zero of=images/vfat.img bs=1M count=1 2> /dev/null +mkfs.vfat images/vfat.img > /dev/null + +# Test mount it + +testing "mount vfat image (explicitly autodetect type)" \ + "mount -t auto images/vfat.img images/vfat.dir && mount | tail -n 1 | grep -o 'vfat.dir type vfat'" \ + "vfat.dir type vfat\n" "" "" +testing "mount ext2 image (autodetect type)" \ + "mount images/ext2.img images/ext2.dir 2> /dev/null && mount | tail -n 1" \ + "/dev/loop1 on /images/ext2.dir type ext2 (rw)\n" "" "" +testing "mount remount ext2 image noatime" \ + "mount -o remount,noatime images/ext2.dir && mount | tail -n 1" \ + "/dev/loop1 on /images/ext2.dir type ext2 (rw,noatime)\n" "" "" +testing "mount remount ext2 image ro remembers noatime" \ + "mount -o remount,ro images/ext2.dir && mount | tail -n 1" \ + "/dev/loop1 on /images/ext2.dir type ext2 (ro,noatime)\n" "" "" + +umount -d images/vfat.dir +umount -d images/ext2.dir + +testing "mount umount freed loop device" \ + "mount images/ext2.img images/ext2.dir && mount | tail -n 1" \ + "/dev/loop0 on /images/ext2.dir type ext2 (rw)\n" "" "" + +testing "mount block device" \ + "mount -t ext2 /dev/loop0 images/test1 && mount | tail -n 1" \ + "/dev/loop0 on /images/test1 type ext2 (rw)\n" "" "" + +umount -d images/ext2.dir images/test1 + +testing "mount remount nonexistent directory" \ + "mount -o remount,noatime images/ext2.dir 2> /dev/null || echo yes" \ + "yes\n" "" "" + +# Fun with mount -a + +testing "mount -a no fstab" "mount -a 2>/dev/null || echo yes" "yes\n" "" "" + +umount /proc + +# The first field is space delimited, the rest tabs. + +cat > /etc/fstab << FSTAB +/proc /proc proc defaults 0 0 +# Autodetect loop, and provide flags with commas in them. +/images/ext2.img /images/ext2.dir ext2 noatime,nodev 0 0 +# autodetect filesystem, flags without commas. +/images/vfat.img /images/vfat.dir auto ro 0 0 +# A block device +/dev/loop2 /images/test1 auto defaults 0 0 +# tmpfs, filesystem specific flag. +walrus /images/test2 tmpfs size=42 0 0 +# Autodetect a bind mount. +/images/test2 /images/test3 auto defaults 0 0 +FSTAB + +# Put something on loop2. +mknod /dev/loop2 b 7 2 +cat images/ext2.img > images/ext2-2.img +losetup /dev/loop2 images/ext2-2.img + +testing "mount -a" "mount -a && echo hello > /images/test2/abc && cat /images/test3/abc && (mount | wc -l)" "hello\n8\n" "" "" + +testing "umount -a" "umount -a && ls /proc" "" "" "" + +#/bin/bash < /dev/tty > /dev/tty 2> /dev/tty +mknod /dev/console c 5 1 +/bin/bash < /dev/console > /dev/console 2> /dev/console +EOF + +exit 0 + +# Run some tests + +losetup nonexistent device (should return error 2) +losetup unbound loop device (should return error 1) +losetup bind file to loop device +losetup bound loop device (display) (should return error 0) +losetup filename (error) +losetup nofile (file not found) +losetup -d +losetup bind with offset +losetup -f (print first loop device) +losetup -f filename (associate file with first loop device) +losetup -o (past end of file) -f filename + +mount -a + with multiple entries in fstab + with duplicate entries in fstab + with relative paths in fstab + with user entries in fstab +mount -o async,sync,atime,noatime,dev,nodev,exec,noexec,loop,suid,nosuid,remount,ro,rw,bind,move +mount -r +mount -o rw -r +mount -w -o ro +mount -t auto + +mount with relative path in fstab +mount block device +mount char device +mount file (autoloop) +mount directory (autobind) + + +testing "umount with no /proc" +testing "umount curdir" + +# 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" \ + "point\nwook\npabst\naargh\nwalrus\n" "" + +optional FEATURE_MOUNT_LOOP +testing "umount -D" + +optional FEATURE_MTAB_SUPPORT +optional FEATURE_MOUNT_NFS +# No idea what to test here. + +optional UMOUNT +optional FEATURE_UMOUNT_ALL +testing "umount -a" +testing "umount -r" +testing "umount -l" +testing "umount -f" + +exit $FAILCOUNT diff --git a/testsuite/msh/msh-supports-underscores-in-variable-names b/testsuite/msh/msh-supports-underscores-in-variable-names new file mode 100644 index 000000000..9c7834b37 --- /dev/null +++ b/testsuite/msh/msh-supports-underscores-in-variable-names @@ -0,0 +1 @@ +test "`busybox msh -c 'FOO_BAR=foo; echo $FOO_BAR'`" = foo diff --git a/testsuite/mv/mv-files-to-dir b/testsuite/mv/mv-files-to-dir new file mode 100644 index 000000000..c8eaba88e --- /dev/null +++ b/testsuite/mv/mv-files-to-dir @@ -0,0 +1,16 @@ +echo file number one > file1 +echo file number two > file2 +ln -s file2 link1 +mkdir dir1 +touch --date='Sat Jan 29 21:24:08 PST 2000' dir1/file3 +mkdir there +busybox mv file1 file2 link1 dir1 there +test -f there/file1 +test -f there/file2 +test -f there/dir1/file3 +test -L there/link1 +test xfile2 = x`readlink there/link1` +test ! -e file1 +test ! -e file2 +test ! -e link1 +test ! -e dir1/file3 diff --git a/testsuite/mv/mv-follows-links b/testsuite/mv/mv-follows-links new file mode 100644 index 000000000..1fb355b81 --- /dev/null +++ b/testsuite/mv/mv-follows-links @@ -0,0 +1,4 @@ +touch foo +ln -s foo bar +busybox mv bar baz +test -f baz diff --git a/testsuite/mv/mv-moves-empty-file b/testsuite/mv/mv-moves-empty-file new file mode 100644 index 000000000..48afca4d5 --- /dev/null +++ b/testsuite/mv/mv-moves-empty-file @@ -0,0 +1,4 @@ +touch foo +busybox mv foo bar +test ! -e foo +test -f bar diff --git a/testsuite/mv/mv-moves-file b/testsuite/mv/mv-moves-file new file mode 100644 index 000000000..edb4c3751 --- /dev/null +++ b/testsuite/mv/mv-moves-file @@ -0,0 +1,3 @@ +touch foo +busybox mv foo bar +test ! -f foo -a -f bar diff --git a/testsuite/mv/mv-moves-hardlinks b/testsuite/mv/mv-moves-hardlinks new file mode 100644 index 000000000..eaa8215a4 --- /dev/null +++ b/testsuite/mv/mv-moves-hardlinks @@ -0,0 +1,4 @@ +touch foo +ln foo bar +busybox mv bar baz +test ! -f bar -a -f baz diff --git a/testsuite/mv/mv-moves-large-file b/testsuite/mv/mv-moves-large-file new file mode 100644 index 000000000..77d088ff1 --- /dev/null +++ b/testsuite/mv/mv-moves-large-file @@ -0,0 +1,4 @@ +dd if=/dev/zero of=foo seek=10k count=1 2>/dev/null +busybox mv foo bar +test ! -e foo +test -f bar diff --git a/testsuite/mv/mv-moves-small-file b/testsuite/mv/mv-moves-small-file new file mode 100644 index 000000000..065c7f1e9 --- /dev/null +++ b/testsuite/mv/mv-moves-small-file @@ -0,0 +1,4 @@ +echo I WANT > foo +busybox mv foo bar +test ! -e foo +test -f bar diff --git a/testsuite/mv/mv-moves-symlinks b/testsuite/mv/mv-moves-symlinks new file mode 100644 index 000000000..c413af07c --- /dev/null +++ b/testsuite/mv/mv-moves-symlinks @@ -0,0 +1,6 @@ +touch foo +ln -s foo bar +busybox mv bar baz +test -f foo +test ! -e bar +test -L baz diff --git a/testsuite/mv/mv-moves-unreadable-files b/testsuite/mv/mv-moves-unreadable-files new file mode 100644 index 000000000..bc9c3133c --- /dev/null +++ b/testsuite/mv/mv-moves-unreadable-files @@ -0,0 +1,5 @@ +touch foo +chmod a-r foo +busybox mv foo bar +test ! -e foo +test -f bar diff --git a/testsuite/mv/mv-preserves-hard-links b/testsuite/mv/mv-preserves-hard-links new file mode 100644 index 000000000..b3ba3aa29 --- /dev/null +++ b/testsuite/mv/mv-preserves-hard-links @@ -0,0 +1,6 @@ +# FEATURE: CONFIG_FEATURE_PRESERVE_HARDLINKS +touch foo +ln foo bar +mkdir baz +busybox mv foo bar baz +test baz/foo -ef baz/bar diff --git a/testsuite/mv/mv-preserves-links b/testsuite/mv/mv-preserves-links new file mode 100644 index 000000000..ea565d2f1 --- /dev/null +++ b/testsuite/mv/mv-preserves-links @@ -0,0 +1,5 @@ +touch foo +ln -s foo bar +busybox mv bar baz +test -L baz +test xfoo = x`readlink baz` diff --git a/testsuite/mv/mv-refuses-mv-dir-to-subdir b/testsuite/mv/mv-refuses-mv-dir-to-subdir new file mode 100644 index 000000000..7c572c4f8 --- /dev/null +++ b/testsuite/mv/mv-refuses-mv-dir-to-subdir @@ -0,0 +1,23 @@ +echo file number one > file1 +echo file number two > file2 +ln -s file2 link1 +mkdir dir1 +touch --date='Sat Jan 29 21:24:08 PST 2000' dir1/file3 +mkdir there +busybox mv file1 file2 link1 dir1 there +test -f there/file1 +test -f there/file2 +test -f there/dir1/file3 +test -L there/link1 +test xfile2 = x`readlink there/link1` +test ! -e file1 +test ! -e file2 +test ! -e link1 +test ! -e dir1/file3 +set +e +busybox mv there there/dir1 +if [ $? != 0 ] ; then + exit 0; +fi + +exit 1; diff --git a/testsuite/mv/mv-removes-source-file b/testsuite/mv/mv-removes-source-file new file mode 100644 index 000000000..48afca4d5 --- /dev/null +++ b/testsuite/mv/mv-removes-source-file @@ -0,0 +1,4 @@ +touch foo +busybox mv foo bar +test ! -e foo +test -f bar diff --git a/testsuite/pidof.tests b/testsuite/pidof.tests new file mode 100755 index 000000000..bfde26e2c --- /dev/null +++ b/testsuite/pidof.tests @@ -0,0 +1,29 @@ +#!/bin/sh + +# pidof tests. +# Copyright 2005 by Bernhard Fischer +# Licensed under GPL v2, see file LICENSE for details. + +# AUDIT: + +. testing.sh + +# testing "test name" "options" "expected result" "file input" "stdin" + +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" "pidof -s init" "1\n" "" "" + +optional FEATURE_PIDOF_OMIT +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/pwd/pwd-prints-working-directory b/testsuite/pwd/pwd-prints-working-directory new file mode 100644 index 000000000..8575347d6 --- /dev/null +++ b/testsuite/pwd/pwd-prints-working-directory @@ -0,0 +1 @@ +test $(pwd) = $(busybox pwd) diff --git a/testsuite/readlink.tests b/testsuite/readlink.tests new file mode 100755 index 000000000..0faa6ed0c --- /dev/null +++ b/testsuite/readlink.tests @@ -0,0 +1,32 @@ +#!/bin/sh + +# Readlink tests. +# Copyright 2006 by Natanael Copa <n@tanael.org> +# Licensed under GPL v2, see file LICENSE for details. + +. testing.sh + +TESTDIR=readlink_testdir +TESTFILE="$TESTDIR/testfile" +TESTLINK="testlink" +FAILLINK="$TESTDIR/$TESTDIR/testlink" + +# create the dir and test files +mkdir -p "./$TESTDIR" +touch "./$TESTFILE" +ln -s "./$TESTFILE" "./$TESTLINK" + +testing "readlink on a file" "readlink ./$TESTFILE" "" "" "" +testing "readlink on a link" "readlink ./$TESTLINK" "./$TESTFILE\n" "" "" + +optional FEATURE_READLINK_FOLLOW + +testing "readlink -f on a file" "readlink -f ./$TESTFILE" "$PWD/$TESTFILE\n" "" "" +testing "readlink -f on a link" "readlink -f ./$TESTLINK" "$PWD/$TESTFILE\n" "" "" +testing "readlink -f on an invalid link" "readlink -f ./$FAILLINK" "" "" "" +testing "readlink -f on a wierd dir" "readlink -f $TESTDIR/../$TESTFILE" "$PWD/$TESTFILE\n" "" "" + + +# clean up +rm -r "$TESTLINK" "$TESTDIR" + diff --git a/testsuite/rm/rm-removes-file b/testsuite/rm/rm-removes-file new file mode 100644 index 000000000..46571a98a --- /dev/null +++ b/testsuite/rm/rm-removes-file @@ -0,0 +1,3 @@ +touch foo +busybox rm foo +test ! -f foo diff --git a/testsuite/rmdir/rmdir-removes-parent-directories b/testsuite/rmdir/rmdir-removes-parent-directories new file mode 100644 index 000000000..222f5dec7 --- /dev/null +++ b/testsuite/rmdir/rmdir-removes-parent-directories @@ -0,0 +1,3 @@ +mkdir -p foo/bar +busybox rmdir -p foo/bar +test ! -d foo diff --git a/testsuite/runtest b/testsuite/runtest new file mode 100755 index 000000000..84cd6a7f3 --- /dev/null +++ b/testsuite/runtest @@ -0,0 +1,140 @@ +#!/bin/sh + +[ -n "$srcdir" ] || srcdir=$(pwd) +[ -n "$bindir" ] || bindir=$(dirname $(pwd)) +PATH=$bindir:$PATH + +# Run old-style test. + +function run_applet_testcase +{ + local applet=$1 + local testcase=$2 + + local status=0 + local RES= + + local uc_applet=$(echo $applet | tr a-z A-Z) + local testname=$(basename $testcase) + + if grep -q "^# CONFIG_${uc_applet} is not set$" $bindir/.config; then + echo UNTESTED: $testname + return 0 + fi + + if grep -q "^# FEATURE: " $testcase; then + local feature=`sed -ne 's/^# FEATURE: //p' $testcase` + + if grep -q "^# ${feature} is not set$" $bindir/.config; then + echo UNTESTED: $testname + return 0 + fi + fi + + rm -rf tmp + mkdir -p tmp + pushd tmp > /dev/null + + d=$srcdir sh -x -e $testcase >.logfile.txt 2>&1 || status=$? + + if [ $status -ne 0 ] ; then + echo FAIL: $testname + if [ $verbose -gt 0 ]; then + cat .logfile.txt + fi + status=$? + else + echo PASS: $testname + rm -f .logfile.txt + status=$? + fi + + popd > /dev/null + rm -rf tmp + + return $status +} + +run_applet_tests () +{ + local applet=$1 + + local status=0 + + for testcase in $srcdir/$applet/*; do + if [ "$testcase" = "$srcdir/$applet/CVS" ]; then + continue + fi + + if run_applet_testcase $applet $testcase; then + : + else + status=1 + fi + done + + return $status +} + + +status=0 +verbose=0 + +if [ x"$1" = x"-v" ]; then + verbose=1 + export VERBOSE=$verbose + shift +fi + +if [ $# -ne 0 ]; then + applets=$(cd $srcdir ; for i in $@; do ls ${i}* ; done) +else + applets=$(ls $srcdir) +fi + +# Populate a directory with links to all busybox applets + +LINKSDIR="${bindir}/runtest-tempdir-links" +rm -rf "$LINKSDIR" 2>/dev/null +mkdir "$LINKSDIR" +for i in $(sed 's@/[a-z0-9/\[]*/@@' $bindir/busybox.links 2>/dev/null) +do + ln -s $bindir/busybox "$LINKSDIR"/$i +done + +# Set up option flags so tests can be selective. + +configfile=${bindir:-../../}/.config +export OPTIONFLAGS=:$(echo $(sed -nr 's/^CONFIG_(.*)=.*/\1/p' $configfile) | sed 's/ /:/g') + +for applet in $applets; do + if [ "$applet" = "links" ]; then continue; fi + if [ "$applet" != "CVS" -a -d "$srcdir/$applet" ]; then + if run_applet_tests $applet; then + : + else + status=1 + fi + fi + + # Is this a new-style test? + applet=$(echo "$applet" | sed -n 's/\.tests$//p') + if [ ${#applet} -ne 0 ] + then + if [ ! -h "$LINKSDIR/$applet" ] && [ "${applet:0:4}" != "all_" ] + then + echo "SKIPPED: $applet (not built)" + continue + fi + if PATH="$LINKSDIR":$srcdir:$bindir:$PATH \ + "${srcdir:-.}/$applet".tests + then + : + else + status=1 + fi + fi + +done +rm -rf "$LINKSDIR" +exit $status diff --git a/testsuite/sed.tests b/testsuite/sed.tests new file mode 100755 index 000000000..2a0d4eacf --- /dev/null +++ b/testsuite/sed.tests @@ -0,0 +1,187 @@ +#!/bin/sh + +# SUSv3 compliant sed tests. +# Copyright 2005 by Rob Landley <rob@landley.net> +# Licensed under GPL v2, see file LICENSE for details. + +. testing.sh + +# testing "description" "arguments" "result" "infile" "stdin" + +# Corner cases +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? + +# -e corner cases +# without -e +# multiple -e +# interact with a +# -eee arg1 arg2 arg3 +# -f corner cases +# -e -f -e +# -n corner cases +# no newline at EOF? +# -r corner cases +# Just make sure it works. +# -i corner cases: +# sed -i - +# permissions +# -i on a symlink +# on a directory +# With $ last-line test +# Continue with \ +# End of script with trailing \ + +# command list +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" "sed -e 'i\' -e '1' -e 'a\' -e '3'" \ + "1\n2\n3\n" "" "2\n" + +# substitutions +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" "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" "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)" "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)" "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)" "sed -e 's/a/b/;:loop;t loop'" \ + "b\nb\nc\n" "" "a\nb\nc\n" +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)" "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)" "sed -e 'N;p'" \ + "a\nb\na\nb\nc\n" "" "a\nb\nc\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)" \ + "sed -n 'N;P;p'" "a\na\nb\n" "" "a\nb\nc\n" + +# Hold space +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" \ + "sed -e '/ook/d;s/ook/ping/p;i woot'" "" "" "ook\n" +testing "sed d ends script iteration (2)" \ + "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" "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" "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" "sed -e 's/woo/bang/' input -" "bang\nbang\n" \ + "woo\n" "woo\n" +testing "sed leave off trailing newline" "sed -e 's/woo/bang/' input -" \ + "bang\nbang" "woo\n" "woo" +testing "sed autoinsert newline" "sed -e 's/woo/bang/' input -" "bang\nbang" \ + "woo" "woo" +testing "sed empty file plus cat" "sed -e 's/nohit//' input -" "one\ntwo" \ + "" "one\ntwo" +testing "sed cat plus empty file" "sed -e 's/nohit//' input -" "one\ntwo" \ + "one\ntwo" "" +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" "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" "sed -ne 's/woo/bang/' input" \ + "" "no\n" "" +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" \ + "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" "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" \ + "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" "sed --version | grep -o 'GNU sed version '" \ + "GNU sed version \n" "" "" + +# Jump to nonexistent label +testing "sed nonexistent label" "sed -e 'b walrus' 2> /dev/null || echo yes" \ + "yes\n" "" "" + +testing "sed backref from empty s uses range regex" \ + "sed -e '/woot/s//eep \0 eep/'" "eep woot eep" "" "woot" + +testing "sed backref from empty s uses range regex with newline" \ + "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]" "sed -e '' -i 2> /dev/null || echo yes" \ + "yes\n" "" "" +rm ./- # Clean up + +testing "sed s/xxx/[/" "sed -e 's/xxx/[/'" "[\n" "" "xxx\n" + +# Ponder this a bit more, why "woo not found" from gnu version? +#testing "sed doesn't substitute in deleted line" \ +# "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," \ +# "" "12345" + +exit $FAILCOUNT diff --git a/testsuite/seq.tests b/testsuite/seq.tests new file mode 100755 index 000000000..ebb44e7a6 --- /dev/null +++ b/testsuite/seq.tests @@ -0,0 +1,36 @@ +#!/bin/sh + +# SUSv3 compliant seq tests. +# Copyright 2006 by Rob Landley <rob@landley.net> +# Licensed under GPL v2, see file LICENSE for details. + +# AUDIT: Full SUSv3 coverage (except internationalization). + +. testing.sh + +# testing "test name" "options" "expected result" "file input" "stdin" +# file input will be file called "input" +# test can create a file "actual" instead of writing to stdout + +# Test exit status + +testing "seq (exit with error)" "seq 2> /dev/null || echo yes" "yes\n" "" "" +testing "seq (exit with error)" "seq 1 2 3 4 2> /dev/null || echo yes" \ + "yes\n" "" "" +testing "seq one argument" "seq 3" "1\n2\n3\n" "" "" +testing "seq two arguments" "seq 5 7" "5\n6\n7\n" "" "" +testing "seq two arguments reversed" "seq 7 5" "" "" "" +testing "seq two arguments equal" "seq 3 3" "3\n" "" "" +testing "seq two arguments equal, arbitrary negative step" "seq 1 -15 1" \ + "1\n" "" "" +testing "seq two arguments equal, arbitrary positive step" "seq 1 +15 1" \ + "1\n" "" "" +testing "seq count up by 2" "seq 4 2 8" "4\n6\n8\n" "" "" +testing "seq count down by 2" "seq 8 -2 4" "8\n6\n4\n" "" "" +testing "seq count wrong way #1" "seq 4 -2 8" "" "" "" +testing "seq count wrong way #2" "seq 8 2 4" "" "" "" +testing "seq count by .3" "seq 3 .3 4" "3\n3.3\n3.6\n3.9\n" "" "" +testing "seq count by -.9" "seq .7 -.9 -2.2" "0.7\n-0.2\n-1.1\n-2\n" "" "" +testing "seq count by zero" "seq 4 0 8 | head -n 10" "" "" "" + +exit $FAILCOUNT diff --git a/testsuite/sort.tests b/testsuite/sort.tests new file mode 100755 index 000000000..5a4937b58 --- /dev/null +++ b/testsuite/sort.tests @@ -0,0 +1,83 @@ +#!/bin/bash + +# SUSv3 compliant sort tests. +# Copyright 2005 by Rob Landley <rob@landley.net> +# Licensed under GPL v2, see file LICENSE for details. + +. testing.sh + +# The basic tests. These should work even with the small busybox. + +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. + +optional FEATURE_SORT_BIG +# Longish chunk of data re-used by the next few tests + +data="42 1 3 woot +42 1 010 zoology +egg 1 2 papyrus +7 3 42 soup +999 3 0 algebra +" + +# Sorting with keys + +testing "sort one key" "sort -k4,4 input" \ +"999 3 0 algebra +egg 1 2 papyrus +7 3 42 soup +42 1 3 woot +42 1 010 zoology +" "$data" "" + +testing "sort key range with numeric option" "sort -k2,3n input" \ +"42 1 010 zoology +42 1 3 woot +egg 1 2 papyrus +7 3 42 soup +999 3 0 algebra +" "$data" "" + +# Busybox is definitely doing this one wrong just now. FIXME + +testing "sort key range with numeric option and global reverse" \ +"sort -k2,3n -r input" \ +"egg 1 2 papyrus +42 1 3 woot +42 1 010 zoology +999 3 0 algebra +7 3 42 soup +" "$data" "" + +# + +testing "sort key range with multiple options" "sort -k2,3rn input" \ +"7 3 42 soup +999 3 0 algebra +42 1 010 zoology +42 1 3 woot +egg 1 2 papyrus +" "$data" "" + +testing "sort key doesn't strip leading blanks, disables fallback global sort" \ +"sort -n -k2 -t ' '" " a \n 1 \n 2 \n" "" " 2 \n 1 \n a \n" + +testing "sort key edge case with -t" "sort -n -k4 -t/" \ +"/usr/lib/finish-install.d/1 +/usr/lib/finish-install.d/4 +/usr/lib/prebaseconfig.d/2 +/usr/lib/prebaseconfig.d/6 +" "" "/usr/lib/finish-install.d/1 +/usr/lib/prebaseconfig.d/2 +/usr/lib/finish-install.d/4 +/usr/lib/prebaseconfig.d/6 +" + +exit $FAILCOUNT diff --git a/testsuite/strings/strings-works-like-GNU b/testsuite/strings/strings-works-like-GNU new file mode 100644 index 000000000..2d6471033 --- /dev/null +++ b/testsuite/strings/strings-works-like-GNU @@ -0,0 +1,9 @@ +rm -f foo bar +strings -af ../../busybox > foo +busybox strings -af ../../busybox > bar +set +e +test ! -f foo -a -f bar +if [ $? = 0 ] ; then + set -e + diff -q foo bar +fi diff --git a/testsuite/tail/tail-n-works b/testsuite/tail/tail-n-works new file mode 100644 index 000000000..27a905f88 --- /dev/null +++ b/testsuite/tail/tail-n-works @@ -0,0 +1,4 @@ +[ -n "$d" ] || d=.. +tail -n 2 "$d/README" > logfile.gnu +busybox tail -n 2 "$d/README" > logfile.bb +cmp logfile.gnu logfile.bb diff --git a/testsuite/tail/tail-works b/testsuite/tail/tail-works new file mode 100644 index 000000000..27a905f88 --- /dev/null +++ b/testsuite/tail/tail-works @@ -0,0 +1,4 @@ +[ -n "$d" ] || d=.. +tail -n 2 "$d/README" > logfile.gnu +busybox tail -n 2 "$d/README" > logfile.bb +cmp logfile.gnu logfile.bb diff --git a/testsuite/tar/tar-archives-multiple-files b/testsuite/tar/tar-archives-multiple-files new file mode 100644 index 000000000..245d9e989 --- /dev/null +++ b/testsuite/tar/tar-archives-multiple-files @@ -0,0 +1,6 @@ +# FEATURE: CONFIG_FEATURE_TAR_CREATE +touch foo bar +busybox tar cf foo.tar foo bar +rm foo bar +tar xf foo.tar +test -f foo -a -f bar diff --git a/testsuite/tar/tar-complains-about-missing-file b/testsuite/tar/tar-complains-about-missing-file new file mode 100644 index 000000000..26e8cbb36 --- /dev/null +++ b/testsuite/tar/tar-complains-about-missing-file @@ -0,0 +1,3 @@ +touch foo +tar cf foo.tar foo +! busybox tar xf foo.tar bar diff --git a/testsuite/tar/tar-demands-at-least-one-ctx b/testsuite/tar/tar-demands-at-least-one-ctx new file mode 100644 index 000000000..85e7f6059 --- /dev/null +++ b/testsuite/tar/tar-demands-at-least-one-ctx @@ -0,0 +1 @@ +! busybox tar v diff --git a/testsuite/tar/tar-demands-at-most-one-ctx b/testsuite/tar/tar-demands-at-most-one-ctx new file mode 100644 index 000000000..130d0e7f9 --- /dev/null +++ b/testsuite/tar/tar-demands-at-most-one-ctx @@ -0,0 +1 @@ +! busybox tar tx diff --git a/testsuite/tar/tar-extracts-all-subdirs b/testsuite/tar/tar-extracts-all-subdirs new file mode 100644 index 000000000..886c37ce9 --- /dev/null +++ b/testsuite/tar/tar-extracts-all-subdirs @@ -0,0 +1,12 @@ +# FEATURE: CONFIG_FEATURE_TAR_CREATE +mkdir -p foo/{1,2,3} +mkdir -p foo/1/{10,11} +mkdir -p foo/1/10/{100,101,102} +tar cf foo.tar -C foo . +rm -rf foo/* +busybox tar xf foo.tar -C foo ./1/10 +find foo | sort >logfile.bb +rm -rf foo/* +tar xf foo.tar -C foo ./1/10 +find foo | sort >logfile.gnu +cmp logfile.gnu logfile.bb diff --git a/testsuite/tar/tar-extracts-file b/testsuite/tar/tar-extracts-file new file mode 100644 index 000000000..ca72f2489 --- /dev/null +++ b/testsuite/tar/tar-extracts-file @@ -0,0 +1,5 @@ +touch foo +tar cf foo.tar foo +rm foo +busybox tar xf foo.tar +test -f foo diff --git a/testsuite/tar/tar-extracts-from-standard-input b/testsuite/tar/tar-extracts-from-standard-input new file mode 100644 index 000000000..a30e9f0b9 --- /dev/null +++ b/testsuite/tar/tar-extracts-from-standard-input @@ -0,0 +1,5 @@ +touch foo +tar cf foo.tar foo +rm foo +cat foo.tar | busybox tar x +test -f foo diff --git a/testsuite/tar/tar-extracts-multiple-files b/testsuite/tar/tar-extracts-multiple-files new file mode 100644 index 000000000..8ae8cdda5 --- /dev/null +++ b/testsuite/tar/tar-extracts-multiple-files @@ -0,0 +1,6 @@ +touch foo bar +busybox tar cf foo.tar foo bar +rm foo bar +busybox tar -xf foo.tar +test -f foo +test -f bar diff --git a/testsuite/tar/tar-extracts-to-standard-output b/testsuite/tar/tar-extracts-to-standard-output new file mode 100644 index 000000000..ca48e364e --- /dev/null +++ b/testsuite/tar/tar-extracts-to-standard-output @@ -0,0 +1,3 @@ +echo foo > foo +tar cf foo.tar foo +cat foo.tar | busybox tar Ox | cmp foo - diff --git a/testsuite/tar/tar-handles-cz-options b/testsuite/tar/tar-handles-cz-options new file mode 100644 index 000000000..5b55e46d3 --- /dev/null +++ b/testsuite/tar/tar-handles-cz-options @@ -0,0 +1,5 @@ +# FEATURE: CONFIG_FEATURE_TAR_CREATE +# FEATURE: CONFIG_FEATURE_TAR_GZIP +touch foo +busybox tar czf foo.tar.gz foo +gzip -d foo.tar.gz diff --git a/testsuite/tar/tar-handles-empty-include-and-non-empty-exclude-list b/testsuite/tar/tar-handles-empty-include-and-non-empty-exclude-list new file mode 100644 index 000000000..503364230 --- /dev/null +++ b/testsuite/tar/tar-handles-empty-include-and-non-empty-exclude-list @@ -0,0 +1,6 @@ +# FEATURE: CONFIG_FEATURE_TAR_FROM +# FEATURE: CONFIG_FEATURE_TAR_CREATE +touch foo +tar cf foo.tar foo +echo foo >foo.exclude +busybox tar xf foo.tar -X foo.exclude diff --git a/testsuite/tar/tar-handles-exclude-and-extract-lists b/testsuite/tar/tar-handles-exclude-and-extract-lists new file mode 100644 index 000000000..2de0f0e91 --- /dev/null +++ b/testsuite/tar/tar-handles-exclude-and-extract-lists @@ -0,0 +1,8 @@ +# FEATURE: CONFIG_FEATURE_TAR_FROM +# FEATURE: CONFIG_FEATURE_TAR_CREATE +touch foo bar baz +tar cf foo.tar foo bar baz +echo foo >foo.exclude +rm foo bar baz +busybox tar xf foo.tar foo bar -X foo.exclude +test ! -f foo -a -f bar -a ! -f baz diff --git a/testsuite/tar/tar-handles-multiple-X-options b/testsuite/tar/tar-handles-multiple-X-options new file mode 100644 index 000000000..155b27e68 --- /dev/null +++ b/testsuite/tar/tar-handles-multiple-X-options @@ -0,0 +1,10 @@ +# FEATURE: CONFIG_FEATURE_TAR_FROM +# FEATURE: CONFIG_FEATURE_TAR_CREATE +touch foo +touch bar +tar cf foo.tar foo bar +echo foo > foo.exclude +echo bar > bar.exclude +rm foo bar +busybox tar xf foo.tar -X foo.exclude -X bar.exclude +test ! -f foo -a ! -f bar diff --git a/testsuite/tar/tar-handles-nested-exclude b/testsuite/tar/tar-handles-nested-exclude new file mode 100644 index 000000000..39013a105 --- /dev/null +++ b/testsuite/tar/tar-handles-nested-exclude @@ -0,0 +1,9 @@ +# FEATURE: CONFIG_FEATURE_TAR_FROM +# FEATURE: CONFIG_FEATURE_TAR_CREATE +mkdir foo +touch foo/bar +tar cf foo.tar foo +rm -rf foo +echo foo/bar >foobar.exclude +busybox tar xf foo.tar foo -X foobar.exclude +test -d foo -a ! -f foo/bar diff --git a/testsuite/tee/tee-appends-input b/testsuite/tee/tee-appends-input new file mode 100644 index 000000000..cff20bf7f --- /dev/null +++ b/testsuite/tee/tee-appends-input @@ -0,0 +1,5 @@ +echo i\'m a little teapot >foo +cp foo bar +echo i\'m a little teapot >>foo +echo i\'m a little teapot | busybox tee -a bar >/dev/null +cmp foo bar diff --git a/testsuite/tee/tee-tees-input b/testsuite/tee/tee-tees-input new file mode 100644 index 000000000..26e217384 --- /dev/null +++ b/testsuite/tee/tee-tees-input @@ -0,0 +1,3 @@ +echo i\'m a little teapot >foo +echo i\'m a little teapot | busybox tee bar >baz +cmp foo bar && cmp foo baz diff --git a/testsuite/testing.sh b/testsuite/testing.sh new file mode 100755 index 000000000..e253e1aa6 --- /dev/null +++ b/testsuite/testing.sh @@ -0,0 +1,154 @@ +# Simple test harness infrastructurei for BusyBox +# +# Copyright 2005 by Rob Landley +# +# License is GPLv2, see LICENSE in the busybox tarball for full license text. + +# This file defines two functions, "testing" and "optionflag" + +# The following environment variables may be set to enable optional behavior +# in "testing": +# VERBOSE - Print the diff -u of each failed test case. +# DEBUG - Enable command tracing. +# SKIP - do not perform this test (this is set by "optionflag") +# +# The "testing" function takes five arguments: +# $1) Description to display when running command +# $2) Command line arguments to command +# $3) Expected result (on stdout) +# $4) Data written to file "input" +# $5) Data written to stdin +# +# The exit value of testing is the exit value of the command it ran. +# +# The environment variable "FAILCOUNT" contains a cumulative total of the +# number of failed tests. + +# The "optional" function is used to skip certain tests, ala: +# optionflag CONFIG_FEATURE_THINGY +# +# The "optional" function checks the environment variable "OPTIONFLAGS", +# which is either empty (in which case it always clears SKIP) or +# else contains a colon-separated list of features (in which case the function +# clears SKIP if the flag was found, or sets it to 1 if the flag was not found). + +export FAILCOUNT=0 +export SKIP= + +# Helper functions + +optional() +{ + option=`echo "$OPTIONFLAGS" | egrep "(^|:)$1(:|\$)"` + # Not set? + if [ -z "$1" ] || [ -z "$OPTIONFLAGS" ] || [ ${#option} -ne 0 ] + then + SKIP="" + return + fi + SKIP=1 +} + +# The testing function + +testing () +{ + NAME="$1" + [ -z "$1" ] && NAME=$2 + + if [ $# -ne 5 ] + then + echo "Test $NAME has the wrong number of arguments ($# $*)" >&2 + exit + fi + + [ -n "$DEBUG" ] && set -x + + if [ -n "$SKIP" ] + then + echo "SKIPPED: $NAME" + return 0 + fi + + echo -ne "$3" > expected + echo -ne "$4" > input + [ -z "$VERBOSE" ] || echo "echo '$5' | $2" + echo -ne "$5" | eval "$2" > actual + RETVAL=$? + + cmp expected actual > /dev/null + if [ $? -ne 0 ] + then + FAILCOUNT=$[$FAILCOUNT+1] + echo "FAIL: $NAME" + [ -n "$VERBOSE" ] && diff -u expected actual + else + echo "PASS: $NAME" + fi + rm -f input expected actual + + [ -n "$DEBUG" ] && set +x + + return $RETVAL +} + +# Recursively grab an executable and all the libraries needed to run it. +# Source paths beginning with / will be copied into destpath, otherwise +# the file is assumed to already be there and only its library dependencies +# are copied. + +function mkchroot +{ + [ $# -lt 2 ] && return + + echo -n . + + dest=$1 + shift + for i in "$@" + do + [ "${i:0:1}" == "/" ] || i=$(which $i) + [ -f "$dest/$i" ] && continue + if [ -e "$i" ] + then + d=`echo "$i" | grep -o '.*/'` && + mkdir -p "$dest/$d" && + cat "$i" > "$dest/$i" && + chmod +x "$dest/$i" + else + echo "Not found: $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/touch/touch-creates-file b/testsuite/touch/touch-creates-file new file mode 100644 index 000000000..4b4935421 --- /dev/null +++ b/testsuite/touch/touch-creates-file @@ -0,0 +1,2 @@ +busybox touch foo +test -f foo diff --git a/testsuite/touch/touch-does-not-create-file b/testsuite/touch/touch-does-not-create-file new file mode 100644 index 000000000..885259286 --- /dev/null +++ b/testsuite/touch/touch-does-not-create-file @@ -0,0 +1,2 @@ +busybox touch -c foo +test ! -f foo diff --git a/testsuite/touch/touch-touches-files-after-non-existent-file b/testsuite/touch/touch-touches-files-after-non-existent-file new file mode 100644 index 000000000..a869ec267 --- /dev/null +++ b/testsuite/touch/touch-touches-files-after-non-existent-file @@ -0,0 +1,3 @@ +touch -t 198001010000 bar +busybox touch -c foo bar +test x"`find bar -mtime -1`" = xbar diff --git a/testsuite/tr/tr-d-works b/testsuite/tr/tr-d-works new file mode 100644 index 000000000..d939e8b0f --- /dev/null +++ b/testsuite/tr/tr-d-works @@ -0,0 +1,4 @@ +echo testing | tr -d aeiou > logfile.gnu +echo testing | busybox tr -d aeiou > logfile.bb + +cmp logfile.gnu logfile.bb diff --git a/testsuite/tr/tr-non-gnu b/testsuite/tr/tr-non-gnu new file mode 100644 index 000000000..ffa6951ae --- /dev/null +++ b/testsuite/tr/tr-non-gnu @@ -0,0 +1 @@ +echo fdhrnzvfu bffvsentr | busybox tr '[a-z]' '[n-z][a-m]' diff --git a/testsuite/tr/tr-works b/testsuite/tr/tr-works new file mode 100644 index 000000000..9b2e90e42 --- /dev/null +++ b/testsuite/tr/tr-works @@ -0,0 +1,24 @@ +run_tr () +{ + echo -n "echo '$1' | tr '$2' '$3': " + echo "$1" | $bb tr "$2" "$3" + echo +} +tr_test () +{ + run_tr "cbaab" abc zyx + run_tr "TESTING A B C" '[A-Z]' '[a-z]' + run_tr "abc[]" "a[b" AXB + run_tr abc '[:alpha:]' A-ZA-Z + run_tr abc56 '[:alnum:]' A-ZA-Zxxxxxxxxxx + run_tr 012 '[:digit:]' abcdefghi + run_tr abc56 '[:lower:]' '[:upper:]' + run_tr " " '[:space:]' 12345 + run_tr " " '[:blank:]' 12 + run_tr 'a b' '[= =]' X + run_tr "[:" '[:' ab +} + +bb= tr_test > logfile.gnu +bb=busybox tr_test > logfile.bb +cmp logfile.gnu logfile.bb diff --git a/testsuite/true/true-is-silent b/testsuite/true/true-is-silent new file mode 100644 index 000000000..1d1bdb22f --- /dev/null +++ b/testsuite/true/true-is-silent @@ -0,0 +1 @@ +busybox true 2>&1 | cmp - /dev/null diff --git a/testsuite/true/true-returns-success b/testsuite/true/true-returns-success new file mode 100644 index 000000000..cdf2d55e5 --- /dev/null +++ b/testsuite/true/true-returns-success @@ -0,0 +1 @@ +busybox true diff --git a/testsuite/umlwrapper.sh b/testsuite/umlwrapper.sh new file mode 100755 index 000000000..e55e4dbd3 --- /dev/null +++ b/testsuite/umlwrapper.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +# Wrapper for User Mode Linux emulation environment + +RUNFILE="$(pwd)/${1}.testroot" +if [ -z "$RUNFILE" ] || [ ! -x "$RUNFILE" ] +then + echo "Can't run '$RUNFILE'" + exit 1 +fi + +shift + +if [ -z $(which linux) ] +then + echo "No User Mode Linux." + exit 1; +fi + +linux rootfstype=hostfs rw init="$RUNFILE" TESTDIR=`pwd` PATH="$PATH" $* quiet diff --git a/testsuite/uniq.tests b/testsuite/uniq.tests new file mode 100755 index 000000000..49d4bed9c --- /dev/null +++ b/testsuite/uniq.tests @@ -0,0 +1,70 @@ +#!/bin/sh + +# SUSv3 compliant uniq tests. +# Copyright 2005 by Rob Landley <rob@landley.net> +# Licensed under GPL v2, see file LICENSE for details. + +# AUDIT: Full SUSv3 coverage (except internationalization). + +. testing.sh + +# testing "test name" "options" "expected result" "file input" "stdin" +# file input will be file called "input" +# test can create a file "actual" instead of writing to stdout + +# Test exit status + +testing "uniq (exit with error)" "uniq nonexistent 2> /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)" "uniq" "one\ntwo\nthree\n" "" \ + "one\ntwo\ntwo\nthree\nthree\nthree\n" +testing "uniq - (specify stdin)" "uniq -" "one\ntwo\nthree\n" "" \ + "one\ntwo\ntwo\nthree\nthree\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)" "uniq input actual > /dev/null" \ + "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" "" +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)" "uniq input -" \ + "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" "" + + +#-f skip fields +#-s skip chars +#-c occurrences +#-d dups only +#-u + +# Test various command line options + +# Leading whitespace is a minor technical violation of the spec, +# but since gnu does it... +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) " "uniq -d" "two\nthree\n" "" \ + "one\ntwo\ntwo\nthree\nthree\nthree\n" + +testing "uniq -f -s (skip fields and chars)" "uniq -f2 -s 3" \ +"cc dd ee8 +aa bb cc9 +" "" \ +"cc dd ee8 +bb cc dd8 +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" "uniq -d -u" "" "" \ + "one\ntwo\ntwo\nthree\nthree\nthree\n" + +exit $FAILCOUNT diff --git a/testsuite/unzip.tests b/testsuite/unzip.tests new file mode 100755 index 000000000..77814886f --- /dev/null +++ b/testsuite/unzip.tests @@ -0,0 +1,38 @@ +#!/bin/sh + +# Tests for unzip. +# Copyright 2006 Rob Landley <rob@landley.net> +# Copyright 2006 Glenn McGrath <bug1@ihug.co.nz> +# Licensed under GPL v2, see file LICENSE for details. + +. testing.sh + +# testing "test name" "options" "expected result" "file input" "stdin" +# file input will be file called "input" +# test can create a file "actual" instead of writing to stdout + +# Create a scratch directory + +mkdir temp +cd temp + +# Create test file to work with. + +mkdir foo +touch foo/bar +zip foo.zip foo foo/bar > /dev/null +rm -f foo/bar +rmdir foo + +# Test that unzipping just foo doesn't create bar. +testing "unzip (subdir only)" "unzip -q foo.zip foo/ && test -d foo && test ! -f foo/bar && echo yes" "yes\n" "" "" + +rmdir foo +rm foo.zip + +# Clean up scratch directory. + +cd .. +rm -rf temp + +exit $FAILCOUNT diff --git a/testsuite/uptime/uptime-works b/testsuite/uptime/uptime-works new file mode 100644 index 000000000..80e578778 --- /dev/null +++ b/testsuite/uptime/uptime-works @@ -0,0 +1,2 @@ +busybox uptime + diff --git a/testsuite/uuencode.tests b/testsuite/uuencode.tests new file mode 100755 index 000000000..cb658db3b --- /dev/null +++ b/testsuite/uuencode.tests @@ -0,0 +1,28 @@ +#!/bin/sh + +# unit test for uuencode to test functionality. +# Copyright 2006 by Erik Hovland <erik@hovland.org> +# Licensed under GPL v2, see file LICENSE for details. + +# AUDIT: Unit tests for uuencode + +. testing.sh + +# testing "test name" "options" "expected result" "file input" "stdin" +# file input will be file called "input" +# test can create a file "actual" instead of writing to stdout + +# Test setup of standard input +saved_umask=$(umask) +umask 0 +testing "uuencode sets standard input mode correctly" \ + "uuencode foo </dev/null | head -n 1 | grep -q 666 && echo yes" "yes\n" "" "" +umask $saved_umask + +testing "uuencode correct encoding" "uuencode bb_uuenc_test.out" \ +"begin 644 bb_uuenc_test.out\nM5&AE(&9A<W0@9W)E>2!F;W@@:G5M<&5D(&]V97(@=&AE(&QA>GD@8G)O=VX@\n%9&]G+@H\`\n\`\nend\n" \ + "" "The fast grey fox jumped over the lazy brown dog.\n" +testing "uuencode correct base64 encoding" "uuencode -m bb_uuenc_test.out" \ +"begin-base64 644 bb_uuenc_test.out\nVGhlIGZhc3QgZ3JleSBmb3gganVtcGVkIG92ZXIgdGhlIGxhenkgYnJvd24g\nZG9nLgo=\n====\n" \ + "" "The fast grey fox jumped over the lazy brown dog.\n" +exit $FAILCOUNT diff --git a/testsuite/wc/wc-counts-all b/testsuite/wc/wc-counts-all new file mode 100644 index 000000000..5e2cb6e4a --- /dev/null +++ b/testsuite/wc/wc-counts-all @@ -0,0 +1 @@ +test "`echo i\'m a little teapot | busybox wc`" = ' 1 4 20' diff --git a/testsuite/wc/wc-counts-characters b/testsuite/wc/wc-counts-characters new file mode 100644 index 000000000..755864684 --- /dev/null +++ b/testsuite/wc/wc-counts-characters @@ -0,0 +1 @@ +test `echo i\'m a little teapot | busybox wc -c` -eq 20 diff --git a/testsuite/wc/wc-counts-lines b/testsuite/wc/wc-counts-lines new file mode 100644 index 000000000..5be6ed089 --- /dev/null +++ b/testsuite/wc/wc-counts-lines @@ -0,0 +1 @@ +test `echo i\'m a little teapot | busybox wc -l` -eq 1 diff --git a/testsuite/wc/wc-counts-words b/testsuite/wc/wc-counts-words new file mode 100644 index 000000000..331650e95 --- /dev/null +++ b/testsuite/wc/wc-counts-words @@ -0,0 +1 @@ +test `echo i\'m a little teapot | busybox wc -w` -eq 4 diff --git a/testsuite/wc/wc-prints-longest-line-length b/testsuite/wc/wc-prints-longest-line-length new file mode 100644 index 000000000..78831fc13 --- /dev/null +++ b/testsuite/wc/wc-prints-longest-line-length @@ -0,0 +1 @@ +test `echo i\'m a little teapot | busybox wc -L` -eq 19 diff --git a/testsuite/wget/wget--O-overrides--P b/testsuite/wget/wget--O-overrides--P new file mode 100644 index 000000000..fdb5d47c0 --- /dev/null +++ b/testsuite/wget/wget--O-overrides--P @@ -0,0 +1,3 @@ +mkdir foo +busybox wget -q -O index.html -P foo http://www.google.com/ +test -s index.html diff --git a/testsuite/wget/wget-handles-empty-path b/testsuite/wget/wget-handles-empty-path new file mode 100644 index 000000000..5b591837a --- /dev/null +++ b/testsuite/wget/wget-handles-empty-path @@ -0,0 +1 @@ +busybox wget http://www.google.com diff --git a/testsuite/wget/wget-retrieves-google-index b/testsuite/wget/wget-retrieves-google-index new file mode 100644 index 000000000..7be9a8087 --- /dev/null +++ b/testsuite/wget/wget-retrieves-google-index @@ -0,0 +1,2 @@ +busybox wget -q -O foo http://www.google.com/ +test -s foo diff --git a/testsuite/wget/wget-supports--P b/testsuite/wget/wget-supports--P new file mode 100644 index 000000000..9b4d095e6 --- /dev/null +++ b/testsuite/wget/wget-supports--P @@ -0,0 +1,3 @@ +mkdir foo +busybox wget -q -P foo http://www.google.com/ +test -s foo/index.html diff --git a/testsuite/which/which-uses-default-path b/testsuite/which/which-uses-default-path new file mode 100644 index 000000000..63ceb9f8f --- /dev/null +++ b/testsuite/which/which-uses-default-path @@ -0,0 +1,4 @@ +BUSYBOX=$(type -p busybox) +SAVED_PATH=$PATH +unset PATH +$BUSYBOX which ls diff --git a/testsuite/xargs/xargs-works b/testsuite/xargs/xargs-works new file mode 100644 index 000000000..c95869e89 --- /dev/null +++ b/testsuite/xargs/xargs-works @@ -0,0 +1,4 @@ +[ -n "$d" ] || d=.. +find "$d" -name \*works -type f | xargs md5sum > logfile.gnu +find "$d" -name \*works -type f | busybox xargs md5sum > logfile.bb +diff -u logfile.gnu logfile.bb |