tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / du / inacc-dest
1 #!/bin/sh
2 # Prior to coreutils-6.5, an inaccessible destination dir (chmod a-x)
3 # would cause du to exit prematurely on systems with native openat support.
4
5 # Copyright (C) 2006-2009 Free Software Foundation, Inc.
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20 if test "$VERBOSE" = yes; then
21   set -x
22   du --version
23 fi
24
25 . $srcdir/test-lib.sh
26 skip_if_root_
27
28 mkdir f && cd f && mkdir a b c d e && touch c/j && chmod a-x c \
29     || framework_failure
30
31 du > ../t 2>&1 && fail=1
32
33 # Accept either of the following outputs.
34 # You get the first from a system with openat _emulation_ (via /proc),
35 # the second from a system with native openat support.
36 # FIXME: there may well be a third output, for systems with neither
37 # /proc support, nor native openat support.
38
39 sed 's/^[0-9][0-9]*     //' ../t | sort -u > out
40 cat <<\EOF > exp || fail=1
41 .
42 ./a
43 ./b
44 ./c
45 ./d
46 ./e
47 du: cannot read directory `./c': Permission denied
48 EOF
49
50 # Map a diagnostic like this
51 #   du: cannot access `./c/j': Permission denied
52 # to this:
53 #   du: cannot access `./c': Permission denied
54 # And accept "cannot read directory" in place of "cannot access"
55 sed "s,/c/j': ,/c': ," out > t && mv t out
56 sed 's,cannot access,cannot read directory,' out > t && mv t out
57
58 compare out exp || fail=1
59
60 Exit $fail