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 | |
Denys Vlasenko | 6ae6426 | 2009-07-18 16:22:26 +0200 | [diff] [blame] | 50 | test x"$SKIP_KNOWN_BUGS" = x"" && { |
| 51 | # Busybox is definitely doing these wrong. FIXME |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 52 | testing "sort key range with numeric option and global reverse" \ |
Rob Landley | 4bb1b04 | 2006-03-16 15:20:45 +0000 | [diff] [blame] | 53 | "sort -k2,3n -r input" \ |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 54 | "egg 1 2 papyrus |
| 55 | 42 1 3 woot |
| 56 | 42 1 010 zoology |
| 57 | 999 3 0 algebra |
| 58 | 7 3 42 soup |
| 59 | " "$data" "" |
| 60 | |
Rob Landley | 4bb1b04 | 2006-03-16 15:20:45 +0000 | [diff] [blame] | 61 | testing "sort key range with multiple options" "sort -k2,3rn input" \ |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 62 | "7 3 42 soup |
| 63 | 999 3 0 algebra |
| 64 | 42 1 010 zoology |
| 65 | 42 1 3 woot |
| 66 | egg 1 2 papyrus |
| 67 | " "$data" "" |
Denys Vlasenko | 6ae6426 | 2009-07-18 16:22:26 +0200 | [diff] [blame] | 68 | } |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 69 | |
Denis Vlasenko | 54cf511 | 2007-02-17 18:11:45 +0000 | [diff] [blame] | 70 | testing "sort key range with two -k options" "sort -k 2,2n -k 1,1r input" "\ |
| 71 | d 2 |
| 72 | b 2 |
| 73 | c 3 |
| 74 | " "\ |
| 75 | c 3 |
| 76 | b 2 |
| 77 | d 2 |
| 78 | " "" |
| 79 | |
Denis Vlasenko | 8336f08 | 2007-01-07 00:21:41 +0000 | [diff] [blame] | 80 | testing "sort with non-default leading delim 1" "sort -n -k2 -t/ input" "\ |
| 81 | /a/2 |
| 82 | /b/1 |
| 83 | " "\ |
| 84 | /a/2 |
| 85 | /b/1 |
| 86 | " "" |
| 87 | |
| 88 | testing "sort with non-default leading delim 2" "sort -n -k3 -t/ input" "\ |
| 89 | /b/1 |
| 90 | /a/2 |
| 91 | " "\ |
| 92 | /b/1 |
| 93 | /a/2 |
| 94 | " "" |
| 95 | |
| 96 | testing "sort with non-default leading delim 3" "sort -n -k3 -t/ input" "\ |
| 97 | //a/2 |
| 98 | //b/1 |
| 99 | " "\ |
| 100 | //a/2 |
| 101 | //b/1 |
| 102 | " "" |
| 103 | |
| 104 | testing "sort -u should consider field only when discarding" "sort -u -k2 input" "\ |
| 105 | a c |
| 106 | " "\ |
| 107 | a c |
| 108 | b c |
| 109 | " "" |
| 110 | |
Denis Vlasenko | 3b92eaa | 2008-02-13 14:30:33 +0000 | [diff] [blame] | 111 | testing "sort -z outputs NUL terminated lines" "sort -z input" "\ |
| 112 | one\0three\0two\0\ |
| 113 | " "\ |
| 114 | one\0two\0three\0\ |
| 115 | " "" |
| 116 | |
Rob Landley | 3921893 | 2006-06-15 20:50:38 +0000 | [diff] [blame] | 117 | testing "sort key doesn't strip leading blanks, disables fallback global sort" \ |
Denis Vlasenko | 9213a9e | 2006-09-17 16:28:10 +0000 | [diff] [blame] | 118 | "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] | 119 | |
Denys Vlasenko | aa42d13 | 2009-12-13 02:09:22 +0100 | [diff] [blame] | 120 | testing "sort file in place" \ |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 121 | "sort -o input input && cat input" "\ |
Denys Vlasenko | aa42d13 | 2009-12-13 02:09:22 +0100 | [diff] [blame] | 122 | 111 |
| 123 | 222 |
| 124 | " "\ |
| 125 | 222 |
| 126 | 111 |
| 127 | " "" |
| 128 | |
| 129 | # testing "description" "command(s)" "result" "infile" "stdin" |
| 130 | |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 131 | exit $FAILCOUNT |