]> git.ipfire.org Git - thirdparty/git.git/commitdiff
tests: allow testing if a path is truly a file or a directory
authorCOGONI Guillaume <cogoni.guillaume@gmail.com>
Tue, 22 Feb 2022 21:54:29 +0000 (22:54 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Feb 2022 23:08:44 +0000 (15:08 -0800)
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 <cogoni.guillaume@gmail.com>
Co-authored-by: BRESSAT Jonathan <git.jonathan.bressat@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t3903-stash.sh
t/test-lib-functions.sh

index d6a37692f66600f9b074369beb3f02c18dee6528..0a82bc857d16ad46fafe8dbc74b4038a4c38722b 100755 (executable)
@@ -390,7 +390,7 @@ test_expect_success SYMLINKS 'stash file to symlink' '
        rm file &&
        ln -s file2 file &&
        git stash save "file to symlink" &&
-       test -f file &&
+       test_path_is_file_not_symlink file &&
        test bar = "$(cat file)" &&
        git stash apply &&
        case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
@@ -401,7 +401,7 @@ test_expect_success SYMLINKS 'stash file to symlink (stage rm)' '
        git rm file &&
        ln -s file2 file &&
        git stash save "file to symlink (stage rm)" &&
-       test -f file &&
+       test_path_is_file_not_symlink file &&
        test bar = "$(cat file)" &&
        git stash apply &&
        case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
@@ -413,7 +413,7 @@ test_expect_success SYMLINKS 'stash file to symlink (full stage)' '
        ln -s file2 file &&
        git add file &&
        git stash save "file to symlink (full stage)" &&
-       test -f file &&
+       test_path_is_file_not_symlink file &&
        test bar = "$(cat file)" &&
        git stash apply &&
        case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
index 85385d2ede7eeaac6febd11772c0e2589cfa0d67..0f439c99d6109110786db0492111ebdb945342a6 100644 (file)
@@ -856,6 +856,16 @@ test_path_is_file () {
        fi
 }
 
+test_path_is_file_not_symlink () {
+       test "$#" -ne 1 && BUG "1 param"
+       test_path_is_file "$1" &&
+       if test -h "$1"
+       then
+               echo "$1 shouldn't be a symbolic link"
+               false
+       fi
+}
+
 test_path_is_dir () {
        test "$#" -ne 1 && BUG "1 param"
        if ! test -d "$1"
@@ -865,6 +875,16 @@ test_path_is_dir () {
        fi
 }
 
+test_path_is_dir_not_symlink () {
+       test "$#" -ne 1 && BUG "1 param"
+       test_path_is_dir "$1" &&
+       if test -h "$1"
+       then
+               echo "$1 shouldn't be a symbolic link"
+               false
+       fi
+}
+
 test_path_exists () {
        test "$#" -ne 1 && BUG "1 param"
        if ! test -e "$1"
@@ -874,6 +894,15 @@ test_path_exists () {
        fi
 }
 
+test_path_is_symlink () {
+       test "$#" -ne 1 && BUG "1 param"
+       if ! test -h "$1"
+       then
+               echo "Symbolic link $1 doesn't exist"
+               false
+       fi
+}
+
 # Check if the directory exists and is empty as expected, barf otherwise.
 test_dir_is_empty () {
        test "$#" -ne 1 && BUG "1 param"