git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 0/2] replace test [-f|-d] with more verbose functions

From
COGONI Guillaume <cogoni.guillaume@gmail.com>
Date
Feb 18, 2022, 17:12 UTC
Message-ID
<20220218171224.262698-1-cogoni.guillaume@gmail.com>
In-Reply-To
<220215.86a6erwzee.gmgdl@evledraar.gmail.com>
> On 02/11/2022 at 7:02 PM, Junio ​​C Hamano wrote:
> * introduce test_path_is_symlink and use it appropriately.  This
>   will be a more verbose version of "test -h".
> * introduce test_path_is_file_not_symlink and use it here.

Replace test [-f|-d] in t/t3903-stash.sh by test_path_is_* Add new functions like test_path_is_* to cover more specifics cases like symbolic link or file that we explicitly refuse to be symbolic link.

COGONI Guillaume (2):
  t/t3903-stash.sh: replace test [-d|-f] with test_path_is_*
  Add new tests functions like test_path_is_*
 t/t3903-stash.sh        | 21 +++++++++------------
 t/test-lib-functions.sh | 20 ++++++++++++++++++++
 2 files changed, 29 insertions(+), 12 deletions(-)
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index e8e933dc4e..0ec19a4499 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -390,10 +390,9 @@ test_expect_success SYMLINKS 'stash file to symlink' '
        rm file &&
        ln -s file2 file &&
        git stash save "file to symlink" &&
-       test_path_is_file file &&
+       test_path_is_file_not_symlink file &&
        test bar = "$(cat file)" &&
-       git stash apply &&
-       case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
+       git stash apply
 '
 
 test_expect_success SYMLINKS 'stash file to symlink (stage rm)' '
@@ -401,10 +400,9 @@ 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_path_is_file file &&
+       test_path_is_file_not_symlink file &&
        test bar = "$(cat file)" &&
-       git stash apply &&
-       case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
+       git stash apply
 '
 
 test_expect_success SYMLINKS 'stash file to symlink (full stage)' '
@@ -413,10 +411,9 @@ 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_path_is_file file &&
+       test_path_is_file_not_symlink file &&
        test bar = "$(cat file)" &&
-       git stash apply &&
-       case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
+       git stash apply
 '
 
 # This test creates a commit with a symlink used for the following tests
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 85385d2ede..61fc5f37e3 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -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 is 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 is a symbolic link"
+               false
+       fi
+}
+
 test_path_exists () {
        test "$#" -ne 1 && BUG "1 param"
        if ! test -e "$1"
-- 
2.25.1
Previous: COGONI GuillaumeNext: COGONI Guillaume
Message 6 of 15 in “t/t3903-stash.sh: replace test [-d|-f] with test_path_is_*”
  1. t/t3903-stash.sh: replace test [-d|-f] with test_path_is_*COGONI Guillaume, Feb 11, 2022
  2. Junio C HamanoFeb 11, 2022
  3. Cogoni GuillaumeFeb 14, 2022
  4. Ævar Arnfjörð BjarmasonFeb 15, 2022
  5. 0/2 replace test [-f|-d] with more verbose functionsCOGONI Guillaume, Feb 18, 2022
  6. 0/2 replace test [-f|-d] with more verbose functionsCOGONI Guillaume, Feb 18, 2022
  7. 1/2 t/t3903-stash.sh: replace test [-d|-f] with test_path_is_*COGONI Guillaume, Feb 18, 2022
  8. 2/2 Add new tests functions like test_path_is_*COGONI Guillaume, Feb 18, 2022
  9. Junio C HamanoFeb 18, 2022
  10. 0/3 replace test [-f|-d] with more verbose functionsCOGONI Guillaume, Feb 22, 2022
  11. 1/3 t/t3903-stash.sh: replace test [-d|-f] with test_path_is_*COGONI Guillaume, Feb 22, 2022
  12. 2/3 tests: allow testing if a path is truly a file or a directoryCOGONI Guillaume, Feb 22, 2022
  13. 3/3 tests: make the code more readableCOGONI Guillaume, Feb 22, 2022
  14. Junio C HamanoFeb 23, 2022
  15. Cogoni GuillaumeFeb 24, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.