From c2fad38bf842b6208d323a7a17bbfaffb4ab17a2 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Sun, 22 May 2022 12:36:58 +0100 Subject: [PATCH] Fix 'cd -e' regress fails on some UNIXen (re: e6989853, b398f33c) On some systems, including at least Solaris 10.1 and QNX 6.5.0, the regression tests below occurred. This is because, on these systems, 'cd .' always fails with 'no such file or directory', regardless of flags, if the present working directory no longer exists. This is a legitimate variation in UNIX-like systems so the tests should be compatible. test builtins begins at 2022-05-22+13:08:28 /usr/local/src/ksh/src/cmd/ksh93/tests/builtins.sh[1499]: cd: .: [No such file or directory] builtins.sh[1501]: FAIL: cd -P without -e exits with error status if $PWD doesn't exist (expected 0, got 1) /usr/local/src/ksh/src/cmd/ksh93/tests/builtins.sh[1504]: cd: .: [No such file or directory] builtins.sh[1506]: FAIL: cd -eP doesn't fail if $PWD doesn't exist (expected 1, got 2) test builtins failed at 2022-05-22+13:08:37 with exit code 2 [ 287 tests 2 errors ] src/cmd/ksh93/tests/builtins.sh: - Delete the 'cd -P .' test for a nonexistent PWD. - For the 'cd -eP .' test for a nonexistent PWD, redirect standard error to /dev/null and also accept exit status 2, which we would expect with the '-e' flag if a 'no such file or directory' error is thrown. --- src/cmd/ksh93/tests/builtins.sh | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/cmd/ksh93/tests/builtins.sh b/src/cmd/ksh93/tests/builtins.sh index a37bb6a28..5fd7f2044 100755 --- a/src/cmd/ksh93/tests/builtins.sh +++ b/src/cmd/ksh93/tests/builtins.sh @@ -1493,17 +1493,12 @@ fi # ====== # These are regression tests for the cd command's -e and -P flags -mkdir -p "$tmp/failpwd" -cd "$tmp/failpwd" -"$SHELL" -c 'cd /; exec rmdir "$1"' x "$tmp/failpwd" -cd -P . -got=$?; exp=0 -(( got == exp )) || err_exit "cd -P without -e exits with error status if \$PWD doesn't exist (expected $exp, got $got)" if ((.sh.version >= 20211205)) then - cd -eP . - got=$?; exp=1 - (( got == exp )) || err_exit "cd -eP doesn't fail if \$PWD doesn't exist (expected $exp, got $got)" + mkdir -p "$tmp/failpwd" + cd "$tmp/failpwd" + "$SHELL" -c 'cd /; exec rmdir "$1"' x "$tmp/failpwd" + cd -eP . 2>/dev/null && err_exit "cd -eP doesn't fail if \$PWD doesn't exist" fi cd "$tmp"