tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / du / slink
1 #!/bin/sh
2 # Ensure that the size of a long-named-symlink is > 0.
3
4 # Copyright (C) 2002-2009 Free Software Foundation, Inc.
5
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.
10
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.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 if test "$VERBOSE" = yes; then
20   set -x
21   du --version
22 fi
23
24 . $srcdir/test-lib.sh
25
26 # Determine if `.' is on a local (would non-NFS be sufficient?) file system.
27 # On at least some NFS implementations, symlinks never take up space,
28
29 # So if this is a non-local file system, skip the test.
30 if df --local . >/dev/null 2>&1; then
31   : # Ok.
32 else
33   skip_test_ "\`.' is on a non-local file system"
34 fi
35
36 if df --type=xfs . >/dev/null 2>&1; then
37   # At least on Irix-6.5.19, when using an xfs file system,
38   # each created symlink (name lengths up to 255) would have a size of `0'.
39   skip_test_ "\`.' is on an XFS file system"
40 fi
41
42 if df --type=nfsv3 . >/dev/null 2>&1; then
43   # At least on OSF/1 4.0d, when using an nfsv3 file system,
44   # each created symlink can end up having a size of 0.
45   skip_test_ "\`.' is on an NFS file system"
46 fi
47
48 symlink_name_lengths='1 15 16 31 32 59 60 63 64 127 128 255 256 511 512 1024'
49 for len in $symlink_name_lengths; do
50   name=`seq 1 $len|tr -c x y |head -c$len`
51   # Record the names of symlinks that are successfully created.
52   ln -fs $name $len > /dev/null 2>&1 \
53     && symlinks="$symlinks $len"
54 done
55
56 du -a $symlinks > out || fail=1
57
58 # Require that at least one of these symlinks has a non-zero size.
59 grep '^[1-9]' out > /dev/null || fail=1
60
61 Exit $fail