t0000-t3999: detect and signal failure within loop
Failures within `for` and `while` loops can go unnoticed if not detected and signaled manually since the loop itself does not abort when a contained command fails, nor will a failure necessarily be detected when the loop finishes since the loop returns the exit code of the last command it ran on the final iteration, which may not be the command which failed. Therefore, detect and signal failures manually within loops using the idiom `|| return 1` (or `|| exit 1` within subshells). Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
efe26b9ee0
commit
db5875aa9f
@ -19,9 +19,9 @@ test_expect_success 'setup' '
|
||||
printf "a" >>refname &&
|
||||
for j in $(test_seq 1 $i)
|
||||
do
|
||||
printf "a*" >>refglob.$i
|
||||
printf "a*" >>refglob.$i || return 1
|
||||
done &&
|
||||
echo b >>refglob.$i
|
||||
echo b >>refglob.$i || return 1
|
||||
done &&
|
||||
test_commit test $(cat refname).t "" $(cat refname).t
|
||||
'
|
||||
|
@ -13,7 +13,7 @@ test_expect_success "setup" '
|
||||
do
|
||||
printf "start\ncreate refs/heads/%d PRE\ncommit\n" $i &&
|
||||
printf "start\nupdate refs/heads/%d POST PRE\ncommit\n" $i &&
|
||||
printf "start\ndelete refs/heads/%d POST\ncommit\n" $i
|
||||
printf "start\ndelete refs/heads/%d POST\ncommit\n" $i || return 1
|
||||
done >instructions
|
||||
'
|
||||
|
||||
@ -22,7 +22,7 @@ test_perf "update-ref" '
|
||||
do
|
||||
git update-ref refs/heads/branch PRE &&
|
||||
git update-ref refs/heads/branch POST PRE &&
|
||||
git update-ref -d refs/heads/branch
|
||||
git update-ref -d refs/heads/branch || return 1
|
||||
done
|
||||
'
|
||||
|
||||
|
@ -15,7 +15,7 @@ test_expect_success "setup $n bad commits" '
|
||||
echo "committer C <c@example.com> 1234567890 +0000" &&
|
||||
echo "data <<EOF" &&
|
||||
echo "$i.Q." &&
|
||||
echo "EOF"
|
||||
echo "EOF" || return 1
|
||||
done | q_to_nul | git fast-import
|
||||
'
|
||||
|
||||
|
@ -22,7 +22,7 @@ test_expect_success 'setup rebasing on top of a lot of changes' '
|
||||
git add unrelated-file$i &&
|
||||
test_tick &&
|
||||
git commit -m commit$i-reverse unrelated-file$i ||
|
||||
break
|
||||
return 1
|
||||
done &&
|
||||
git checkout to-rebase &&
|
||||
test_commit our-patch interesting-file
|
||||
|
@ -22,7 +22,7 @@ test_expect_success 'set up thread-counting tests' '
|
||||
while test $t -gt 0
|
||||
do
|
||||
threads="$t $threads" &&
|
||||
t=$((t / 2))
|
||||
t=$((t / 2)) || return 1
|
||||
done
|
||||
'
|
||||
|
||||
|
@ -130,7 +130,7 @@ test_expect_success 'generate lots of packs' '
|
||||
echo "data <<EOF" &&
|
||||
echo "blob $i" &&
|
||||
echo "EOF" &&
|
||||
echo "checkpoint"
|
||||
echo "checkpoint" || return 1
|
||||
done |
|
||||
git -c fastimport.unpackLimit=0 fast-import
|
||||
'
|
||||
|
@ -119,10 +119,10 @@ test_expect_success "one time repo setup" '
|
||||
fi &&
|
||||
|
||||
mkdir 1_file 10_files 100_files 1000_files 10000_files &&
|
||||
for i in $(test_seq 1 10); do touch 10_files/$i; done &&
|
||||
for i in $(test_seq 1 100); do touch 100_files/$i; done &&
|
||||
for i in $(test_seq 1 1000); do touch 1000_files/$i; done &&
|
||||
for i in $(test_seq 1 10000); do touch 10000_files/$i; done &&
|
||||
for i in $(test_seq 1 10); do touch 10_files/$i || return 1; done &&
|
||||
for i in $(test_seq 1 100); do touch 100_files/$i || return 1; done &&
|
||||
for i in $(test_seq 1 1000); do touch 1000_files/$i || return 1; done &&
|
||||
for i in $(test_seq 1 10000); do touch 10000_files/$i || return 1; done &&
|
||||
git add 1_file 10_files 100_files 1000_files 10000_files &&
|
||||
git commit -qm "Add files" &&
|
||||
|
||||
|
Reference in New Issue
Block a user