{"thread":{"id":"66851","subject":"[PATCH] t: use test_must_fail instead of NOT operator","startedAt":"2026-11-15T18:15:21Z","lastAt":"2026-11-16T17:33:43Z","messageCount":3,"participants":["Hardik Kumar","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"558505","messageId":"20261115-t-tmf-refactor-v1-1-d7a95cdeaedd@gmail.com","threadId":"66851","inReplyTo":null,"subject":"[PATCH] t: use test_must_fail instead of NOT operator","fromName":"Hardik Kumar","fromEmail":"hardikxk@gmail.com","sentAt":"2026-11-15T18:15:21Z","receivedAt":"2026-11-15T18:15:21Z","isPatch":true,"sender":{"key":"hardikxk@gmail.com","avatar":"https://avatars.githubusercontent.com/u/183656738?v=4"},"body":"Replace `!` operator with `test_must_fail` for multiple unit tests where\na git command is expected to fail.\n\n`test_must_fail` handles edge cases like a command killed by a signal\nor a crash because of a segfault, by actually failing the test unlike\nthe `!` operator which would result in the test being passed as the\ncrash is accepted as a failure (the test is expected to fail).\n\nSigned-off-by: Hardik Kumar <hardikxk@gmail.com>\n---\n t/t5564-http-proxy.sh       | 4 ++--\n t/t6030-bisect-porcelain.sh | 4 ++--\n t/t7400-submodule-basic.sh  | 4 ++--\n t/t9001-send-email.sh       | 2 +-\n 4 files changed, 7 insertions(+), 7 deletions(-)\n\ndiff --git a/t/t5564-http-proxy.sh b/t/t5564-http-proxy.sh\nindex 866e2b4e93..429604d528 100755\n--- a/t/t5564-http-proxy.sh\n+++ b/t/t5564-http-proxy.sh\n@@ -89,14 +89,14 @@ test_expect_success SOCKS_PROXY 'clone via Unix socket' '\n '\n \n test_expect_success 'Unix socket requires socks*:' - <<\\EOT\n-\t! git clone -c http.proxy=localhost/path https://example.com/repo.git 2>err && {\n+\ttest_must_fail git clone -c http.proxy=localhost/path https://example.com/repo.git 2>err && {\n \t\ttest_grep -Fx \"fatal: Invalid proxy URL 'localhost/path': only SOCKS proxies support paths\" err ||\n \t\told_libcurl_error err\n \t}\n EOT\n \n test_expect_success 'Unix socket requires localhost' - <<\\EOT\n-\t! git clone -c http.proxy=socks4://127.0.0.1/path https://example.com/repo.git 2>err && {\n+\ttest_must_fail git clone -c http.proxy=socks4://127.0.0.1/path https://example.com/repo.git 2>err && {\n \t\ttest_grep -Fx \"fatal: Invalid proxy URL 'socks4://127.0.0.1/path': host must be localhost if a path is present\" err ||\n \t\told_libcurl_error err\n \t}\ndiff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh\nindex a7588222a8..d5e7987f56 100755\n--- a/t/t6030-bisect-porcelain.sh\n+++ b/t/t6030-bisect-porcelain.sh\n@@ -437,7 +437,7 @@ test_expect_success 'git bisect run: negative exit code' \"\n \tgit bisect start &&\n \tgit bisect good $HASH1 &&\n \tgit bisect bad $HASH4 &&\n-\t! git bisect run ./fail.sh 2>err &&\n+\ttest_must_fail git bisect run ./fail.sh 2>err &&\n \tsed -E -n 's/.*(bisect.*code) (-?[0-9]+) (from.*)/\\1 -1 \\3/p' err >actual &&\n \ttest_cmp expect actual\n \"\n@@ -460,7 +460,7 @@ test_expect_success 'git bisect run: unable to verify on good' \"\n \tgit bisect start &&\n \tgit bisect good $HASH1 &&\n \tgit bisect bad $HASH4 &&\n-\t! git bisect run ./fail.sh 2>err &&\n+\ttest_must_fail git bisect run ./fail.sh 2>err &&\n \tsed -n 's/.*\\(unable to verify.*\\)/\\1/p' err >actual &&\n \ttest_cmp expect actual\n \"\ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex 36ff5b9546..345c257829 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -237,7 +237,7 @@ test_expect_success 'submodule add to .gitignored path fails' '\n \t\techo \"*\" > .gitignore &&\n \t\tgit add --force .gitignore &&\n \t\tgit commit -m\"Ignore everything\" &&\n-\t\t! git submodule add \"$submodurl\" submod >actual 2>&1 &&\n+\t\ttest_must_fail git submodule add \"$submodurl\" submod >actual 2>&1 &&\n \t\ttest_cmp expect actual\n \t)\n '\n@@ -280,7 +280,7 @@ test_expect_success 'submodule add relays add --dry-run stderr' '\n \t(\n \t\tcd addtest &&\n \t\t: >.git/index.lock &&\n-\t\t! git submodule add \"$submodurl\" sub-while-locked 2>output.err &&\n+\t\ttest_must_fail git submodule add \"$submodurl\" sub-while-locked 2>output.err &&\n \t\ttest_grep \"^fatal: .*index\\.lock\" output.err &&\n \t\ttest_path_is_missing sub-while-locked\n \t)\ndiff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh\nindex d1393ef197..ef612acaeb 100755\n--- a/t/t9001-send-email.sh\n+++ b/t/t9001-send-email.sh\n@@ -476,7 +476,7 @@ test_expect_success $PREREQ 'malform output reported on blank lines in command o\n \n SomeOtherField: someone-else@example.com\"\n \tEOF\n-\t! git send-email \\\n+\ttest_must_fail git send-email \\\n \t\t--from=\"Example <nobody@example.com>\" \\\n \t\t--to=nobody@example.com \\\n \t\t--header-cmd=./headercmd-malformed-output \\\n\n---\nbase-commit: 7fb6055e678f800320d8ab8cd8f201d9493d1ba0\nchange-id: 20261115-t-tmf-refactor-dc3742c2eab7\n\n\n"},{"id":"558556","messageId":"xmqqcxs4n4k0.fsf@gitster.g","threadId":"66851","inReplyTo":"20261115-t-tmf-refactor-v1-1-d7a95cdeaedd@gmail.com","subject":"Re: [PATCH] t: use test_must_fail instead of NOT operator","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-16T16:07:11Z","receivedAt":"2026-11-16T16:07:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Hardik Kumar <hardikxk@gmail.com> writes:\n\n> Replace `!` operator with `test_must_fail` for multiple unit tests where\n> a git command is expected to fail.\n>\n> `test_must_fail` handles edge cases like a command killed by a signal\n> or a crash because of a segfault, by actually failing the test unlike\n> the `!` operator which would result in the test being passed as the\n> crash is accepted as a failure (the test is expected to fail).\n>\n> Signed-off-by: Hardik Kumar <hardikxk@gmail.com>\n> ---\n>  t/t5564-http-proxy.sh       | 4 ++--\n>  t/t6030-bisect-porcelain.sh | 4 ++--\n>  t/t7400-submodule-basic.sh  | 4 ++--\n>  t/t9001-send-email.sh       | 2 +-\n>  4 files changed, 7 insertions(+), 7 deletions(-)\n\nAll of them look sensible, but I am curious why you chose only\nthese, among 14 hits in\n\n    $ git grep -l '^[ \t]*! git ' t/\n\nI suspect that it is because these are ...\n\n> -\t! git clone -c http.proxy=localhost/path https://example.com/repo.git 2>err && {\n> -\t! git clone -c http.proxy=socks4://127.0.0.1/path https://example.com/repo.git 2>err && {\n> -\t! git bisect run ./fail.sh 2>err &&\n> -\t! git bisect run ./fail.sh 2>err &&\n\n... simple cases in which the use of leading ! negation is the only\nissue with them, and if that is the reasoning, I think that is\nsensible.  Contrasting these, many of the hits in t2206 (one among\n14 hits in the above grep), for example, look like this:\n\n  ! git status --porcelain | grep \"^.*$\" &&\n\nwhich violates \"do not hide exit status of git behind a pipe\" rule,\nin addition to have a strange looking leading ! negation.\n\nWill queue.\n\n"},{"id":"558564","messageId":"DMWTDHJGGUD8.2ZZHA8YHM7EU4@gmail.com","threadId":"66851","inReplyTo":"xmqqcxs4n4k0.fsf@gitster.g","subject":"Re: [PATCH] t: use test_must_fail instead of NOT operator","fromName":"Hardik Kumar","fromEmail":"hardikxk@gmail.com","sentAt":"2026-11-16T17:33:43Z","receivedAt":"2026-11-16T17:33:43Z","isPatch":true,"sender":{"key":"hardikxk@gmail.com","avatar":"https://avatars.githubusercontent.com/u/183656738?v=4"},"body":"On Mon Nov 16, 2026 at 9:37 PM IST, Junio C Hamano wrote:\n> All of them look sensible, but I am curious why you chose only\n> these, among 14 hits in\n>\n>     $ git grep -l '^[ \t]*! git ' t/\n>\n> I suspect that it is because these are ...\n>\n>> -\t! git clone -c http.proxy=localhost/path https://example.com/repo.git 2>err && {\n>> -\t! git clone -c http.proxy=socks4://127.0.0.1/path https://example.com/repo.git 2>err && {\n>> -\t! git bisect run ./fail.sh 2>err &&\n>> -\t! git bisect run ./fail.sh 2>err &&\n>\n> ... simple cases in which the use of leading ! negation is the only\n> issue with them, and if that is the reasoning, I think that is\n> sensible.  Contrasting these, many of the hits in t2206 (one among\n> 14 hits in the above grep), for example, look like this:\n>\n>   ! git status --porcelain | grep \"^.*$\" &&\n>\n> which violates \"do not hide exit status of git behind a pipe\" rule,\n> in addition to have a strange looking leading ! negation.\n\nYes, I should've mentioned the reason for not replacing the other\ninstances in the patch reply. I just trying keeping the patch to these\nspecific cases as they were the obvious standouts.\n\nThanks.\n\n"}]}