]> git.cameronkatri.com Git - apple_cmds.git/blob - shell_cmds/sh/tests/builtins/cd4.0
Import macOS userland
[apple_cmds.git] / shell_cmds / sh / tests / builtins / cd4.0
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
8 set -e
9 L=$(getconf PATH_MAX / 2>/dev/null) || L=4096
10 [ "$L" -lt 100000 ] 2>/dev/null || L=4096
11 L=$((L+100))
12 T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX)
13 trap 'chmod u+r ${T}; rm -rf ${T}' 0
14 cd -Pe $T
15 D=$(pwd)
16 chmod u-r "$D"
17 if [ -r "$D" ]; then
18 # Running as root, cannot test.
19 exit 0
20 fi
21 set +e
22 while [ ${#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
36 done
37 echo "cd -Pe never returned 1"
38 exit 0