From: Hardik Kumar <hardikxk@gmail.com>
To: git@vger.kernel.org
Cc: Hardik Kumar <hardikxk@gmail.com>
Subject: [PATCH] t: use test_must_fail instead of NOT operator
Date: Sun, 15 Nov 2026 23:45:21 +0530 [thread overview]
Message-ID: <20261115-t-tmf-refactor-v1-1-d7a95cdeaedd@gmail.com> (raw)
Replace `!` operator with `test_must_fail` for multiple unit tests where
a git command is expected to fail.
`test_must_fail` handles edge cases like a command killed by a signal
or a crash because of a segfault, by actually failing the test unlike
the `!` operator which would result in the test being passed as the
crash is accepted as a failure (the test is expected to fail).
Signed-off-by: Hardik Kumar <hardikxk@gmail.com>
---
t/t5564-http-proxy.sh | 4 ++--
t/t6030-bisect-porcelain.sh | 4 ++--
t/t7400-submodule-basic.sh | 4 ++--
t/t9001-send-email.sh | 2 +-
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/t/t5564-http-proxy.sh b/t/t5564-http-proxy.sh
index 866e2b4e93..429604d528 100755
--- a/t/t5564-http-proxy.sh
+++ b/t/t5564-http-proxy.sh
@@ -89,14 +89,14 @@ test_expect_success SOCKS_PROXY 'clone via Unix socket' '
'
test_expect_success 'Unix socket requires socks*:' - <<\EOT
- ! git clone -c http.proxy=localhost/path https://example.com/repo.git 2>err && {
+ test_must_fail git clone -c http.proxy=localhost/path https://example.com/repo.git 2>err && {
test_grep -Fx "fatal: Invalid proxy URL 'localhost/path': only SOCKS proxies support paths" err ||
old_libcurl_error err
}
EOT
test_expect_success 'Unix socket requires localhost' - <<\EOT
- ! git clone -c http.proxy=socks4://127.0.0.1/path https://example.com/repo.git 2>err && {
+ test_must_fail git clone -c http.proxy=socks4://127.0.0.1/path https://example.com/repo.git 2>err && {
test_grep -Fx "fatal: Invalid proxy URL 'socks4://127.0.0.1/path': host must be localhost if a path is present" err ||
old_libcurl_error err
}
diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh
index a7588222a8..d5e7987f56 100755
--- a/t/t6030-bisect-porcelain.sh
+++ b/t/t6030-bisect-porcelain.sh
@@ -437,7 +437,7 @@ test_expect_success 'git bisect run: negative exit code' "
git bisect start &&
git bisect good $HASH1 &&
git bisect bad $HASH4 &&
- ! git bisect run ./fail.sh 2>err &&
+ test_must_fail git bisect run ./fail.sh 2>err &&
sed -E -n 's/.*(bisect.*code) (-?[0-9]+) (from.*)/\1 -1 \3/p' err >actual &&
test_cmp expect actual
"
@@ -460,7 +460,7 @@ test_expect_success 'git bisect run: unable to verify on good' "
git bisect start &&
git bisect good $HASH1 &&
git bisect bad $HASH4 &&
- ! git bisect run ./fail.sh 2>err &&
+ test_must_fail git bisect run ./fail.sh 2>err &&
sed -n 's/.*\(unable to verify.*\)/\1/p' err >actual &&
test_cmp expect actual
"
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 36ff5b9546..345c257829 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -237,7 +237,7 @@ test_expect_success 'submodule add to .gitignored path fails' '
echo "*" > .gitignore &&
git add --force .gitignore &&
git commit -m"Ignore everything" &&
- ! git submodule add "$submodurl" submod >actual 2>&1 &&
+ test_must_fail git submodule add "$submodurl" submod >actual 2>&1 &&
test_cmp expect actual
)
'
@@ -280,7 +280,7 @@ test_expect_success 'submodule add relays add --dry-run stderr' '
(
cd addtest &&
: >.git/index.lock &&
- ! git submodule add "$submodurl" sub-while-locked 2>output.err &&
+ test_must_fail git submodule add "$submodurl" sub-while-locked 2>output.err &&
test_grep "^fatal: .*index\.lock" output.err &&
test_path_is_missing sub-while-locked
)
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index d1393ef197..ef612acaeb 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -476,7 +476,7 @@ test_expect_success $PREREQ 'malform output reported on blank lines in command o
SomeOtherField: someone-else@example.com"
EOF
- ! git send-email \
+ test_must_fail git send-email \
--from="Example <nobody@example.com>" \
--to=nobody@example.com \
--header-cmd=./headercmd-malformed-output \
---
base-commit: 7fb6055e678f800320d8ab8cd8f201d9493d1ba0
change-id: 20261115-t-tmf-refactor-dc3742c2eab7
next reply other threads:[~2026-11-15 18:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 18:15 Hardik Kumar [this message]
2026-11-16 16:07 ` [PATCH] t: use test_must_fail instead of NOT operator Junio C Hamano
2026-11-16 17:33 ` Hardik Kumar
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=20261115-t-tmf-refactor-v1-1-d7a95cdeaedd@gmail.com \
--to=hardikxk@gmail.com \
--cc=git@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox