tests: add test for locale decimal processing
[coreutils.git] / tests / du / hard-link.sh
blobdac9396433a55c475ef2d0ed14e438f9527cd1a2
1 #!/bin/sh
2 # Ensure that hard-linked files are counted (and listed) only once.
3 # Likewise for excluded directories.
4 # Ensure that hard links _are_ listed twice when using --count-links.
6 # Copyright (C) 2003-2019 Free Software Foundation, Inc.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <https://www.gnu.org/licenses/>.
21 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
22 print_ver_ du
24 mkdir -p dir/sub
25 ( cd dir &&
26 { echo non-empty > f1
27 ln f1 f2
28 ln -s f1 f3
29 echo non-empty > sub/F; } )
31 du -a -L --exclude=sub --count-links dir \
32 | sed 's/^[0-9][0-9]* //' | sort -r > out || fail=1
34 # For these tests, transform f1 or f2 or f3 (whichever name is find
35 # first) to f_. That is necessary because, depending on the type of
36 # file system, du could encounter any of those linked files first,
37 # thus listing that one and not the others.
38 for args in '-L' 'dir' '-L dir'
40 echo === >> out
41 du -a --exclude=sub $args dir \
42 | sed 's/^[0-9][0-9]* //' | sed 's/f[123]/f_/' >> out || fail=1
43 done
45 cat <<\EOF > exp
46 dir/f3
47 dir/f2
48 dir/f1
49 dir
50 ===
51 dir/f_
52 dir
53 ===
54 dir/f_
55 dir/f_
56 dir
57 ===
58 dir/f_
59 dir
60 EOF
62 compare exp out || fail=1
64 Exit $fail