bc: upstream fixes
[oweals/busybox.git] / testsuite / sort.tests
index 294530988f7afcc364fb1343f98c9e7d7a84923d..c51a8e475b11b980cca060978fa34d535c6c9082 100755 (executable)
@@ -2,18 +2,17 @@
 
 # SUSv3 compliant sort tests.
 # Copyright 2005 by Rob Landley <rob@landley.net>
-# Licensed under GPL v2, see file LICENSE for details.
+# Licensed under GPLv2, see file LICENSE in this source tree.
 
-if [ ${#COMMAND} -eq 0 ]; then COMMAND=sort; fi
-. testing.sh
+. ./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.
@@ -28,9 +27,11 @@ egg  1       2       papyrus
 999    3       0       algebra
 "
 
+# testing "description" "command(s)" "result" "infile" "stdin"
+
 # 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 +39,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
@@ -46,10 +47,8 @@ egg  1       2       papyrus
 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" \
-"-k2,3n -r input" \
+"sort -k2,3n -r input" \
 "egg   1       2       papyrus
 42     1       3       woot
 42     1       010     zoology
@@ -57,9 +56,7 @@ testing "sort key range with numeric option and global reverse" \
 7      3       42      soup
 " "$data" ""
 
-# 
-
-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
@@ -67,4 +64,117 @@ testing "sort key range with multiple options" "-k2,3rn input" \
 egg    1       2       papyrus
 " "$data" ""
 
+testing "sort key range with two -k options" "sort -k 2,2n -k 1,1r input" "\
+d 2
+b 2
+c 3
+" "\
+c 3
+b 2
+d 2
+" ""
+
+testing "sort with non-default leading delim 1" "sort -n -k2 -t/ input" "\
+/a/2
+/b/1
+" "\
+/a/2
+/b/1
+" ""
+
+testing "sort with non-default leading delim 2" "sort -n -k3 -t/ input" "\
+/b/1
+/a/2
+" "\
+/b/1
+/a/2
+" ""
+
+testing "sort with non-default leading delim 3" "sort -n -k3 -t/ input" "\
+//a/2
+//b/1
+" "\
+//a/2
+//b/1
+" ""
+
+testing "sort with non-default leading delim 4" "sort -t: -k1,1 input" "\
+a:b
+a/a:a
+" "\
+a/a:a
+a:b
+" ""
+
+testing "sort with ENDCHAR" "sort -t. -k1,1.1 -k2 input" "\
+ab.1
+aa.2
+" "\
+aa.2
+ab.1
+" ""
+
+testing "glibc build sort" "sort -t. -k 1,1 -k 2n,2n -k 3 input" "\
+GLIBC_2.1
+GLIBC_2.1.1
+GLIBC_2.2
+GLIBC_2.2.1
+GLIBC_2.10
+GLIBC_2.20
+GLIBC_2.21
+" "\
+GLIBC_2.21
+GLIBC_2.1.1
+GLIBC_2.2.1
+GLIBC_2.2
+GLIBC_2.20
+GLIBC_2.10
+GLIBC_2.1
+" ""
+
+testing "glibc build sort unique" "sort -u -t. -k 1,1 -k 2n,2n -k 3 input" "\
+GLIBC_2.1
+GLIBC_2.1.1
+GLIBC_2.2
+GLIBC_2.2.1
+GLIBC_2.10
+GLIBC_2.20
+GLIBC_2.21
+" "\
+GLIBC_2.10
+GLIBC_2.2.1
+GLIBC_2.1.1
+GLIBC_2.20
+GLIBC_2.2
+GLIBC_2.1
+GLIBC_2.21
+" ""
+
+testing "sort -u should consider field only when discarding" "sort -u -k2 input" "\
+a c
+" "\
+a c
+b c
+" ""
+
+testing "sort -z outputs NUL terminated lines" "sort -z input" "\
+one\0three\0two\0\
+" "\
+one\0two\0three\0\
+" ""
+
+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 file in place" \
+"sort -o input input && cat input" "\
+111
+222
+" "\
+222
+111
+" ""
+
+# testing "description" "command(s)" "result" "infile" "stdin"
+
 exit $FAILCOUNT