xref: /dragonfly/tools/regression/bin/sh/builtins/cd4.0 (revision 3e3895bf4584c1562faf4533cbd97026ee6a8dcf)
1# $FreeBSD: head/bin/sh/tests/builtins/cd4.0 222154 2011-05-20 22:55:18Z jilles $
2
3# This test assumes that whatever mechanism cd -P uses to determine the
4# pathname to the current directory if it is longer than PATH_MAX requires
5# read permission on all parent directories. It also works if this
6# requirement always applies.
7
8set -e
9L=$(getconf PATH_MAX / 2>/dev/null) || L=4096
10[ "$L" -lt 100000 ] 2>/dev/null || L=4096
11L=$((L+100))
12T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX)
13trap 'chmod u+r ${T}; rm -rf ${T}' 0
14cd -Pe $T
15D=$(pwd)
16chmod u-r "$D"
17if [ -r "$D" ]; then
18          # Running as root, cannot test.
19          exit 0
20fi
21set +e
22while [ ${#D} -lt $L ]; do
23          mkdir veryverylongdirectoryname || exit
24          cd -Pe veryverylongdirectoryname 2>/dev/null
25          r=$?
26          [ $r -gt 1 ] && exit $r
27          if [ $r -eq 1 ]; then
28                    # Verify that the directory was changed correctly.
29                    cd -Pe .. || exit
30                    [ "$(pwd)" = "$D" ] || exit
31                    # Verify that omitting -e results in success.
32                    cd -P veryverylongdirectoryname 2>/dev/null || exit
33                    exit 0
34          fi
35          D=$D/veryverylongdirectoryname
36done
37echo "cd -Pe never returned 1"
38exit 0
39