git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: COGONI Guillaume <cogoni.guillaume@gmail.com>
To: avarab@gmail.com
Cc: cogoni.guillaume@gmail.com, git.jonathan.bressat@gmail.com,
	git@vger.kernel.org, gitster@pobox.com,
	guillaume.cogoni@gmail.com, matthieu.moy@univ-lyon1.fr
Subject: [PATCH v2 0/2] replace test [-f|-d] with more verbose functions
Date: Fri, 18 Feb 2022 18:10:47 +0100	[thread overview]
Message-ID: <20220218171049.262341-1-cogoni.guillaume@gmail.com> (raw)
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


  reply	other threads:[~2022-02-18 17:11 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-11 13:46 [PATCH] t/t3903-stash.sh: replace test [-d|-f] with test_path_is_* COGONI Guillaume
2022-02-11 18:02 ` Junio C Hamano
2022-02-14 20:22   ` Cogoni Guillaume
2022-02-15 22:13     ` Ævar Arnfjörð Bjarmason
2022-02-18 17:10       ` COGONI Guillaume [this message]
2022-02-18 17:12       ` [PATCH v2 0/2] replace test [-f|-d] with more verbose functions COGONI Guillaume
2022-02-18 17:12         ` [PATCH v2 1/2] t/t3903-stash.sh: replace test [-d|-f] with test_path_is_* COGONI Guillaume
2022-02-18 17:12         ` [PATCH v2 2/2] Add new tests functions like test_path_is_* COGONI Guillaume
2022-02-18 18:48           ` Junio C Hamano
2022-02-22 21:54             ` [PATCH v3 0/3] replace test [-f|-d] with more verbose functions COGONI Guillaume
2022-02-22 21:54               ` [PATCH v3 1/3] t/t3903-stash.sh: replace test [-d|-f] with test_path_is_* COGONI Guillaume
2022-02-22 21:54               ` [PATCH v3 2/3] tests: allow testing if a path is truly a file or a directory COGONI Guillaume
2022-02-22 21:54               ` [PATCH v3 3/3] tests: make the code more readable COGONI Guillaume
2022-02-23 22:59               ` [PATCH v3 0/3] replace test [-f|-d] with more verbose functions Junio C Hamano
2022-02-24 18:22                 ` Cogoni Guillaume

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220218171049.262341-1-cogoni.guillaume@gmail.com \
    --to=cogoni.guillaume@gmail.com \
    --cc=avarab@gmail.com \
    --cc=git.jonathan.bressat@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=guillaume.cogoni@gmail.com \
    --cc=matthieu.moy@univ-lyon1.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).