Tizen 2.0 Release
[external/tizen-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 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 2 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, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 # 02110-1301, USA.
22
23 # The trick is to create an un-stat'able symlink and to see if ls
24 # can report its type nonetheless, using dirent.d_type.
25
26 if test "$VERBOSE" = yes; then
27   set -x
28   ls --version
29 fi
30
31 . $srcdir/../envvar-check
32
33 pwd=`pwd`
34 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
35 trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0
36 trap '(exit $?); exit $?' 1 2 13 15
37
38 framework_failure=0
39 mkdir -p $tmp || framework_failure=1
40 cd $tmp || framework_failure=1
41
42 # Skip this test unless "." is on a file system with useful d_type info.
43 # FIXME: This uses "ls -p" to decide whether to test "ls" with other options,
44 # but if ls's d_type code is buggy then "ls -p" might be buggy too.
45 mkdir -p c/d || framework_failure=1
46 chmod a-x c || framework_failure=1
47 if test "X`ls -p c 2>&1`" != Xd/; then
48   echo "$0: '.' is not on a suitable file system for this test" 1>&2
49   echo "$0: skipping this test" 1>&2
50   (exit 77); exit 77
51 fi
52
53 mkdir d || framework_failure=1
54 ln -s / d/s || framework_failure=1
55 chmod 600 d || framework_failure=1
56
57 mkdir -p e/a2345 e/b || framework_failure=1
58 chmod 600 e || framework_failure=1
59
60 if test $framework_failure = 1; then
61   echo "$0: failure in testing framework" 1>&2
62   (exit 1); exit 1
63 fi
64
65 fail=0
66
67 ls --file-type d > out || fail=1
68 cat <<\EOF > exp || fail=1
69 s@
70 EOF
71
72 cmp out exp || fail=1
73 test $fail = 1 && diff out exp 2> /dev/null
74
75 rm -f out exp
76 # Check for the ls -CF misaligned-columns bug:
77 ls -CF e > out || fail=1
78
79 # coreutils-6.0 would print two spaces after the first slash,
80 # rather than the appropriate TAB.
81 printf 'a2345/\tb/\n' > exp || fail=1
82
83 cmp out exp || fail=1
84 test $fail = 1 && diff out exp 2> /dev/null
85
86 (exit $fail); exit $fail