maint: factor out common macros of stat and printf
[coreutils.git] / tests / du / deref.sh
blobf64cfc43d44a15ff85ee5bdb7e279bad46d39766
1 #!/bin/sh
2 # prior to coreutils-4.5.3, du -D didn't work in some cases
3 # Based on an example from Andreas Schwab and/or Michal Svec.
4 # Also, up to coreutils-8.5, du -L sometimes incorrectly
5 # counted the space of the followed symlinks.
7 # Copyright (C) 2002-2024 Free Software Foundation, Inc.
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <https://www.gnu.org/licenses/>.
22 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
23 print_ver_ du
25 mkdir -p a/sub || framework_failure_
26 ln -s a/sub slink || framework_failure_
27 touch b || framework_failure_
28 ln -s .. a/sub/dotdot || framework_failure_
29 ln -s nowhere dangle || framework_failure_
32 # This used to fail with the following diagnostic:
33 # du: 'b': No such file or directory
34 du -sD slink b > /dev/null 2>&1 || fail=1
36 # This used to fail to report the dangling symlink.
37 returns_ 1 du -L dangle > /dev/null 2>&1 || fail=1
39 # du -L used to mess up, either by counting the symlink's file system space
40 # itself (-L should follow symlinks, not count their space)
41 # or (briefly in July 2010) by omitting the entry for "a".
42 du_L_output=$(du -L a) || fail=1
43 du_lL_output=$(du -lL a) || fail=1
44 du_x_output=$(du --exclude=dotdot a) || fail=1
45 test "X$du_L_output" = "X$du_x_output" || fail=1
46 test "X$du_lL_output" = "X$du_x_output" || fail=1
48 Exit $fail