2009-11-05 05:11:22 +05:30
|
|
|
#!/bin/sh
|
2005-09-02 06:11:53 +05:30
|
|
|
|
|
|
|
# SUSv3 compliant sort tests.
|
|
|
|
# Copyright 2005 by Rob Landley <rob@landley.net>
|
2010-08-16 23:44:46 +05:30
|
|
|
# Licensed under GPLv2, see file LICENSE in this source tree.
|
2005-09-02 06:11:53 +05:30
|
|
|
|
2009-11-05 05:11:22 +05:30
|
|
|
. ./testing.sh
|
2005-09-02 06:11:53 +05:30
|
|
|
|
|
|
|
# The basic tests. These should work even with the small busybox.
|
|
|
|
|
2006-03-16 20:50:45 +05:30
|
|
|
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" \
|
2005-09-02 06:11:53 +05:30
|
|
|
"point\nwook\npabst\naargh\nwalrus\n" ""
|
|
|
|
|
|
|
|
# These tests require the full option set.
|
|
|
|
|
2005-11-07 14:20:53 +05:30
|
|
|
optional FEATURE_SORT_BIG
|
2005-09-02 06:11:53 +05:30
|
|
|
# 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
|
|
|
|
"
|
|
|
|
|
2009-12-13 06:39:22 +05:30
|
|
|
# testing "description" "command(s)" "result" "infile" "stdin"
|
|
|
|
|
2005-09-02 06:11:53 +05:30
|
|
|
# Sorting with keys
|
|
|
|
|
2006-03-16 20:50:45 +05:30
|
|
|
testing "sort one key" "sort -k4,4 input" \
|
2005-09-02 06:11:53 +05:30
|
|
|
"999 3 0 algebra
|
|
|
|
egg 1 2 papyrus
|
|
|
|
7 3 42 soup
|
|
|
|
42 1 3 woot
|
|
|
|
42 1 010 zoology
|
|
|
|
" "$data" ""
|
|
|
|
|
2006-03-16 20:50:45 +05:30
|
|
|
testing "sort key range with numeric option" "sort -k2,3n input" \
|
2005-09-02 06:11:53 +05:30
|
|
|
"42 1 010 zoology
|
|
|
|
42 1 3 woot
|
|
|
|
egg 1 2 papyrus
|
|
|
|
7 3 42 soup
|
|
|
|
999 3 0 algebra
|
|
|
|
" "$data" ""
|
|
|
|
|
|
|
|
testing "sort key range with numeric option and global reverse" \
|
2006-03-16 20:50:45 +05:30
|
|
|
"sort -k2,3n -r input" \
|
2005-09-02 06:11:53 +05:30
|
|
|
"egg 1 2 papyrus
|
|
|
|
42 1 3 woot
|
|
|
|
42 1 010 zoology
|
|
|
|
999 3 0 algebra
|
|
|
|
7 3 42 soup
|
|
|
|
" "$data" ""
|
|
|
|
|
2006-03-16 20:50:45 +05:30
|
|
|
testing "sort key range with multiple options" "sort -k2,3rn input" \
|
2005-09-02 06:11:53 +05:30
|
|
|
"7 3 42 soup
|
|
|
|
999 3 0 algebra
|
|
|
|
42 1 010 zoology
|
|
|
|
42 1 3 woot
|
|
|
|
egg 1 2 papyrus
|
|
|
|
" "$data" ""
|
|
|
|
|
2007-02-17 23:41:45 +05:30
|
|
|
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
|
|
|
|
" ""
|
|
|
|
|
2007-01-07 05:51:41 +05:30
|
|
|
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
|
|
|
|
" ""
|
|
|
|
|
2015-09-20 01:36:40 +05:30
|
|
|
testing "sort with non-default leading delim 4" "sort -t: -k1,1 input" "\
|
|
|
|
a:b
|
|
|
|
a/a:a
|
|
|
|
" "\
|
|
|
|
a/a:a
|
|
|
|
a:b
|
|
|
|
" ""
|
|
|
|
|
2015-10-19 22:57:26 +05:30
|
|
|
testing "sort with ENDCHAR" "sort -t. -k1,1.1 -k2 input" "\
|
|
|
|
ab.1
|
|
|
|
aa.2
|
|
|
|
" "\
|
|
|
|
aa.2
|
|
|
|
ab.1
|
|
|
|
" ""
|
|
|
|
|
2015-10-19 18:14:51 +05:30
|
|
|
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
|
|
|
|
" ""
|
|
|
|
|
2007-01-07 05:51:41 +05:30
|
|
|
testing "sort -u should consider field only when discarding" "sort -u -k2 input" "\
|
|
|
|
a c
|
|
|
|
" "\
|
|
|
|
a c
|
|
|
|
b c
|
|
|
|
" ""
|
|
|
|
|
2008-02-13 20:00:33 +05:30
|
|
|
testing "sort -z outputs NUL terminated lines" "sort -z input" "\
|
|
|
|
one\0three\0two\0\
|
|
|
|
" "\
|
|
|
|
one\0two\0three\0\
|
|
|
|
" ""
|
|
|
|
|
2006-06-16 02:20:38 +05:30
|
|
|
testing "sort key doesn't strip leading blanks, disables fallback global sort" \
|
2006-09-17 21:58:10 +05:30
|
|
|
"sort -n -k2 -t ' '" " a \n 1 \n 2 \n" "" " 2 \n 1 \n a \n"
|
2006-06-16 02:20:38 +05:30
|
|
|
|
2009-12-13 06:39:22 +05:30
|
|
|
testing "sort file in place" \
|
2010-05-11 07:23:57 +05:30
|
|
|
"sort -o input input && cat input" "\
|
2009-12-13 06:39:22 +05:30
|
|
|
111
|
|
|
|
222
|
|
|
|
" "\
|
|
|
|
222
|
|
|
|
111
|
|
|
|
" ""
|
|
|
|
|
2022-01-05 04:23:21 +05:30
|
|
|
testing "sort -sr (stable and reverse) does NOT reverse 'stable' ordering" \
|
|
|
|
"sort -k2 -r -s input" "\
|
|
|
|
b 2
|
|
|
|
d 2
|
|
|
|
a 1
|
|
|
|
c 1
|
|
|
|
" "\
|
|
|
|
a 1
|
|
|
|
b 2
|
|
|
|
c 1
|
|
|
|
d 2
|
|
|
|
" ""
|
|
|
|
|
2022-01-05 16:35:55 +05:30
|
|
|
testing "sort -h" \
|
|
|
|
"sort -h input" "\
|
|
|
|
3e
|
|
|
|
4m
|
|
|
|
5y
|
|
|
|
1023
|
|
|
|
1024
|
|
|
|
1025
|
|
|
|
3000
|
|
|
|
2K
|
|
|
|
3k
|
|
|
|
1M
|
|
|
|
2E
|
|
|
|
1Y
|
|
|
|
" "\
|
|
|
|
1Y
|
|
|
|
5y
|
|
|
|
1M
|
|
|
|
2E
|
|
|
|
3k
|
|
|
|
3e
|
|
|
|
2K
|
|
|
|
4m
|
|
|
|
1023
|
|
|
|
1025
|
|
|
|
3000
|
|
|
|
1024
|
|
|
|
" ""
|
|
|
|
|
2009-12-13 06:39:22 +05:30
|
|
|
# testing "description" "command(s)" "result" "infile" "stdin"
|
|
|
|
|
2022-07-29 19:35:50 +05:30
|
|
|
testing "sort -k2,2M" \
|
|
|
|
"sort -k2,2M input" "\
|
|
|
|
3 March
|
|
|
|
2 April
|
|
|
|
1 May
|
|
|
|
" "\
|
|
|
|
2 April
|
|
|
|
1 May
|
|
|
|
3 March
|
|
|
|
" ""
|
|
|
|
|
2022-07-29 20:10:00 +05:30
|
|
|
testing "sort -s -u" \
|
|
|
|
"sort -s -u -k 2 input" "\
|
|
|
|
z a
|
|
|
|
z b
|
|
|
|
" "\
|
|
|
|
z b
|
|
|
|
a b
|
|
|
|
z a
|
|
|
|
a a" ""
|
|
|
|
|
2005-09-02 06:11:53 +05:30
|
|
|
exit $FAILCOUNT
|