All of lore.kernel.org
 help / color / mirror / Atom feed
From: "SZEDER Gábor" <szeder.dev@gmail.com>
To: git@vger.kernel.org
Cc: "Jeff King" <peff@peff.net>, "Denton Liu" <liu.denton@gmail.com>,
	"SZEDER Gábor" <szeder.dev@gmail.com>
Subject: [PATCH 2/2] test-lib-functions: use BUG() in 'test_must_fail'
Date: Sun, 21 Feb 2021 20:25:12 +0100	[thread overview]
Message-ID: <20210221192512.3096291-2-szeder.dev@gmail.com> (raw)
In-Reply-To: <20210221192512.3096291-1-szeder.dev@gmail.com>

In many test helper functions we verify that they were invoked with
sensible parameters, and call BUG() to abort the test script when the
parameters are buggy.  6a67c75948 (test-lib-functions: restrict
test_must_fail usage, 2020-07-07) added such a parameter verification
to 'test_must_fail', but it didn't report the error with BUG(), like
we usually do.

As discussed in detail in the previous patch, BUG() didn't really work
in 'test_must_fail' back then, but it resolved those issues, so let's
use BUG() in this case as well.

The two tests checking that 'test_must_fail' recognizes invalid
parameters need some updates:

  - BUG() calls 'exit 1' to abort the test script, but we don't want
    that to happen while testing 'test_must_fail' itself, so in those
    tests we must invoke that function in a subshell.
  - These tests check that 'test_must_fail' failed with the
    appropriate error message, but BUG() sends its error message to a
    different file descriptor, so update the redirection accordingly.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
 t/t0000-basic.sh        | 4 ++--
 t/test-lib-functions.sh | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index a6e570d674..b9d5c6c404 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -1315,12 +1315,12 @@ test_expect_success 'test_must_fail on a failing git command with env' '
 '
 
 test_expect_success 'test_must_fail rejects a non-git command' '
-	! test_must_fail grep ^$ notafile 2>err &&
+	! ( test_must_fail grep ^$ notafile ) 7>err &&
 	grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err
 '
 
 test_expect_success 'test_must_fail rejects a non-git command with env' '
-	! test_must_fail env var1=a var2=b grep ^$ notafile 2>err &&
+	! ( test_must_fail env var1=a var2=b grep ^$ notafile ) 7>err &&
 	grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err
 '
 
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index a40c1c5d83..cdbc59e4f0 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -910,8 +910,7 @@ test_must_fail () {
 	esac
 	if ! test_must_fail_acceptable "$@"
 	then
-		echo >&6 "test_must_fail: only 'git' is allowed: $*"
-		return 1
+		BUG "test_must_fail: only 'git' is allowed: $*"
 	fi
 	"$@" 2>&6
 	exit_code=$?
-- 
2.30.1.940.gce394404de


  reply	other threads:[~2021-02-21 19:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-21 19:25 [PATCH 1/2] tests: don't mess with fd 7 of test helper functions SZEDER Gábor
2021-02-21 19:25 ` SZEDER Gábor [this message]
2021-02-21 21:58   ` [PATCH 2/2] test-lib-functions: use BUG() in 'test_must_fail' Jeff King
2021-02-22 19:11     ` Jeff King
2021-02-22 19:17       ` Jeff King
2021-02-22 20:02         ` Junio C Hamano
2026-04-14 20:52     ` SZEDER Gábor
2026-04-14 21:11       ` Junio C Hamano
2026-04-14 22:18         ` Jeff King
2026-04-15 15:25           ` Junio C Hamano
2026-04-14 22:14       ` Jeff King
2021-02-21 21:50 ` [PATCH 1/2] tests: don't mess with fd 7 of test helper functions Jeff King
2021-02-22 17:45   ` Junio C Hamano

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

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

  git send-email \
    --in-reply-to=20210221192512.3096291-2-szeder.dev@gmail.com \
    --to=szeder.dev@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=liu.denton@gmail.com \
    --cc=peff@peff.net \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.