maint: factor out common macros of stat and printf
[coreutils.git] / tests / du / max-depth.sh
blobad8a1f5de1cf4b8812f0335654a63c43b767dcae
1 #!/bin/sh
2 # exercise du's --max-depth=N option
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_ du
22 mkdir -p a/b/c/d/e || framework_failure_
23 printf 'a/b/c\na/b\na\n' > exp || framework_failure_
25 du --max-depth=2 a > out 2>err || fail=1
27 # Remove the sizes. They vary between file systems.
28 cut -f2- out > k && mv k out
29 compare exp out || fail=1
30 compare /dev/null err || fail=1
32 # Repeat, but use -d 1.
33 printf 'a/b\na\n' > exp || framework_failure_
34 du -d 1 a > out 2>err || fail=1
35 cut -f2- out > k && mv k out
36 compare exp out || fail=1
37 compare /dev/null err || fail=1
39 Exit $fail