Thread View: linux.kernel.git
3 messages
3 total messages
Started by Hardik Kumar
Sun, 15 Nov 2026 18:15
[PATCH] t: use test_must_fail instead of NOT operator
Author: Hardik Kumar
Date: Sun, 15 Nov 2026 18:15
Date: Sun, 15 Nov 2026 18:15
99 lines
15169 bytes
15169 bytes
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
Re: [PATCH] t: use test_must_fail instead of NOT operator
Author: Junio C Hamano
Date: Mon, 16 Nov 2026 16:07
Date: Mon, 16 Nov 2026 16:07
42 lines
14060 bytes
14060 bytes
Hardik Kumar <hardikxk@gmail.com> writes:
> 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(-)
All of them look sensible, but I am curious why you chose only
these, among 14 hits in
$ git grep -l '^[ ]*! git ' t/
I suspect that it is because these are ...
> - ! git clone -c http.proxy=localhost/path https://example.com/repo.git 2>err && {
> - ! git clone -c http.proxy=socks4://127.0.0.1/path https://example.com/repo.git 2>err && {
> - ! git bisect run ./fail.sh 2>err &&
> - ! git bisect run ./fail.sh 2>err &&
... simple cases in which the use of leading ! negation is the only
issue with them, and if that is the reasoning, I think that is
sensible. Contrasting these, many of the hits in t2206 (one among
14 hits in the above grep), for example, look like this:
! git status --porcelain | grep "^.*$" &&
which violates "do not hide exit status of git behind a pipe" rule,
in addition to have a strange looking leading ! negation.
Will queue.
Re: [PATCH] t: use test_must_fail instead of NOT operator
Author: "Hardik Kumar"
Date: Mon, 16 Nov 2026 17:33
Date: Mon, 16 Nov 2026 17:33
31 lines
11732 bytes
11732 bytes
On Mon Nov 16, 2026 at 9:37 PM IST, Junio C Hamano wrote:
> All of them look sensible, but I am curious why you chose only
> these, among 14 hits in
>
> $ git grep -l '^[ ]*! git ' t/
>
> I suspect that it is because these are ...
>
>> - ! git clone -c http.proxy=localhost/path https://example.com/repo.git 2>err && {
>> - ! git clone -c http.proxy=socks4://127.0.0.1/path https://example.com/repo.git 2>err && {
>> - ! git bisect run ./fail.sh 2>err &&
>> - ! git bisect run ./fail.sh 2>err &&
>
> ... simple cases in which the use of leading ! negation is the only
> issue with them, and if that is the reasoning, I think that is
> sensible. Contrasting these, many of the hits in t2206 (one among
> 14 hits in the above grep), for example, look like this:
>
> ! git status --porcelain | grep "^.*$" &&
>
> which violates "do not hide exit status of git behind a pipe" rule,
> in addition to have a strange looking leading ! negation.
Yes, I should've mentioned the reason for not replacing the other
instances in the patch reply. I just trying keeping the patch to these
specific cases as they were the obvious standouts.
Thanks.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads