maint: factor out common macros of stat and printf
[coreutils.git] / tests / sort / sort-debug-warn.sh
blob6e445a0b51f5c76b6df3be3d289293183e76a589
1 #!/bin/sh
2 # Test warnings for sort options
4 # Copyright (C) 2010-2024 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ sort
22 cat <<\EOF > exp
24 sort: text ordering performed using simple byte comparison
25 sort: key 1 has zero width and will be ignored
27 sort: text ordering performed using simple byte comparison
28 sort: key 1 has zero width and will be ignored
29 sort: note numbers use '.' as a decimal point in this locale
31 sort: text ordering performed using simple byte comparison
32 sort: key 1 is numeric and spans multiple fields
33 sort: note numbers use '.' as a decimal point in this locale
35 sort: text ordering performed using simple byte comparison
36 sort: note numbers use '.' as a decimal point in this locale
37 sort: options '-bghMRrV' are ignored
39 sort: text ordering performed using simple byte comparison
40 sort: note numbers use '.' as a decimal point in this locale
41 sort: options '-bghMRV' are ignored
42 sort: option '-r' only applies to last-resort comparison
44 sort: text ordering performed using simple byte comparison
45 sort: note numbers use '.' as a decimal point in this locale
46 sort: option '-r' only applies to last-resort comparison
48 sort: text ordering performed using simple byte comparison
49 sort: leading blanks are significant in key 2; consider also specifying 'b'
50 sort: note numbers use '.' as a decimal point in this locale
51 sort: options '-bg' are ignored
53 sort: text ordering performed using simple byte comparison
54 sort: note numbers use '.' as a decimal point in this locale
56 sort: text ordering performed using simple byte comparison
57 sort: note numbers use '.' as a decimal point in this locale
58 sort: option '-b' is ignored
60 sort: text ordering performed using simple byte comparison
61 sort: note numbers use '.' as a decimal point in this locale
63 sort: text ordering performed using simple byte comparison
64 sort: leading blanks are significant in key 1; consider also specifying 'b'
66 sort: text ordering performed using simple byte comparison
67 sort: leading blanks are significant in key 1; consider also specifying 'b'
69 sort: text ordering performed using simple byte comparison
70 sort: leading blanks are significant in key 1; consider also specifying 'b'
71 sort: option '-d' is ignored
73 sort: text ordering performed using simple byte comparison
74 sort: leading blanks are significant in key 1; consider also specifying 'b'
75 sort: option '-i' is ignored
77 sort: text ordering performed using simple byte comparison
79 sort: text ordering performed using simple byte comparison
81 sort: text ordering performed using simple byte comparison
82 EOF
84 echo 1 >> out
85 sort -s -k2,1 --debug /dev/null 2>>out || fail=1
86 echo 2 >> out
87 sort -s -k2,1n --debug /dev/null 2>>out || fail=1
88 echo 3 >> out
89 sort -s -k1,2n --debug /dev/null 2>>out || fail=1
90 echo 4 >> out
91 sort -s -rRVMhgb -k1,1n --debug /dev/null 2>>out || fail=1
92 echo 5 >> out
93 sort -rRVMhgb -k1,1n --debug /dev/null 2>>out || fail=1
94 echo 6 >> out
95 sort -r -k1,1n --debug /dev/null 2>>out || fail=1
96 echo 7 >> out
97 sort -gbr -k1,1n -k1,1r --debug /dev/null 2>>out || fail=1
98 echo 8 >> out
99 sort -b -k1b,1bn --debug /dev/null 2>>out || fail=1 # no warning
100 echo 9 >> out
101 sort -b -k1,1bn --debug /dev/null 2>>out || fail=1
102 echo 10 >> out
103 sort -b -k1,1bn -k2b,2 --debug /dev/null 2>>out || fail=1 # no warning
104 echo 11 >> out
105 sort -r -k1,1r --debug /dev/null 2>>out || fail=1 # no warning for redundant opt
106 echo 12 >> out
107 sort -i -k1,1i --debug /dev/null 2>>out || fail=1 # no warning
108 echo 13 >> out
109 sort -d -k1,1b --debug /dev/null 2>>out || fail=1
110 echo 14 >> out
111 sort -i -k1,1d --debug /dev/null 2>>out || fail=1
112 echo 15 >> out
113 sort -r --debug /dev/null 2>>out || fail=1 #no warning
114 echo 16 >> out
115 sort -rM --debug /dev/null 2>>out || fail=1 #no warning
116 echo 17 >> out
117 sort -rM -k1,1 --debug /dev/null 2>>out || fail=1 #no warning
118 compare exp out || fail=1
121 cat <<\EOF > exp
122 sort: failed to set locale
123 sort: text ordering performed using simple byte comparison
125 LC_ALL=missing sort --debug /dev/null 2>out || fail=1
126 # musl libc maps unknown locales to the default utf8 locale
127 # with no way to determine failures. This is discussed at:
128 # https://www.openwall.com/lists/musl/2016/04/02/1
129 if ! grep -E 'using .*(missing|C.UTF-8).* sorting rules' out; then
130 compare exp out || fail=1
134 cat <<\EOF > exp
135 sort: text ordering performed using simple byte comparison
136 sort: key 1 is numeric and spans multiple fields
137 sort: obsolescent key '+2 -1' used; consider '-k 3,1' instead
138 sort: key 2 has zero width and will be ignored
139 sort: note numbers use '.' as a decimal point in this locale
140 sort: option '-b' is ignored
141 sort: option '-r' only applies to last-resort comparison
143 sort --debug -rb -k2n +2.2 -1b /dev/null 2>out || fail=1
144 compare exp out || fail=1
147 # check sign, decimal point, and grouping character warnings
148 cat <<\EOF > exp
149 sort: text ordering performed using simple byte comparison
150 sort: key 1 is numeric and spans multiple fields
151 sort: field separator ',' is treated as a group separator in numbers
153 if test $(printf '0,9\n0,8\n' | sort -ns | tail -n1) = '0,9'; then
154 # thousands_sep == ,
155 sort -nk1 -t, --debug /dev/null 2>out || fail=1
156 compare exp out || fail=1
159 cat <<\EOF > exp
160 sort: text ordering performed using simple byte comparison
161 sort: key 1 is numeric and spans multiple fields
162 sort: field separator '.' is treated as a decimal point in numbers
164 sort -nk1 -t. --debug /dev/null 2>out || fail=1
165 compare exp out || fail=1
167 cat <<\EOF > exp
168 sort: text ordering performed using simple byte comparison
169 sort: key 1 is numeric and spans multiple fields
170 sort: field separator '-' is treated as a minus sign in numbers
171 sort: note numbers use '.' as a decimal point in this locale
173 sort -nk1 -t- --debug /dev/null 2>out || fail=1
174 compare exp out || fail=1
176 cat <<\EOF > exp
177 sort: text ordering performed using simple byte comparison
178 sort: key 1 is numeric and spans multiple fields
179 sort: field separator '+' is treated as a plus sign in numbers
180 sort: note numbers use '.' as a decimal point in this locale
182 sort -gk1 -t+ --debug /dev/null 2>out || fail=1
183 compare exp out || fail=1
185 Exit $fail