]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t: prepare conditional test execution for `set -e`
authorPatrick Steinhardt <ps@pks.im>
Tue, 21 Apr 2026 07:34:18 +0000 (09:34 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 22 Apr 2026 22:53:36 +0000 (15:53 -0700)
We have some test in our test suite where we use the pattern of
`test ... && test_expect_succeess` to conditionally execute a test. The
problem is that when we decide to not execute the test, we'll indeed
skip the test, but the overall statement will also be unsuccessful. This
will become a problem once we enable `set -e`.

Prepare for this future by turning this into a proper conditional, which
is also a bit easier to read overall.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t4032-diff-inter-hunk-context.sh
t/t7450-bad-git-dotfiles.sh

index c98eb6abb2e3e5028c2fe20581a57120d70474f2..2d216fb70f982b59fb7a1bbf956ea5d2cf92da34 100755 (executable)
@@ -40,11 +40,13 @@ t() {
                test $(git $cmd $file | grep '^@@ ' | wc -l) = $hunks
        "
 
-       test -f $expected &&
-       test_expect_success "$label: check output" "
-               git $cmd $file | grep -v '^index ' >actual &&
-               test_cmp $expected actual
-       "
+       if test -f $expected
+       then
+               test_expect_success "$label: check output" "
+                       git $cmd $file | grep -v '^index ' >actual &&
+                       test_cmp $expected actual
+               "
+       fi
 }
 
 cat <<EOF >expected.f1.0.1 || exit 1
index f512eed278c46b60f824be2865a7a56859188c9c..8cc86522b27d9bb1bca6de0c4cc0e1f7abdf7e17 100755 (executable)
@@ -220,17 +220,19 @@ check_dotx_symlink () {
                )
        '
 
-       test -n "$refuse_index" &&
-       test_expect_success "refuse to load symlinked $name into index ($type)" '
-               test_must_fail \
-                       git -C $dir \
-                           -c core.protectntfs \
-                           -c core.protecthfs \
-                           read-tree $tree 2>err &&
-               grep "invalid path.*$name" err &&
-               git -C $dir ls-files -s >out &&
-               test_must_be_empty out
-       '
+       if test -n "$refuse_index"
+       then
+               test_expect_success "refuse to load symlinked $name into index ($type)" '
+                       test_must_fail \
+                               git -C $dir \
+                                   -c core.protectntfs \
+                                   -c core.protecthfs \
+                                   read-tree $tree 2>err &&
+                       grep "invalid path.*$name" err &&
+                       git -C $dir ls-files -s >out &&
+                       test_must_be_empty out
+               '
+       fi
 }
 
 check_dotx_symlink gitmodules vanilla .gitmodules