aboutsummaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2005-09-02 00:41:53 +0000
committerRob Landley <rob@landley.net>2005-09-02 00:41:53 +0000
commit1689075c992a45a4a50f1aaad8aaf1d2983060c8 (patch)
tree679fa07497ea54120459a76464d3257862537b2e /testsuite
parentbabd3fbba668e04841cbe683ca49097fb871fca8 (diff)
downloadbusybox-1689075c992a45a4a50f1aaad8aaf1d2983060c8.tar.gz
Working on a new test harness. Moved the sort tests into it.
Diffstat (limited to 'testsuite')
-rwxr-xr-xtestsuite/runtest10
-rwxr-xr-xtestsuite/sort.tests69
-rwxr-xr-xtestsuite/testing.sh62
3 files changed, 141 insertions, 0 deletions
diff --git a/testsuite/runtest b/testsuite/runtest
index 6ba334bce..91b794317 100755
--- a/testsuite/runtest
+++ b/testsuite/runtest
@@ -97,6 +97,16 @@ for applet in $applets; do
status=1
fi
fi
+
+ if [ -f "$applet".tests ]
+ then
+ rm -f links/"$applet"
+ ln -s ../../busybox links/"$applet"
+ PATH=links:$PATH ./"$applet".tests
+ if [ $? -ne 0 ]; then status=1; fi
+ fi
+
+
done
exit $status
diff --git a/testsuite/sort.tests b/testsuite/sort.tests
new file mode 100755
index 000000000..b23cf4312
--- /dev/null
+++ b/testsuite/sort.tests
@@ -0,0 +1,69 @@
+#!/bin/sh
+
+# SUSv3 compliant sort tests.
+# 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" \
+ "point\nwook\npabst\naargh\nwalrus\n" ""
+
+# These tests require the full option set.
+
+# 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" "-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" "-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...
+
+testing "sort key range with numeric option and global reverse" \
+"-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" "-k2,3rn input" \
+"7 3 42 soup
+999 3 0 algebra
+42 1 010 zoology
+42 1 3 woot
+egg 1 2 papyrus
+" "$data" ""
+
+exit $FAILCOUNT
diff --git a/testsuite/testing.sh b/testsuite/testing.sh
new file mode 100755
index 000000000..d516f722a
--- /dev/null
+++ b/testsuite/testing.sh
@@ -0,0 +1,62 @@
+# Simple test harness infrastructurei for BusyBox
+#
+# Copyright 2005 by Rob Landley
+#
+# License is GPLv2, see LICENSE in the busybox tarball for full license text.
+
+# The "testing" function uses one environment variable:
+# COMMAND = command to execute
+#
+# The 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
+#
+
+# The command line parsing is ugly and should be improved.
+
+if [ "$1" == "-v" ]
+then
+ verbose=1
+fi
+
+export FAILCOUNT=0
+
+# The testing function
+
+function testing()
+{
+ if [ $# -ne 5 ]
+ then
+ echo "Test $1 has the wrong number of arguments" >&2
+ exit
+ fi
+
+ f=$FAILCOUNT
+ echo -ne "$3" > expected
+ echo -ne "$4" > input
+ echo -n -e "$5" | eval "$COMMAND $2" > actual
+ RETVAL=$?
+
+ cmp expected actual > /dev/null
+ if [ $? -ne 0 ]
+ then
+ FAILCOUNT=$[$FAILCOUNT+1]
+ echo FAIL:"$1"
+ if [ $verbose ]
+ then
+ diff -u expected actual
+ fi
+ else
+ echo PASS:"$1"
+ fi
+ rm -f input expected actual
+
+ return $RETVAL
+}