From 3c2cf6241bf995fac3de41049106ba74016e2963 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 28 Dec 2020 22:40:30 +0100 Subject: [PATCH] Add some error tests for `cd` Makes work on #7577 easier. --- tests/checks/cd.fish | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tests/checks/cd.fish b/tests/checks/cd.fish index 88cb84da6..b08e7af74 100644 --- a/tests/checks/cd.fish +++ b/tests/checks/cd.fish @@ -126,10 +126,73 @@ test $PWD = $base/-testdir echo $status #CHECK: 0 +# test a few error cases - nonexistent directory +set -l old_cdpath $CDPATH +set -l old_path $PWD +cd nonexistent +#CHECKERR: cd: The directory 'nonexistent' does not exist +#CHECKERR: {{.*}}/cd.fish (line {{\d+}}): +#CHECKERR: builtin cd $argv +#CHECKERR: ^ +#CHECKERR: in function 'cd' with arguments 'nonexistent' +#CHECKERR: called on line {{\d+}} of file {{.*}}/cd.fish + +touch file +cd file +#CHECKERR: cd: 'file' is not a directory +#CHECKERR: {{.*}}/cd.fish (line {{\d+}}): +#CHECKERR: builtin cd $argv +#CHECKERR: ^ +#CHECKERR: in function 'cd' with arguments 'file' +#CHECKERR: called on line {{\d+}} of file {{.*}}/cd.fish + +# a directory that isn't executable +mkdir bad-perms +chmod -x bad-perms +cd bad-perms +#CHECKERR: cd: Permission denied: 'bad-perms' +#CHECKERR: {{.*}}/cd.fish (line {{\d+}}): +#CHECKERR: builtin cd $argv +#CHECKERR: ^ +#CHECKERR: in function 'cd' with arguments 'bad-perms' +#CHECKERR: called on line {{\d+}} of file {{.*}}/cd.fish + +cd $old_path +mkdir -p cdpath-dir/bad-perms +mkdir -p cdpath-dir/nonexistent +mkdir -p cdpath-dir/file +set CDPATH $PWD/cdpath-dir $old_cdpath + +# A different directory with the same name that is first in $CDPATH works. +cd bad-perms +cd $old_path +cd nonexistent +cd $old_path +cd file +cd $old_path + +# Even if the good dirs are later in $CDPATH most errors still aren't a problem +# - they just cause us to keep looking. +cd $old_path +set CDPATH $old_cdpath $PWD/cdpath-dir +cd nonexistent +cd $old_path +cd bad-perms +# Permission errors are still a problem! +#CHECKERR: cd: Permission denied: 'bad-perms' +#CHECKERR: {{.*}}/cd.fish (line {{\d+}}): +#CHECKERR: builtin cd $argv +#CHECKERR: ^ +#CHECKERR: in function 'cd' with arguments 'bad-perms' +#CHECKERR: called on line {{\d+}} of file {{.*}}/cd.fish +cd $old_path +cd file +cd $old_path # cd back before removing the test directory again. cd $oldpwd rm -Rf $base +set -g CDPATH ./ # Verify that PWD on-variable events are sent function __fish_test_changed_pwd --on-variable PWD