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:
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" &&
|
||||
|
||||
|
@ -200,7 +200,7 @@ test_expect_success 'setup' '
|
||||
do
|
||||
: >$dir/not-ignored &&
|
||||
: >$dir/ignored-and-untracked &&
|
||||
: >$dir/ignored-but-in-index
|
||||
: >$dir/ignored-but-in-index || return 1
|
||||
done &&
|
||||
git add -f ignored-but-in-index a/ignored-but-in-index &&
|
||||
cat <<-\EOF >a/.gitignore &&
|
||||
|
@ -220,7 +220,7 @@ test_expect_success 'grow / shrink' '
|
||||
for n in $(test_seq 51)
|
||||
do
|
||||
echo put key$n value$n >> in &&
|
||||
echo NULL >> expect
|
||||
echo NULL >> expect || return 1
|
||||
done &&
|
||||
echo size >> in &&
|
||||
echo 64 51 >> expect &&
|
||||
@ -231,7 +231,7 @@ test_expect_success 'grow / shrink' '
|
||||
for n in $(test_seq 12)
|
||||
do
|
||||
echo remove key$n >> in &&
|
||||
echo value$n >> expect
|
||||
echo value$n >> expect || return 1
|
||||
done &&
|
||||
echo size >> in &&
|
||||
echo 256 40 >> expect &&
|
||||
|
@ -285,7 +285,7 @@ test_expect_success 'required filter with absent smudge field' '
|
||||
test_expect_success 'filtering large input to small output should use little memory' '
|
||||
test_config filter.devnull.clean "cat >/dev/null" &&
|
||||
test_config filter.devnull.required true &&
|
||||
for i in $(test_seq 1 30); do printf "%1048576d" 1; done >30MB &&
|
||||
for i in $(test_seq 1 30); do printf "%1048576d" 1 || return 1; done >30MB &&
|
||||
echo "30MB filter=devnull" >.gitattributes &&
|
||||
GIT_MMAP_LIMIT=1m GIT_ALLOC_LIMIT=1m git add 30MB
|
||||
'
|
||||
@ -303,7 +303,7 @@ test_expect_success 'filter that does not read is fine' '
|
||||
test_expect_success EXPENSIVE 'filter large file' '
|
||||
test_config filter.largefile.smudge cat &&
|
||||
test_config filter.largefile.clean cat &&
|
||||
for i in $(test_seq 1 2048); do printf "%1048576d" 1; done >2GB &&
|
||||
for i in $(test_seq 1 2048); do printf "%1048576d" 1 || return 1; done >2GB &&
|
||||
echo "2GB filter=largefile" >.gitattributes &&
|
||||
git add 2GB 2>err &&
|
||||
test_must_be_empty err &&
|
||||
@ -643,7 +643,7 @@ test_expect_success PERL 'required process filter should process multiple packet
|
||||
for FILE in "$TEST_ROOT"/*.file
|
||||
do
|
||||
cp "$FILE" . &&
|
||||
rot13.sh <"$FILE" >"$FILE.rot13"
|
||||
rot13.sh <"$FILE" >"$FILE.rot13" || return 1
|
||||
done &&
|
||||
|
||||
echo "*.file filter=protocol" >.gitattributes &&
|
||||
@ -682,7 +682,7 @@ test_expect_success PERL 'required process filter should process multiple packet
|
||||
|
||||
for FILE in *.file
|
||||
do
|
||||
test_cmp_committed_rot13 "$TEST_ROOT/$FILE" $FILE
|
||||
test_cmp_committed_rot13 "$TEST_ROOT/$FILE" $FILE || return 1
|
||||
done
|
||||
)
|
||||
'
|
||||
|
@ -84,7 +84,7 @@ test_expect_success 'get bloom filter for commit with 10 changes' '
|
||||
mkdir smallDir &&
|
||||
for i in $(test_seq 0 9)
|
||||
do
|
||||
echo $i >smallDir/$i
|
||||
echo $i >smallDir/$i || return 1
|
||||
done &&
|
||||
git add smallDir &&
|
||||
git commit -m "commit with 10 changes" &&
|
||||
@ -102,7 +102,7 @@ test_expect_success EXPENSIVE 'get bloom filter for commit with 513 changes' '
|
||||
mkdir bigDir &&
|
||||
for i in $(test_seq 0 511)
|
||||
do
|
||||
echo $i >bigDir/$i
|
||||
echo $i >bigDir/$i || return 1
|
||||
done &&
|
||||
git add bigDir &&
|
||||
git commit -m "commit with 513 changes" &&
|
||||
|
@ -469,7 +469,7 @@ test_expect_success 'rev-list dies for missing objects on cmd line' '
|
||||
git -C repo rev-list --ignore-missing --objects \
|
||||
--exclude-promisor-objects "$OBJ" &&
|
||||
git -C repo rev-list --ignore-missing --objects-edge-aggressive \
|
||||
--exclude-promisor-objects "$OBJ"
|
||||
--exclude-promisor-objects "$OBJ" || return 1
|
||||
done
|
||||
'
|
||||
|
||||
|
@ -105,7 +105,7 @@ test_expect_success 'packsize limit' '
|
||||
count=0 &&
|
||||
for pi in .git/objects/pack/pack-*.idx
|
||||
do
|
||||
test_path_is_file "$pi" && count=$(( $count + 1 ))
|
||||
test_path_is_file "$pi" && count=$(( $count + 1 )) || return 1
|
||||
done &&
|
||||
test $count = 2 &&
|
||||
|
||||
@ -118,7 +118,7 @@ test_expect_success 'packsize limit' '
|
||||
|
||||
for pi in .git/objects/pack/pack-*.idx
|
||||
do
|
||||
git show-index <"$pi"
|
||||
git show-index <"$pi" || return 1
|
||||
done |
|
||||
sed -e "s/^[0-9]* \([0-9a-f]*\) .*/\1/" |
|
||||
sort >actual &&
|
||||
|
@ -586,7 +586,7 @@ test_expect_success 'pattern-checks: contained glob characters' '
|
||||
!/*/
|
||||
something$c-else/
|
||||
EOF
|
||||
check_read_tree_errors repo "a" "disabling cone pattern matching"
|
||||
check_read_tree_errors repo "a" "disabling cone pattern matching" || return 1
|
||||
done
|
||||
'
|
||||
|
||||
|
@ -718,7 +718,7 @@ test_expect_success bool '
|
||||
for i in 1 2 3 4
|
||||
do
|
||||
git config --bool --get bool.true$i >>result &&
|
||||
git config --bool --get bool.false$i >>result
|
||||
git config --bool --get bool.false$i >>result || return 1
|
||||
done &&
|
||||
test_cmp expect result'
|
||||
|
||||
|
@ -1368,7 +1368,7 @@ test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction creating branches
|
||||
(
|
||||
for i in $(test_seq 33)
|
||||
do
|
||||
echo "create refs/heads/$i HEAD"
|
||||
echo "create refs/heads/$i HEAD" || exit 1
|
||||
done >large_input &&
|
||||
run_with_limited_open_files git update-ref --stdin <large_input &&
|
||||
git rev-parse --verify -q refs/heads/33
|
||||
@ -1379,7 +1379,7 @@ test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction deleting branches
|
||||
(
|
||||
for i in $(test_seq 33)
|
||||
do
|
||||
echo "delete refs/heads/$i HEAD"
|
||||
echo "delete refs/heads/$i HEAD" || exit 1
|
||||
done >large_input &&
|
||||
run_with_limited_open_files git update-ref --stdin <large_input &&
|
||||
test_must_fail git rev-parse --verify -q refs/heads/33
|
||||
|
@ -123,14 +123,14 @@ test_expect_success 'show-ref -d' '
|
||||
test_expect_success 'show-ref --heads, --tags, --head, pattern' '
|
||||
for branch in B main side
|
||||
do
|
||||
echo $(git rev-parse refs/heads/$branch) refs/heads/$branch
|
||||
echo $(git rev-parse refs/heads/$branch) refs/heads/$branch || return 1
|
||||
done >expect.heads &&
|
||||
git show-ref --heads >actual &&
|
||||
test_cmp expect.heads actual &&
|
||||
|
||||
for tag in A B C
|
||||
do
|
||||
echo $(git rev-parse refs/tags/$tag) refs/tags/$tag
|
||||
echo $(git rev-parse refs/tags/$tag) refs/tags/$tag || return 1
|
||||
done >expect.tags &&
|
||||
git show-ref --tags >actual &&
|
||||
test_cmp expect.tags actual &&
|
||||
|
@ -349,12 +349,12 @@ test_expect_success SHA1 'parsing reverse reflogs at BUFSIZ boundaries' '
|
||||
printf "$zf%02d $zf%02d %s\t" $i $(($i+1)) "$ident" &&
|
||||
if test $i = 75; then
|
||||
for j in $(test_seq 1 89); do
|
||||
printf X
|
||||
printf X || return 1
|
||||
done
|
||||
else
|
||||
printf X
|
||||
fi &&
|
||||
printf "\n"
|
||||
printf "\n" || return 1
|
||||
done >.git/logs/refs/heads/reflogskip &&
|
||||
git rev-parse reflogskip@{73} >actual &&
|
||||
echo ${zf}03 >expect &&
|
||||
|
@ -381,7 +381,7 @@ test_expect_success 'ambiguous commits are printed by type first, then hash orde
|
||||
do
|
||||
grep $type objects >$type.objects &&
|
||||
sort $type.objects >$type.objects.sorted &&
|
||||
test_cmp $type.objects.sorted $type.objects
|
||||
test_cmp $type.objects.sorted $type.objects || return 1
|
||||
done
|
||||
'
|
||||
|
||||
|
@ -57,7 +57,7 @@ test_expect_success 'checkout all stage 0 to temporary files' '
|
||||
test $(grep $f actual | cut "-d " -f2) = $f &&
|
||||
p=$(grep $f actual | cut "-d " -f1) &&
|
||||
test -f $p &&
|
||||
test $(cat $p) = tree1$f
|
||||
test $(cat $p) = tree1$f || return 1
|
||||
done
|
||||
'
|
||||
|
||||
@ -85,7 +85,7 @@ test_expect_success 'checkout all stage 2 to temporary files' '
|
||||
test $(grep $f actual | cut "-d " -f2) = $f &&
|
||||
p=$(grep $f actual | cut "-d " -f1) &&
|
||||
test -f $p &&
|
||||
test $(cat $p) = tree2$f
|
||||
test $(cat $p) = tree2$f || return 1
|
||||
done
|
||||
'
|
||||
|
||||
|
@ -49,14 +49,14 @@ test_expect_success '"checkout -" detaches again' '
|
||||
test_expect_success 'more switches' '
|
||||
for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
|
||||
do
|
||||
git checkout -b branch$i
|
||||
git checkout -b branch$i || return 1
|
||||
done
|
||||
'
|
||||
|
||||
more_switches () {
|
||||
for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
|
||||
do
|
||||
git checkout branch$i
|
||||
git checkout branch$i || return 1
|
||||
done
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ test_expect_success 'add -u resolves unmerged paths' '
|
||||
do
|
||||
echo "100644 $one 1 $path" &&
|
||||
echo "100644 $two 2 $path" &&
|
||||
echo "100644 $three 3 $path"
|
||||
echo "100644 $three 3 $path" || return 1
|
||||
done &&
|
||||
echo "100644 $one 1 path3" &&
|
||||
echo "100644 $one 1 path4" &&
|
||||
|
@ -116,7 +116,7 @@ test_expect_success 'cache-tree does not ignore dir that has i-t-a entries' '
|
||||
mkdir 2 &&
|
||||
for f in 1 2/1 2/2 3
|
||||
do
|
||||
echo "$f" >"$f"
|
||||
echo "$f" >"$f" || return 1
|
||||
done &&
|
||||
git add 1 2/2 3 &&
|
||||
git add -N 2/1 &&
|
||||
|
@ -9,7 +9,7 @@ test_expect_success 'setup' '
|
||||
for i in $(test_seq 1 10)
|
||||
do
|
||||
git checkout -b branch$i initial &&
|
||||
test_commit --no-tag branch$i
|
||||
test_commit --no-tag branch$i || return 1
|
||||
done &&
|
||||
git for-each-ref \
|
||||
--sort=version:refname \
|
||||
@ -49,7 +49,7 @@ test_expect_success 'show-branch with more than 8 branches' '
|
||||
test_expect_success 'show-branch with showbranch.default' '
|
||||
for branch in $(cat branches.sorted)
|
||||
do
|
||||
test_config showbranch.default $branch --add
|
||||
test_config showbranch.default $branch --add || return 1
|
||||
done &&
|
||||
git show-branch >actual &&
|
||||
test_cmp expect actual
|
||||
@ -124,7 +124,7 @@ test_expect_success 'show branch --merge-base with one argument' '
|
||||
do
|
||||
git rev-parse $branch >expect &&
|
||||
git show-branch --merge-base $branch >actual &&
|
||||
test_cmp expect actual
|
||||
test_cmp expect actual || return 1
|
||||
done
|
||||
'
|
||||
|
||||
@ -133,7 +133,7 @@ test_expect_success 'show branch --merge-base with two arguments' '
|
||||
do
|
||||
git rev-parse initial >expect &&
|
||||
git show-branch --merge-base initial $branch >actual &&
|
||||
test_cmp expect actual
|
||||
test_cmp expect actual || return 1
|
||||
done
|
||||
'
|
||||
|
||||
|
@ -30,7 +30,7 @@ verify_notes () {
|
||||
while [ $i -gt 0 ]; do
|
||||
echo " commit #$i" &&
|
||||
echo " note for commit #$i" &&
|
||||
i=$(($i-1));
|
||||
i=$(($i-1)) || return 1
|
||||
done > expect &&
|
||||
test_cmp expect output
|
||||
}
|
||||
@ -42,7 +42,7 @@ test_expect_success "setup: create $number_of_commits commits" '
|
||||
while [ $nr -lt $number_of_commits ]; do
|
||||
nr=$(($nr+1)) &&
|
||||
test_tick &&
|
||||
cat <<INPUT_END
|
||||
cat <<INPUT_END || return 1
|
||||
commit refs/heads/main
|
||||
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
|
||||
data <<COMMIT
|
||||
@ -178,7 +178,7 @@ verify_concatenated_notes () {
|
||||
echo " first note for commit #$i" &&
|
||||
echo " " &&
|
||||
echo " second note for commit #$i" &&
|
||||
i=$(($i-1));
|
||||
i=$(($i-1)) || return 1
|
||||
done > expect &&
|
||||
test_cmp expect output
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ test_expect_success 'many notes created correctly with git-notes' '
|
||||
do
|
||||
echo " commit #$i" &&
|
||||
echo " note #$i" &&
|
||||
i=$(($i - 1));
|
||||
i=$(($i - 1)) || return 1
|
||||
done > expect &&
|
||||
test_cmp expect output
|
||||
'
|
||||
@ -106,7 +106,7 @@ test_expect_success 'most notes deleted correctly with git-notes' '
|
||||
do
|
||||
echo " commit #$i" &&
|
||||
echo " note #$i" &&
|
||||
i=$(($i - 1));
|
||||
i=$(($i - 1)) || return 1
|
||||
done > expect &&
|
||||
test_cmp expect output
|
||||
'
|
||||
|
@ -826,7 +826,7 @@ test_expect_success 'always cherry-pick with --no-ff' '
|
||||
do
|
||||
test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
|
||||
git diff HEAD~$p original-no-ff-branch~$p > out &&
|
||||
test_must_be_empty out
|
||||
test_must_be_empty out || return 1
|
||||
done &&
|
||||
test_cmp_rev HEAD~3 original-no-ff-branch~3 &&
|
||||
git diff HEAD~3 original-no-ff-branch~3 > out &&
|
||||
@ -1341,7 +1341,7 @@ test_expect_success 'rebase --continue removes CHERRY_PICK_HEAD' '
|
||||
test_seq 5 | sed "s/$double/&&/" >seq &&
|
||||
git add seq &&
|
||||
test_tick &&
|
||||
git commit -m seq-$double
|
||||
git commit -m seq-$double || return 1
|
||||
done &&
|
||||
git tag seq-onto &&
|
||||
git reset --hard HEAD~2 &&
|
||||
|
@ -19,7 +19,7 @@ test_expect_success setup '
|
||||
|
||||
for l in a b c d e f g h i j k l m n o
|
||||
do
|
||||
echo $l$l$l$l$l$l$l$l$l
|
||||
echo $l$l$l$l$l$l$l$l$l || return 1
|
||||
done >oops &&
|
||||
|
||||
test_tick &&
|
||||
|
@ -29,7 +29,7 @@ test_expect_success setup '
|
||||
git add file1 &&
|
||||
test_tick &&
|
||||
git commit -m "$val" &&
|
||||
git tag $val
|
||||
git tag $val || return 1
|
||||
done
|
||||
'
|
||||
|
||||
|
@ -143,7 +143,7 @@ test_expect_success 'git add with filemode=0, symlinks=0, and unmerged entries'
|
||||
do
|
||||
echo $s > stage$s &&
|
||||
echo "100755 $(git hash-object -w stage$s) $s file" &&
|
||||
echo "120000 $(printf $s | git hash-object -w -t blob --stdin) $s symlink"
|
||||
echo "120000 $(printf $s | git hash-object -w -t blob --stdin) $s symlink" || return 1
|
||||
done | git update-index --index-info &&
|
||||
git config core.filemode 0 &&
|
||||
git config core.symlinks 0 &&
|
||||
|
@ -70,7 +70,7 @@ test_crlf_subject_body_and_contents() {
|
||||
for ref in ${LIB_CRLF_BRANCHES}
|
||||
do
|
||||
cat .crlf-${file}-\"\${ref}\".txt >>expect &&
|
||||
printf \"\n\" >>expect
|
||||
printf \"\n\" >>expect || return 1
|
||||
done &&
|
||||
git $command_and_args --format=\"%${atom}\" >actual &&
|
||||
test_cmp expect actual
|
||||
@ -90,7 +90,7 @@ test_expect_success 'branch: --verbose works with messages using CRLF' '
|
||||
do
|
||||
printf " " >>expect &&
|
||||
cat .crlf-subject-${branch}.txt >>expect &&
|
||||
printf "\n" >>expect
|
||||
printf "\n" >>expect || return 1
|
||||
done &&
|
||||
git branch -v >tmp &&
|
||||
# Remove first two columns, and the line for the currently checked out branch
|
||||
|
Loading…
Reference in New Issue
Block a user