tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / ls / stat-dtype
1 #!/bin/sh
2 # Ensure that ls --file-type does not call stat unnecessarily.
3 # Also check for the dtype-related (and fs-type dependent) bug
4 # in coreutils-6.0 that made ls -CF columns misaligned.
5
6 # Copyright (C) 2006-2009 Free Software Foundation, Inc.
7
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.
12
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.
17
18 # You should have received a copy of the GNU General Public License
19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 # The trick is to create an un-stat'able symlink and to see if ls
22 # can report its type nonetheless, using dirent.d_type.
23
24 if test "$VERBOSE" = yes; then
25   set -x
26   ls --version
27 fi
28
29 . $srcdir/test-lib.sh
30
31 # Skip this test unless "." is on a file system with useful d_type info.
32 # FIXME: This uses "ls -p" to decide whether to test "ls" with other options,
33 # but if ls's d_type code is buggy then "ls -p" might be buggy too.
34 mkdir -p c/d || framework_failure
35 chmod a-x c || framework_failure
36 if test "X`ls -p c 2>&1`" != Xd/; then
37   skip_test_ "'.' is not on a suitable file system for this test"
38 fi
39
40 mkdir d || framework_failure
41 ln -s / d/s || framework_failure
42 chmod 600 d || framework_failure
43
44 mkdir -p e/a2345 e/b || framework_failure
45 chmod 600 e || framework_failure
46
47
48 ls --file-type d > out || fail=1
49 cat <<\EOF > exp || fail=1
50 s@
51 EOF
52
53 compare out exp || fail=1
54
55 rm -f out exp
56 # Check for the ls -CF misaligned-columns bug:
57 ls -CF e > out || fail=1
58
59 # coreutils-6.0 would print two spaces after the first slash,
60 # rather than the appropriate TAB.
61 printf 'a2345/\tb/\n' > exp || fail=1
62
63 compare out exp || fail=1
64
65 Exit $fail