Mike Frysinger | caa7940 | 2009-11-04 18:41:22 -0500 | [diff] [blame] | 1 | #!/bin/sh |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 2 | |
| 3 | # SUSv3 compliant sort tests. |
| 4 | # Copyright 2005 by Rob Landley <rob@landley.net> |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 5 | # Licensed under GPLv2, see file LICENSE in this source tree. |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 6 | |
Mike Frysinger | caa7940 | 2009-11-04 18:41:22 -0500 | [diff] [blame] | 7 | . ./testing.sh |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 8 | |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 9 | # The basic tests. These should work even with the small busybox. |
| 10 | |
Rob Landley | 4bb1b04 | 2006-03-16 15:20:45 +0000 | [diff] [blame] | 11 | testing "sort" "sort input" "a\nb\nc\n" "c\na\nb\n" "" |
| 12 | testing "sort #2" "sort input" "010\n1\n3\n" "3\n1\n010\n" "" |
| 13 | testing "sort stdin" "sort" "a\nb\nc\n" "" "b\na\nc\n" |
| 14 | testing "sort numeric" "sort -n input" "1\n3\n010\n" "3\n1\n010\n" "" |
| 15 | testing "sort reverse" "sort -r input" "wook\nwalrus\npoint\npabst\naargh\n" \ |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 16 | "point\nwook\npabst\naargh\nwalrus\n" "" |
| 17 | |
| 18 | # These tests require the full option set. |
| 19 | |
Rob Landley | 48c6157 | 2005-11-07 08:50:53 +0000 | [diff] [blame] | 20 | optional FEATURE_SORT_BIG |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 21 | # Longish chunk of data re-used by the next few tests |
| 22 | |
| 23 | data="42 1 3 woot |
| 24 | 42 1 010 zoology |
| 25 | egg 1 2 papyrus |
| 26 | 7 3 42 soup |
| 27 | 999 3 0 algebra |
| 28 | " |
| 29 | |
Denys Vlasenko | aa42d13 | 2009-12-13 02:09:22 +0100 | [diff] [blame] | 30 | # testing "description" "command(s)" "result" "infile" "stdin" |
| 31 | |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 32 | # Sorting with keys |
| 33 | |
Rob Landley | 4bb1b04 | 2006-03-16 15:20:45 +0000 | [diff] [blame] | 34 | testing "sort one key" "sort -k4,4 input" \ |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 35 | "999 3 0 algebra |
| 36 | egg 1 2 papyrus |
| 37 | 7 3 42 soup |
| 38 | 42 1 3 woot |
| 39 | 42 1 010 zoology |
| 40 | " "$data" "" |
| 41 | |
Rob Landley | 4bb1b04 | 2006-03-16 15:20:45 +0000 | [diff] [blame] | 42 | testing "sort key range with numeric option" "sort -k2,3n input" \ |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 43 | "42 1 010 zoology |
| 44 | 42 1 3 woot |
| 45 | egg 1 2 papyrus |
| 46 | 7 3 42 soup |
| 47 | 999 3 0 algebra |
| 48 | " "$data" "" |
| 49 | |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 50 | testing "sort key range with numeric option and global reverse" \ |
Rob Landley | 4bb1b04 | 2006-03-16 15:20:45 +0000 | [diff] [blame] | 51 | "sort -k2,3n -r input" \ |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 52 | "egg 1 2 papyrus |
| 53 | 42 1 3 woot |
| 54 | 42 1 010 zoology |
| 55 | 999 3 0 algebra |
| 56 | 7 3 42 soup |
| 57 | " "$data" "" |
| 58 | |
Rob Landley | 4bb1b04 | 2006-03-16 15:20:45 +0000 | [diff] [blame] | 59 | testing "sort key range with multiple options" "sort -k2,3rn input" \ |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 60 | "7 3 42 soup |
| 61 | 999 3 0 algebra |
| 62 | 42 1 010 zoology |
| 63 | 42 1 3 woot |
| 64 | egg 1 2 papyrus |
| 65 | " "$data" "" |
| 66 | |
Denis Vlasenko | 54cf511 | 2007-02-17 18:11:45 +0000 | [diff] [blame] | 67 | testing "sort key range with two -k options" "sort -k 2,2n -k 1,1r input" "\ |
| 68 | d 2 |
| 69 | b 2 |
| 70 | c 3 |
| 71 | " "\ |
| 72 | c 3 |
| 73 | b 2 |
| 74 | d 2 |
| 75 | " "" |
| 76 | |
Denis Vlasenko | 8336f08 | 2007-01-07 00:21:41 +0000 | [diff] [blame] | 77 | testing "sort with non-default leading delim 1" "sort -n -k2 -t/ input" "\ |
| 78 | /a/2 |
| 79 | /b/1 |
| 80 | " "\ |
| 81 | /a/2 |
| 82 | /b/1 |
| 83 | " "" |
| 84 | |
| 85 | testing "sort with non-default leading delim 2" "sort -n -k3 -t/ input" "\ |
| 86 | /b/1 |
| 87 | /a/2 |
| 88 | " "\ |
| 89 | /b/1 |
| 90 | /a/2 |
| 91 | " "" |
| 92 | |
| 93 | testing "sort with non-default leading delim 3" "sort -n -k3 -t/ input" "\ |
| 94 | //a/2 |
| 95 | //b/1 |
| 96 | " "\ |
| 97 | //a/2 |
| 98 | //b/1 |
| 99 | " "" |
| 100 | |
Denys Vlasenko | 8aa7cf3 | 2015-09-19 22:06:40 +0200 | [diff] [blame] | 101 | testing "sort with non-default leading delim 4" "sort -t: -k1,1 input" "\ |
| 102 | a:b |
| 103 | a/a:a |
| 104 | " "\ |
| 105 | a/a:a |
| 106 | a:b |
| 107 | " "" |
| 108 | |
Denys Vlasenko | 0506e29 | 2015-10-19 19:27:26 +0200 | [diff] [blame] | 109 | testing "sort with ENDCHAR" "sort -t. -k1,1.1 -k2 input" "\ |
| 110 | ab.1 |
| 111 | aa.2 |
| 112 | " "\ |
| 113 | aa.2 |
| 114 | ab.1 |
| 115 | " "" |
| 116 | |
Denys Vlasenko | 2e86a5c | 2015-10-19 14:44:51 +0200 | [diff] [blame] | 117 | testing "glibc build sort" "sort -t. -k 1,1 -k 2n,2n -k 3 input" "\ |
| 118 | GLIBC_2.1 |
| 119 | GLIBC_2.1.1 |
| 120 | GLIBC_2.2 |
| 121 | GLIBC_2.2.1 |
| 122 | GLIBC_2.10 |
| 123 | GLIBC_2.20 |
| 124 | GLIBC_2.21 |
| 125 | " "\ |
| 126 | GLIBC_2.21 |
| 127 | GLIBC_2.1.1 |
| 128 | GLIBC_2.2.1 |
| 129 | GLIBC_2.2 |
| 130 | GLIBC_2.20 |
| 131 | GLIBC_2.10 |
| 132 | GLIBC_2.1 |
| 133 | " "" |
| 134 | |
| 135 | testing "glibc build sort unique" "sort -u -t. -k 1,1 -k 2n,2n -k 3 input" "\ |
| 136 | GLIBC_2.1 |
| 137 | GLIBC_2.1.1 |
| 138 | GLIBC_2.2 |
| 139 | GLIBC_2.2.1 |
| 140 | GLIBC_2.10 |
| 141 | GLIBC_2.20 |
| 142 | GLIBC_2.21 |
| 143 | " "\ |
| 144 | GLIBC_2.10 |
| 145 | GLIBC_2.2.1 |
| 146 | GLIBC_2.1.1 |
| 147 | GLIBC_2.20 |
| 148 | GLIBC_2.2 |
| 149 | GLIBC_2.1 |
| 150 | GLIBC_2.21 |
| 151 | " "" |
| 152 | |
Denis Vlasenko | 8336f08 | 2007-01-07 00:21:41 +0000 | [diff] [blame] | 153 | testing "sort -u should consider field only when discarding" "sort -u -k2 input" "\ |
| 154 | a c |
| 155 | " "\ |
| 156 | a c |
| 157 | b c |
| 158 | " "" |
| 159 | |
Denis Vlasenko | 3b92eaa | 2008-02-13 14:30:33 +0000 | [diff] [blame] | 160 | testing "sort -z outputs NUL terminated lines" "sort -z input" "\ |
| 161 | one\0three\0two\0\ |
| 162 | " "\ |
| 163 | one\0two\0three\0\ |
| 164 | " "" |
| 165 | |
Rob Landley | 3921893 | 2006-06-15 20:50:38 +0000 | [diff] [blame] | 166 | testing "sort key doesn't strip leading blanks, disables fallback global sort" \ |
Denis Vlasenko | 9213a9e | 2006-09-17 16:28:10 +0000 | [diff] [blame] | 167 | "sort -n -k2 -t ' '" " a \n 1 \n 2 \n" "" " 2 \n 1 \n a \n" |
Rob Landley | 3921893 | 2006-06-15 20:50:38 +0000 | [diff] [blame] | 168 | |
Denys Vlasenko | aa42d13 | 2009-12-13 02:09:22 +0100 | [diff] [blame] | 169 | testing "sort file in place" \ |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 170 | "sort -o input input && cat input" "\ |
Denys Vlasenko | aa42d13 | 2009-12-13 02:09:22 +0100 | [diff] [blame] | 171 | 111 |
| 172 | 222 |
| 173 | " "\ |
| 174 | 222 |
| 175 | 111 |
| 176 | " "" |
| 177 | |
| 178 | # testing "description" "command(s)" "result" "infile" "stdin" |
| 179 | |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 180 | exit $FAILCOUNT |