1#!/bin/sh 2# Test warnings for sort options 3 4# Copyright (C) 2010-2023 Free Software Foundation, Inc. 5 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. 10 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. 15 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/>. 18 19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src 20print_ver_ sort 21 22cat <<\EOF > exp 231 24sort: text ordering performed using simple byte comparison 25sort: key 1 has zero width and will be ignored 262 27sort: text ordering performed using simple byte comparison 28sort: key 1 has zero width and will be ignored 29sort: note numbers use '.' as a decimal point in this locale 303 31sort: text ordering performed using simple byte comparison 32sort: key 1 is numeric and spans multiple fields 33sort: note numbers use '.' as a decimal point in this locale 344 35sort: text ordering performed using simple byte comparison 36sort: note numbers use '.' as a decimal point in this locale 37sort: options '-bghMRrV' are ignored 385 39sort: text ordering performed using simple byte comparison 40sort: note numbers use '.' as a decimal point in this locale 41sort: options '-bghMRV' are ignored 42sort: option '-r' only applies to last-resort comparison 436 44sort: text ordering performed using simple byte comparison 45sort: note numbers use '.' as a decimal point in this locale 46sort: option '-r' only applies to last-resort comparison 477 48sort: text ordering performed using simple byte comparison 49sort: leading blanks are significant in key 2; consider also specifying 'b' 50sort: note numbers use '.' as a decimal point in this locale 51sort: options '-bg' are ignored 528 53sort: text ordering performed using simple byte comparison 54sort: note numbers use '.' as a decimal point in this locale 559 56sort: text ordering performed using simple byte comparison 57sort: note numbers use '.' as a decimal point in this locale 58sort: option '-b' is ignored 5910 60sort: text ordering performed using simple byte comparison 61sort: note numbers use '.' as a decimal point in this locale 6211 63sort: text ordering performed using simple byte comparison 64sort: leading blanks are significant in key 1; consider also specifying 'b' 6512 66sort: text ordering performed using simple byte comparison 67sort: leading blanks are significant in key 1; consider also specifying 'b' 6813 69sort: text ordering performed using simple byte comparison 70sort: leading blanks are significant in key 1; consider also specifying 'b' 71sort: option '-d' is ignored 7214 73sort: text ordering performed using simple byte comparison 74sort: leading blanks are significant in key 1; consider also specifying 'b' 75sort: option '-i' is ignored 7615 77sort: text ordering performed using simple byte comparison 7816 79sort: text ordering performed using simple byte comparison 8017 81sort: text ordering performed using simple byte comparison 82EOF 83 84echo 1 >> out 85sort -s -k2,1 --debug /dev/null 2>>out || fail=1 86echo 2 >> out 87sort -s -k2,1n --debug /dev/null 2>>out || fail=1 88echo 3 >> out 89sort -s -k1,2n --debug /dev/null 2>>out || fail=1 90echo 4 >> out 91sort -s -rRVMhgb -k1,1n --debug /dev/null 2>>out || fail=1 92echo 5 >> out 93sort -rRVMhgb -k1,1n --debug /dev/null 2>>out || fail=1 94echo 6 >> out 95sort -r -k1,1n --debug /dev/null 2>>out || fail=1 96echo 7 >> out 97sort -gbr -k1,1n -k1,1r --debug /dev/null 2>>out || fail=1 98echo 8 >> out 99sort -b -k1b,1bn --debug /dev/null 2>>out || fail=1 # no warning 100echo 9 >> out 101sort -b -k1,1bn --debug /dev/null 2>>out || fail=1 102echo 10 >> out 103sort -b -k1,1bn -k2b,2 --debug /dev/null 2>>out || fail=1 # no warning 104echo 11 >> out 105sort -r -k1,1r --debug /dev/null 2>>out || fail=1 # no warning for redundant opt 106echo 12 >> out 107sort -i -k1,1i --debug /dev/null 2>>out || fail=1 # no warning 108echo 13 >> out 109sort -d -k1,1b --debug /dev/null 2>>out || fail=1 110echo 14 >> out 111sort -i -k1,1d --debug /dev/null 2>>out || fail=1 112echo 15 >> out 113sort -r --debug /dev/null 2>>out || fail=1 #no warning 114echo 16 >> out 115sort -rM --debug /dev/null 2>>out || fail=1 #no warning 116echo 17 >> out 117sort -rM -k1,1 --debug /dev/null 2>>out || fail=1 #no warning 118compare exp out || fail=1 119 120 121cat <<\EOF > exp 122sort: failed to set locale 123sort: text ordering performed using simple byte comparison 124EOF 125LC_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 129if ! grep -E 'using .*(missing|C.UTF-8).* sorting rules' out; then 130 compare exp out || fail=1 131fi 132 133 134cat <<\EOF > exp 135sort: text ordering performed using simple byte comparison 136sort: key 1 is numeric and spans multiple fields 137sort: obsolescent key '+2 -1' used; consider '-k 3,1' instead 138sort: key 2 has zero width and will be ignored 139sort: note numbers use '.' as a decimal point in this locale 140sort: option '-b' is ignored 141sort: option '-r' only applies to last-resort comparison 142EOF 143sort --debug -rb -k2n +2.2 -1b /dev/null 2>out || fail=1 144compare exp out || fail=1 145 146 147# check sign, decimal point, and grouping character warnings 148cat <<\EOF > exp 149sort: text ordering performed using simple byte comparison 150sort: key 1 is numeric and spans multiple fields 151sort: field separator ',' is treated as a group separator in numbers 152EOF 153if 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 157fi 158 159cat <<\EOF > exp 160sort: text ordering performed using simple byte comparison 161sort: key 1 is numeric and spans multiple fields 162sort: field separator '.' is treated as a decimal point in numbers 163EOF 164sort -nk1 -t. --debug /dev/null 2>out || fail=1 165compare exp out || fail=1 166 167cat <<\EOF > exp 168sort: text ordering performed using simple byte comparison 169sort: key 1 is numeric and spans multiple fields 170sort: field separator '-' is treated as a minus sign in numbers 171sort: note numbers use '.' as a decimal point in this locale 172EOF 173sort -nk1 -t- --debug /dev/null 2>out || fail=1 174compare exp out || fail=1 175 176cat <<\EOF > exp 177sort: text ordering performed using simple byte comparison 178sort: key 1 is numeric and spans multiple fields 179sort: field separator '+' is treated as a plus sign in numbers 180sort: note numbers use '.' as a decimal point in this locale 181EOF 182sort -gk1 -t+ --debug /dev/null 2>out || fail=1 183compare exp out || fail=1 184 185Exit $fail 186