1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-04-21 11:16:16 +02:00

sort: --debug: add warnings about sign, radix, and grouping chars

New warnings are added related to the handling
of thousands grouping characters, decimal points, and sign characters.
Examples now diagnosed are:

$ printf '0,9\n1,a\n' | sort -nk1 --debug -t, -s
sort: key 1 is numeric and spans multiple fields
sort: field separator ‘,’ is treated as a group separator in numbers
1,a
_
0,9
___

$ printf '1,a\n0,9\n' | LC_ALL=fr_FR.utf8 sort -gk1 --debug -t, -s
sort: key 1 is numeric and spans multiple fields
sort: field separator ‘,’ is treated as a decimal point in numbers
0,9
___
1,a
__

$ printf '1.0\n0.9\n' | LC_ALL=fr_FR.utf8 sort -s -k1,1g --debug
sort: note numbers use ‘,’ as a decimal point in this locale
0.9
_
1.0
_

$ LC_ALL=fr_FR.utf8 sort -n --debug /dev/null
sort: text ordering performed using ‘fr_FR.utf8’ sorting rules
sort: note numbers use ‘,’ as a decimal point in this locale
sort: the multi-byte number group separator in this locale \
      is not supported

$ sort --debug -t- -k1n /dev/null
sort: key 1 is numeric and spans multiple fields
sort: field separator ‘-’ is treated as a minus sign in numbers
sort: note numbers use ‘.’ as a decimal point in this locale

$ sort --debug -t+ -k1g /dev/null
sort: key 1 is numeric and spans multiple fields
sort: field separator ‘+’ is treated as a plus sign in numbers
sort: note numbers use ‘.’ as a decimal point in this locale

* src/sort.c (key_warnings): Add the warnings above.
* tests/misc/sort-debug-warn.sh: Add test cases.
Also check that all sort invocations succeed.
* NEWS: Mention the improvement.
Addresses https://bugs.gnu.org/51011
This commit is contained in:
Pádraig Brady
2021-10-10 18:35:59 +01:00
parent aa31b919ca
commit bafff0019c
3 changed files with 159 additions and 25 deletions

View File

@@ -26,30 +26,39 @@ sort: key 1 has zero width and will be ignored
2
sort: text ordering performed using simple byte comparison
sort: key 1 has zero width and will be ignored
sort: note numbers use '.' as a decimal point in this locale
3
sort: text ordering performed using simple byte comparison
sort: key 1 is numeric and spans multiple fields
sort: note numbers use '.' as a decimal point in this locale
4
sort: text ordering performed using simple byte comparison
sort: note numbers use '.' as a decimal point in this locale
sort: options '-bghMRrV' are ignored
5
sort: text ordering performed using simple byte comparison
sort: note numbers use '.' as a decimal point in this locale
sort: options '-bghMRV' are ignored
sort: option '-r' only applies to last-resort comparison
6
sort: text ordering performed using simple byte comparison
sort: note numbers use '.' as a decimal point in this locale
sort: option '-r' only applies to last-resort comparison
7
sort: text ordering performed using simple byte comparison
sort: leading blanks are significant in key 2; consider also specifying 'b'
sort: note numbers use '.' as a decimal point in this locale
sort: options '-bg' are ignored
8
sort: text ordering performed using simple byte comparison
sort: note numbers use '.' as a decimal point in this locale
9
sort: text ordering performed using simple byte comparison
sort: note numbers use '.' as a decimal point in this locale
sort: option '-b' is ignored
10
sort: text ordering performed using simple byte comparison
sort: note numbers use '.' as a decimal point in this locale
11
sort: text ordering performed using simple byte comparison
sort: leading blanks are significant in key 1; consider also specifying 'b'
@@ -73,40 +82,39 @@ sort: text ordering performed using simple byte comparison
EOF
echo 1 >> out
sort -s -k2,1 --debug /dev/null 2>>out
sort -s -k2,1 --debug /dev/null 2>>out || fail=1
echo 2 >> out
sort -s -k2,1n --debug /dev/null 2>>out
sort -s -k2,1n --debug /dev/null 2>>out || fail=1
echo 3 >> out
sort -s -k1,2n --debug /dev/null 2>>out
sort -s -k1,2n --debug /dev/null 2>>out || fail=1
echo 4 >> out
sort -s -rRVMhgb -k1,1n --debug /dev/null 2>>out
sort -s -rRVMhgb -k1,1n --debug /dev/null 2>>out || fail=1
echo 5 >> out
sort -rRVMhgb -k1,1n --debug /dev/null 2>>out
sort -rRVMhgb -k1,1n --debug /dev/null 2>>out || fail=1
echo 6 >> out
sort -r -k1,1n --debug /dev/null 2>>out
sort -r -k1,1n --debug /dev/null 2>>out || fail=1
echo 7 >> out
sort -gbr -k1,1n -k1,1r --debug /dev/null 2>>out
sort -gbr -k1,1n -k1,1r --debug /dev/null 2>>out || fail=1
echo 8 >> out
sort -b -k1b,1bn --debug /dev/null 2>>out # no warning
sort -b -k1b,1bn --debug /dev/null 2>>out || fail=1 # no warning
echo 9 >> out
sort -b -k1,1bn --debug /dev/null 2>>out
sort -b -k1,1bn --debug /dev/null 2>>out || fail=1
echo 10 >> out
sort -b -k1,1bn -k2b,2 --debug /dev/null 2>>out # no warning
sort -b -k1,1bn -k2b,2 --debug /dev/null 2>>out || fail=1 # no warning
echo 11 >> out
sort -r -k1,1r --debug /dev/null 2>>out # no warning for redundant options
sort -r -k1,1r --debug /dev/null 2>>out || fail=1 # no warning for redundant opt
echo 12 >> out
sort -i -k1,1i --debug /dev/null 2>>out # no warning
sort -i -k1,1i --debug /dev/null 2>>out || fail=1 # no warning
echo 13 >> out
sort -d -k1,1b --debug /dev/null 2>>out
sort -d -k1,1b --debug /dev/null 2>>out || fail=1
echo 14 >> out
sort -i -k1,1d --debug /dev/null 2>>out
sort -i -k1,1d --debug /dev/null 2>>out || fail=1
echo 15 >> out
sort -r --debug /dev/null 2>>out #no warning
sort -r --debug /dev/null 2>>out || fail=1 #no warning
echo 16 >> out
sort -rM --debug /dev/null 2>>out #no warning
sort -rM --debug /dev/null 2>>out || fail=1 #no warning
echo 17 >> out
sort -rM -k1,1 --debug /dev/null 2>>out #no warning
sort -rM -k1,1 --debug /dev/null 2>>out || fail=1 #no warning
compare exp out || fail=1
@@ -114,9 +122,7 @@ cat <<\EOF > exp
sort: failed to set locale
sort: text ordering performed using simple byte comparison
EOF
LC_ALL=missing sort --debug /dev/null 2>out
LC_ALL=missing sort --debug /dev/null 2>out || fail=1
# musl libc maps unknown locales to the default utf8 locale
# with no way to determine failures. This is discussed at:
# http://www.openwall.com/lists/musl/2016/04/02/1
@@ -130,12 +136,50 @@ sort: text ordering performed using simple byte comparison
sort: key 1 is numeric and spans multiple fields
sort: obsolescent key '+2 -1' used; consider '-k 3,1' instead
sort: key 2 has zero width and will be ignored
sort: note numbers use '.' as a decimal point in this locale
sort: option '-b' is ignored
sort: option '-r' only applies to last-resort comparison
EOF
sort --debug -rb -k2n +2.2 -1b /dev/null 2>out || fail=1
compare exp out || fail=1
sort --debug -rb -k2n +2.2 -1b /dev/null 2>out
# check sign, decimal point, and grouping character warnings
cat <<\EOF > exp
sort: text ordering performed using simple byte comparison
sort: key 1 is numeric and spans multiple fields
sort: field separator ',' is treated as a group separator in numbers
EOF
if test $(printf '0,9\n0,8\n' | sort -ns | tail -n1) = '0,9'; then
# thousands_sep == ,
sort -nk1 -t, --debug /dev/null 2>out || fail=1
compare exp out || fail=1
fi
cat <<\EOF > exp
sort: text ordering performed using simple byte comparison
sort: key 1 is numeric and spans multiple fields
sort: field separator '.' is treated as a decimal point in numbers
EOF
sort -nk1 -t. --debug /dev/null 2>out || fail=1
compare exp out || fail=1
cat <<\EOF > exp
sort: text ordering performed using simple byte comparison
sort: key 1 is numeric and spans multiple fields
sort: field separator '-' is treated as a minus sign in numbers
sort: note numbers use '.' as a decimal point in this locale
EOF
sort -nk1 -t- --debug /dev/null 2>out || fail=1
compare exp out || fail=1
cat <<\EOF > exp
sort: text ordering performed using simple byte comparison
sort: key 1 is numeric and spans multiple fields
sort: field separator '+' is treated as a plus sign in numbers
sort: note numbers use '.' as a decimal point in this locale
EOF
sort -gk1 -t+ --debug /dev/null 2>out || fail=1
compare exp out || fail=1
Exit $fail