tests: fix POSIX shell source style
[oweals/busybox.git] / testsuite / sort.tests
1 #!/bin/sh
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
7 . ./testing.sh
8
9 # The basic tests.  These should work even with the small busybox.
10
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" \
16         "point\nwook\npabst\naargh\nwalrus\n" ""
17
18 # These tests require the full option set.
19
20 optional FEATURE_SORT_BIG
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
32 testing "sort one key" "sort -k4,4 input" \
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
40 testing "sort key range with numeric option" "sort -k2,3n input" \
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
48 test x"$SKIP_KNOWN_BUGS" = x"" && {
49 # Busybox is definitely doing these wrong.  FIXME
50 testing "sort key range with numeric option and global reverse" \
51 "sort -k2,3n -r input" \
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
59 testing "sort key range with multiple options" "sort -k2,3rn input" \
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 }
67
68 testing "sort key range with two -k options" "sort -k 2,2n -k 1,1r input" "\
69 d 2
70 b 2
71 c 3
72 " "\
73 c 3
74 b 2
75 d 2
76 " ""
77
78 testing "sort with non-default leading delim 1" "sort -n -k2 -t/ input" "\
79 /a/2
80 /b/1
81 " "\
82 /a/2
83 /b/1
84 " ""
85
86 testing "sort with non-default leading delim 2" "sort -n -k3 -t/ input" "\
87 /b/1
88 /a/2
89 " "\
90 /b/1
91 /a/2
92 " ""
93
94 testing "sort with non-default leading delim 3" "sort -n -k3 -t/ input" "\
95 //a/2
96 //b/1
97 " "\
98 //a/2
99 //b/1
100 " ""
101
102 testing "sort -u should consider field only when discarding" "sort -u -k2 input" "\
103 a c
104 " "\
105 a c
106 b c
107 " ""
108
109 testing "sort -z outputs NUL terminated lines" "sort -z input" "\
110 one\0three\0two\0\
111 " "\
112 one\0two\0three\0\
113 " ""
114
115 testing "sort key doesn't strip leading blanks, disables fallback global sort" \
116 "sort -n -k2 -t ' '" " a \n 1 \n 2 \n" "" " 2 \n 1 \n a \n"
117
118 exit $FAILCOUNT