Skip to content

Commit 456296b

Browse files
WoodfeaSIr-Lorrak
authored andcommitted
tests: allow testing if a path is truly a file or a directory
Add test_path_is_file_not_symlink(), test_path_is_dir_not_symlink() and test_path_is_symlink(). Case of use for the first one in test t/t3903-stash.sh to replace "test -f" because that function explicitly want the file not to be a symlink. Give more friendly error message. Signed-off-by: COGONI Guillaume <[email protected]> Co-authored-by: BRESSAT Jonathan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f01f948 commit 456296b

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

t/t3903-stash.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ test_expect_success SYMLINKS 'stash file to symlink' '
390390
rm file &&
391391
ln -s file2 file &&
392392
git stash save "file to symlink" &&
393-
test -f file &&
393+
test_path_is_file_not_symlink file &&
394394
test bar = "$(cat file)" &&
395395
git stash apply &&
396396
case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
@@ -401,7 +401,7 @@ test_expect_success SYMLINKS 'stash file to symlink (stage rm)' '
401401
git rm file &&
402402
ln -s file2 file &&
403403
git stash save "file to symlink (stage rm)" &&
404-
test -f file &&
404+
test_path_is_file_not_symlink file &&
405405
test bar = "$(cat file)" &&
406406
git stash apply &&
407407
case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
@@ -413,7 +413,7 @@ test_expect_success SYMLINKS 'stash file to symlink (full stage)' '
413413
ln -s file2 file &&
414414
git add file &&
415415
git stash save "file to symlink (full stage)" &&
416-
test -f file &&
416+
test_path_is_file_not_symlink file &&
417417
test bar = "$(cat file)" &&
418418
git stash apply &&
419419
case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac

t/test-lib-functions.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,16 @@ test_path_is_file () {
856856
fi
857857
}
858858

859+
test_path_is_file_not_symlink () {
860+
test "$#" -ne 1 && BUG "1 param"
861+
test_path_is_file "$1" &&
862+
if test -h "$1"
863+
then
864+
echo "$1 shouldn't be a symbolic link"
865+
false
866+
fi
867+
}
868+
859869
test_path_is_dir () {
860870
test "$#" -ne 1 && BUG "1 param"
861871
if ! test -d "$1"
@@ -865,6 +875,16 @@ test_path_is_dir () {
865875
fi
866876
}
867877

878+
test_path_is_dir_not_symlink () {
879+
test "$#" -ne 1 && BUG "1 param"
880+
test_path_is_dir "$1" &&
881+
if test -h "$1"
882+
then
883+
echo "$1 shouldn't be a symbolic link"
884+
false
885+
fi
886+
}
887+
868888
test_path_exists () {
869889
test "$#" -ne 1 && BUG "1 param"
870890
if ! test -e "$1"
@@ -874,6 +894,15 @@ test_path_exists () {
874894
fi
875895
}
876896

897+
test_path_is_symlink () {
898+
test "$#" -ne 1 && BUG "1 param"
899+
if ! test -h "$1"
900+
then
901+
echo "Symbolic link $1 doesn't exist"
902+
false
903+
fi
904+
}
905+
877906
# Check if the directory exists and is empty as expected, barf otherwise.
878907
test_dir_is_empty () {
879908
test "$#" -ne 1 && BUG "1 param"

0 commit comments

Comments
 (0)