Git development
 help / color / mirror / Atom feed
* [PATCH] t: use test_must_fail instead of NOT operator
@ 2026-11-15 18:15 Hardik Kumar
  2026-11-16 16:07 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Hardik Kumar @ 2026-11-15 18:15 UTC (permalink / raw)
  To: git; +Cc: Hardik Kumar

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-16 17:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-15 18:15 [PATCH] t: use test_must_fail instead of NOT operator Hardik Kumar
2026-11-16 16:07 ` Junio C Hamano
2026-11-16 17:33   ` Hardik Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox