Skip to content

Commit 56758a2

Browse files
pks-tgitster
authored andcommitted
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>
1 parent 7f30e62 commit 56758a2

2 files changed

Lines changed: 20 additions & 16 deletions

File tree

t/t4032-diff-inter-hunk-context.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ t() {
4040
test $(git $cmd $file | grep '^@@ ' | wc -l) = $hunks
4141
"
4242

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
4850
}
4951

5052
cat <<EOF >expected.f1.0.1 || exit 1

t/t7450-bad-git-dotfiles.sh

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,19 @@ check_dotx_symlink () {
220220
)
221221
'
222222

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
234236
}
235237

236238
check_dotx_symlink gitmodules vanilla .gitmodules

0 commit comments

Comments
 (0)