git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Eric Sunshine <sunshine@sunshineco.com>
Subject: [PATCH] test_cmp: diagnose incorrect arguments more precisely
Date: Sat,  3 Oct 2020 03:04:12 -0400	[thread overview]
Message-ID: <20201003070412.33015-1-sunshine@sunshineco.com> (raw)
In-Reply-To: <xmqq4knxwhkc.fsf@gitster.c.googlers.com>

d572f52a64 (test_cmp: diagnose incorrect arguments, 2020-08-09) taught
test_cmp() and test_cmp_bin() to diagnose a missing input source. Even
though the arguments to test_cmp() must name regular files (or standard
input), it only diagnoses whether a source is missing, which makes the
check a bit loose. Teach the check to be more precise by diagnosing, not
only a missing source, but also if the source is not a regular file.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---

  On Wed, Sep 16, 2020 at 5:14 PM Junio C Hamano <gitster@pobox.com> wrote:
  > Eric Sunshine <sunshine@sunshineco.com> writes:
  > > [...] I ask because test_cmp() was updated not long ago to
  > > provide better diagnostics when one of the files is missing.
  > > [1]: d572f52a64 (test_cmp: diagnose incorrect arguments, 2020-08-09)
  >
  > Yes, you did this with the commit,
  >         test "x$1" = x- || test -e "$1" || BUG "test_cmp '$1' missing"
  >         test "x$2" = x- || test -e "$2" || BUG "test_cmp '$2' missing"
  > and I do not immediately see why "test -e" shouldn't be "test -f".
  > It should ideally be "stdin is OK, otherwise it must be a readable
  > regular file".

  Perhaps the present patch suitably address your concern?

 t/test-lib-functions.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 8d59b90348..4bc54e9e80 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -955,8 +955,8 @@ test_cmp() {
 	test $# -eq 2 || BUG "test_cmp requires two arguments"
 	if ! eval "$GIT_TEST_CMP" '"$@"'
 	then
-		test "x$1" = x- || test -e "$1" || BUG "test_cmp '$1' missing"
-		test "x$2" = x- || test -e "$2" || BUG "test_cmp '$2' missing"
+		test "x$1" = x- || test -f "$1" || BUG "test_cmp '$1' missing or not regular file"
+		test "x$2" = x- || test -f "$2" || BUG "test_cmp '$2' missing or not regular file"
 		return 1
 	fi
 }
@@ -990,8 +990,8 @@ test_cmp_bin() {
 	test $# -eq 2 || BUG "test_cmp_bin requires two arguments"
 	if ! cmp "$@"
 	then
-		test "x$1" = x- || test -e "$1" || BUG "test_cmp_bin '$1' missing"
-		test "x$2" = x- || test -e "$2" || BUG "test_cmp_bin '$2' missing"
+		test "x$1" = x- || test -f "$1" || BUG "test_cmp_bin '$1' missing or not regular file"
+		test "x$2" = x- || test -f "$2" || BUG "test_cmp_bin '$2' missing or not regular file"
 		return 1
 	fi
 }
-- 
2.28.0.942.g77c4c6094c


  reply	other threads:[~2020-10-03  7:06 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-16 10:29 [PATCH 00/15] remote-mediawiki: various fixes to make tests pass Ævar Arnfjörð Bjarmason
2020-09-16 10:29 ` [PATCH 01/15] remote-mediawiki doc: correct link to GitHub project Ævar Arnfjörð Bjarmason
2020-09-16 10:29 ` [PATCH 02/15] remote-mediawiki doc: link to MediaWiki's current version Ævar Arnfjörð Bjarmason
2020-09-16 10:29 ` [PATCH 03/15] remote-mediawiki doc: bump recommended PHP version to 7.3 Ævar Arnfjörð Bjarmason
2020-09-16 13:47   ` Đoàn Trần Công Danh
2020-09-16 20:41     ` Junio C Hamano
2020-09-16 10:29 ` [PATCH 04/15] remote-mediawiki tests: use the login/password variables Ævar Arnfjörð Bjarmason
2020-09-16 10:29 ` [PATCH 05/15] remote-mediawiki tests: use a 10 character password Ævar Arnfjörð Bjarmason
2020-09-16 10:29 ` [PATCH 06/15] remote-mediawiki tests: use test_cmp in tests Ævar Arnfjörð Bjarmason
2020-09-16 18:38   ` Jeff King
2020-09-16 10:29 ` [PATCH 07/15] remote-mediawiki tests: guard test_cmp with test_path_is_file Ævar Arnfjörð Bjarmason
2020-09-16 14:04   ` Đoàn Trần Công Danh
2020-09-16 16:53   ` Eric Sunshine
2020-09-16 21:13     ` Junio C Hamano
2020-10-03  7:04       ` Eric Sunshine [this message]
2020-10-03 17:22         ` [PATCH] test_cmp: diagnose incorrect arguments more precisely Junio C Hamano
2020-09-21  8:54     ` [PATCH 07/15] remote-mediawiki tests: guard test_cmp with test_path_is_file Ævar Arnfjörð Bjarmason
2020-09-21 10:42       ` Ævar Arnfjörð Bjarmason
2020-09-16 18:41   ` Jeff King
2020-09-16 10:29 ` [PATCH 08/15] remote-mediawiki tests: change `[]` to `test` Ævar Arnfjörð Bjarmason
2020-09-16 10:29 ` [PATCH 09/15] remote-mediawiki tests: use "$dir/" instead of "$dir." Ævar Arnfjörð Bjarmason
2020-09-16 18:43   ` Jeff King
2020-09-16 21:15   ` Junio C Hamano
2020-09-16 10:29 ` [PATCH 10/15] remote-mediawiki tests: use a more idiomatic dispatch table Ævar Arnfjörð Bjarmason
2020-09-16 10:29 ` [PATCH 11/15] remote-mediawiki tests: replace deprecated Perl construct Ævar Arnfjörð Bjarmason
2020-09-16 18:49   ` Jeff King
2020-09-16 10:29 ` [PATCH 12/15] remote-mediawiki tests: use inline PerlIO for readability Ævar Arnfjörð Bjarmason
2020-09-16 10:29 ` [PATCH 13/15] remote-mediawiki tests: use CLI installer Ævar Arnfjörð Bjarmason
2020-09-16 10:29 ` [PATCH 14/15] remote-mediawiki: fix duplicate revisions being imported Ævar Arnfjörð Bjarmason
2020-09-16 10:29 ` [PATCH 15/15] remote-mediawiki tests: annotate failing tests Ævar Arnfjörð Bjarmason
2020-09-16 18:57 ` [PATCH 00/15] remote-mediawiki: various fixes to make tests pass Jeff King
2020-09-17 22:28   ` Junio C Hamano
2020-09-16 19:46 ` Johannes Schindelin
2020-09-21 10:15   ` Ævar Arnfjörð Bjarmason
2020-09-21 10:39 ` [PATCH v2 00/18] remote-mediawiki: fix RCE issue, and the tests Ævar Arnfjörð Bjarmason
2020-09-25  6:50   ` Jeff King
2020-09-21 10:39 ` [PATCH v2 01/18] remote-mediawiki doc: correct link to GitHub project Ævar Arnfjörð Bjarmason
2020-09-21 10:39 ` [PATCH v2 02/18] remote-mediawiki doc: link to MediaWiki's current version Ævar Arnfjörð Bjarmason
2020-09-21 10:39 ` [PATCH v2 03/18] remote-mediawiki doc: don't hardcode Debian PHP versions Ævar Arnfjörð Bjarmason
2020-09-21 10:39 ` [PATCH v2 04/18] remote-mediawiki tests: use the login/password variables Ævar Arnfjörð Bjarmason
2020-09-21 10:39 ` [PATCH v2 05/18] remote-mediawiki tests: use a 10 character password Ævar Arnfjörð Bjarmason
2020-09-21 10:39 ` [PATCH v2 06/18] remote-mediawiki tests: use test_cmp in tests Ævar Arnfjörð Bjarmason
2020-09-21 10:39 ` [PATCH v2 07/18] remote-mediawiki tests: change `[]` to `test` Ævar Arnfjörð Bjarmason
2020-09-21 10:39 ` [PATCH v2 08/18] remote-mediawiki tests: use "$dir/" instead of "$dir." Ævar Arnfjörð Bjarmason
2020-09-21 10:39 ` [PATCH v2 09/18] remote-mediawiki tests: use a more idiomatic dispatch table Ævar Arnfjörð Bjarmason
2020-09-21 10:39 ` [PATCH v2 10/18] remote-mediawiki tests: replace deprecated Perl construct Ævar Arnfjörð Bjarmason
2020-09-21 10:39 ` [PATCH v2 11/18] remote-mediawiki tests: use inline PerlIO for readability Ævar Arnfjörð Bjarmason
2020-09-21 10:39 ` [PATCH v2 12/18] remote-mediawiki tests: use CLI installer Ævar Arnfjörð Bjarmason
2020-09-21 10:39 ` [PATCH v2 13/18] remote-mediawiki: fix duplicate revisions being imported Ævar Arnfjörð Bjarmason
2020-09-21 10:39 ` [PATCH v2 14/18] remote-mediawiki tests: annotate failing tests Ævar Arnfjörð Bjarmason
2020-09-21 10:39 ` [PATCH v2 15/18] remote-mediawiki: provide a list form of run_git() Ævar Arnfjörð Bjarmason
2020-09-21 10:39 ` [PATCH v2 16/18] remote-mediawiki: convert to quoted run_git() invocation Ævar Arnfjörð Bjarmason
2020-09-21 10:39 ` [PATCH v2 17/18] remote-mediawiki: annotate unquoted uses of run_git() Ævar Arnfjörð Bjarmason
2020-09-21 10:40 ` [PATCH v2 18/18] remote-mediawiki: use "sh" to eliminate unquoted commands Ævar Arnfjörð Bjarmason

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=20201003070412.33015-1-sunshine@sunshineco.com \
    --to=sunshine@sunshineco.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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).