t: prepare conditional test execution for `set -e`
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>
Patrick Steinhardt committed
Apr 21, 2026 at 09:34 UTC
0c6600cdc751e8c018e6baddc0edce070c7c3f55
2 files changed
+20
-16
t/t4032-diff-inter-hunk-context.sh
+7
-5
@@ -40,11 +40,13 @@ t() {
40
test $(git $cmd $file | grep '^@@ ' | wc -l) = $hunks
41
"
42
43
- test -f $expected &&
44
- test_expect_success "$label: check output" "
45
- git $cmd $file | grep -v '^index ' >actual &&
46
- test_cmp $expected actual
47
- "
43
+ if test -f $expected
44
+ then
45
+ test_expect_success "$label: check output" "
46
+ git $cmd $file | grep -v '^index ' >actual &&
47
+ test_cmp $expected actual
48
+ "
49
+ fi
50
}
51
52
cat <<EOF >expected.f1.0.1 || exit 1
t/t7450-bad-git-dotfiles.sh
+13
-11
@@ -220,17 +220,19 @@ check_dotx_symlink () {
220
)
221
'
222
223
- test -n "$refuse_index" &&
224
- test_expect_success "refuse to load symlinked $name into index ($type)" '
225
- test_must_fail \
226
- git -C $dir \
227
- -c core.protectntfs \
228
- -c core.protecthfs \
229
- read-tree $tree 2>err &&
230
- grep "invalid path.*$name" err &&
231
- git -C $dir ls-files -s >out &&
232
- test_must_be_empty out
233
- '
223
+ if test -n "$refuse_index"
224
+ then
225
+ test_expect_success "refuse to load symlinked $name into index ($type)" '
226
+ test_must_fail \
227
+ git -C $dir \
228
+ -c core.protectntfs \
229
+ -c core.protecthfs \
230
+ read-tree $tree 2>err &&
231
+ grep "invalid path.*$name" err &&
232
+ git -C $dir ls-files -s >out &&
233
+ test_must_be_empty out
234
+ '
235
+ fi
236
}
237
238
check_dotx_symlink gitmodules vanilla .gitmodules