Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / misc / pwd-unreadable-parent
1 #!/bin/sh
2 # Ensure that pwd and "readlink -e ." work even when a parent directory
3 # is unreadable.  Perform this test only on systems with a usable getcwd
4 # function that has this capability.
5
6 # Copyright (C) 2007 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 if test "$VERBOSE" = yes; then
24   set -x
25   pwd --version
26   readlink --version
27 fi
28
29 test $host_os != linux-gnu &&
30   {
31     echo 1>&2 "$0: vendor getcwd may be inadequate; skipping this test"
32     (exit 77); exit 77
33   }
34
35 # Linux ia64 has the gl_FUNC_GETCWD_ABORT_BUG, so we can't use
36 # the system getcwd.
37 test $REPLACE_GETCWD = 1 &&
38   {
39     echo 1>&2 "$0: can't use buggy system getcwd; skipping this test"
40     (exit 77); exit 77
41   }
42
43 pwd=`pwd`
44 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
45 trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0
46 trap '(exit $?); exit $?' 1 2 13 15
47
48 framework_failure=0
49 mkdir -p $tmp || framework_failure=1
50 cd $tmp || framework_failure=1
51
52 mkdir -p a/b || framework_failure=1
53 cd a/b || framework_failure=1
54 chmod a=x .. || framework_failure=1
55
56 if test $framework_failure = 1; then
57   echo "$0: failure in testing framework" 1>&2
58   (exit 1); exit 1
59 fi
60
61 pwd_exe=$pwd/../../src/pwd
62
63 fail=0
64 $pwd_exe > exp || fail=1
65 readlink -ev . > out || fail=1
66
67 cmp out exp || fail=1
68 test $fail = 1 && diff out exp 2> /dev/null
69
70 (exit $fail); exit $fail