git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] t: use test_must_fail instead of NOT operator

From
Hardik Kumar <hardikxk@gmail.com>
Date
Nov 15, 2026, 18:15 UTC
Message-ID
<20261115-t-tmf-refactor-v1-1-d7a95cdeaedd@gmail.com>

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: Junio C Hamano
Message 1 of 3 in “t: use test_must_fail instead of NOT operator”
  1. t: use test_must_fail instead of NOT operatorHardik Kumar, Nov 15, 2026
  2. Junio C HamanoNov 16, 2026
  3. Hardik KumarNov 16, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.