Rob Landley | 3921893 | 2006-06-15 20:50:38 +0000 | [diff] [blame] | 1 | #!/bin/bash |
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> |
| 5 | # Licensed under GPL v2, see file LICENSE for details. |
| 6 | |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 7 | . testing.sh |
| 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 | |
| 30 | # Sorting with keys |
| 31 | |
Rob Landley | 4bb1b04 | 2006-03-16 15:20:45 +0000 | [diff] [blame] | 32 | testing "sort one key" "sort -k4,4 input" \ |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 33 | "999 3 0 algebra |
| 34 | egg 1 2 papyrus |
| 35 | 7 3 42 soup |
| 36 | 42 1 3 woot |
| 37 | 42 1 010 zoology |
| 38 | " "$data" "" |
| 39 | |
Rob Landley | 4bb1b04 | 2006-03-16 15:20:45 +0000 | [diff] [blame] | 40 | testing "sort key range with numeric option" "sort -k2,3n input" \ |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 41 | "42 1 010 zoology |
| 42 | 42 1 3 woot |
| 43 | egg 1 2 papyrus |
| 44 | 7 3 42 soup |
| 45 | 999 3 0 algebra |
| 46 | " "$data" "" |
| 47 | |
Rob Landley | 48c6157 | 2005-11-07 08:50:53 +0000 | [diff] [blame] | 48 | # Busybox is definitely doing this one wrong just now. FIXME |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 49 | |
| 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 | |
Denis Vlasenko | 9213a9e | 2006-09-17 16:28:10 +0000 | [diff] [blame] | 59 | # |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 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" "" |
| 68 | |
Denis Vlasenko | 54cf511 | 2007-02-17 18:11:45 +0000 | [diff] [blame] | 69 | testing "sort key range with two -k options" "sort -k 2,2n -k 1,1r input" "\ |
| 70 | d 2 |
| 71 | b 2 |
| 72 | c 3 |
| 73 | " "\ |
| 74 | c 3 |
| 75 | b 2 |
| 76 | d 2 |
| 77 | " "" |
| 78 | |
Denis Vlasenko | 8336f08 | 2007-01-07 00:21:41 +0000 | [diff] [blame] | 79 | testing "sort with non-default leading delim 1" "sort -n -k2 -t/ input" "\ |
| 80 | /a/2 |
| 81 | /b/1 |
| 82 | " "\ |
| 83 | /a/2 |
| 84 | /b/1 |
| 85 | " "" |
| 86 | |
| 87 | testing "sort with non-default leading delim 2" "sort -n -k3 -t/ input" "\ |
| 88 | /b/1 |
| 89 | /a/2 |
| 90 | " "\ |
| 91 | /b/1 |
| 92 | /a/2 |
| 93 | " "" |
| 94 | |
| 95 | testing "sort with non-default leading delim 3" "sort -n -k3 -t/ input" "\ |
| 96 | //a/2 |
| 97 | //b/1 |
| 98 | " "\ |
| 99 | //a/2 |
| 100 | //b/1 |
| 101 | " "" |
| 102 | |
| 103 | testing "sort -u should consider field only when discarding" "sort -u -k2 input" "\ |
| 104 | a c |
| 105 | " "\ |
| 106 | a c |
| 107 | b c |
| 108 | " "" |
| 109 | |
Denis Vlasenko | 3b92eaa | 2008-02-13 14:30:33 +0000 | [diff] [blame] | 110 | testing "sort -z outputs NUL terminated lines" "sort -z input" "\ |
| 111 | one\0three\0two\0\ |
| 112 | " "\ |
| 113 | one\0two\0three\0\ |
| 114 | " "" |
| 115 | |
Rob Landley | 3921893 | 2006-06-15 20:50:38 +0000 | [diff] [blame] | 116 | testing "sort key doesn't strip leading blanks, disables fallback global sort" \ |
Denis Vlasenko | 9213a9e | 2006-09-17 16:28:10 +0000 | [diff] [blame] | 117 | "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] | 118 | |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 119 | exit $FAILCOUNT |