t6000-t9999: 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:
Eric Sunshine 2021-12-09 00:11:15 -05:00 коммит произвёл Junio C Hamano
Родитель d0fd993137
Коммит 0c51d6b4ae
32 изменённых файлов: 65 добавлений и 65 удалений

Просмотреть файл

@ -12,7 +12,7 @@ test_expect_success 'creating page w/ >500 revisions' '
for i in $(test_seq 501)
do
echo "creating revision $i" &&
wiki_editpage foo "revision $i<br/>" true
wiki_editpage foo "revision $i<br/>" true || return 1
done
'

Просмотреть файл

@ -161,7 +161,7 @@ test_expect_success 'blame huge graft' '
GIT_AUTHOR_NAME=$i$j GIT_AUTHOR_EMAIL=$i$j@test.git \
git commit -a -m "$i$j" &&
commit=$(git rev-parse --verify HEAD) &&
graft="$graft$commit "
graft="$graft$commit " || return 1
done
done &&
printf "%s " $graft >.git/info/grafts &&

Просмотреть файл

@ -8,7 +8,7 @@ test_expect_success 'setup' '
for n in 1 2 3 4 5 ; do
echo $n > a &&
git add a &&
git commit -m "$n"
git commit -m "$n" || return 1
done
'

Просмотреть файл

@ -124,7 +124,7 @@ test_expect_success 'dodecapus' '
git checkout -b root$i five &&
test_commit $i &&
roots="$roots root$i" ||
return
return 1
done &&
git checkout main &&
test_tick &&
@ -143,7 +143,7 @@ test_expect_success 'ancestors with the same commit time' '
test_tick_keep=$test_tick &&
for i in 1 2 3 4 5 6 7 8; do
test_tick=$test_tick_keep &&
test_commit t$i
test_commit t$i || return 1
done &&
git rev-list t1^! --not t$i >result &&
test_must_be_empty result

Просмотреть файл

@ -32,7 +32,7 @@ test_expect_success 'setup' '
test_tick &&
git commit --allow-empty -m "$i" &&
commit=$(git rev-parse --verify HEAD) &&
printf "$commit " >>.git/info/grafts
printf "$commit " >>.git/info/grafts || return 1
done
'

Просмотреть файл

@ -18,7 +18,7 @@ test_expect_success 'setup r1' '
do
echo "This is file: $n" > r1/file.$n &&
git -C r1 add file.$n &&
git -C r1 commit -m "$n"
git -C r1 commit -m "$n" || return 1
done
'
@ -75,7 +75,7 @@ test_expect_success 'setup r2' '
do
printf "%"$n"s" X > r2/large.$n &&
git -C r2 add large.$n &&
git -C r2 commit -m "$n"
git -C r2 commit -m "$n" || return 1
done
'
@ -248,7 +248,7 @@ test_expect_success 'setup r3' '
echo "This is file: $n" > r3/$n &&
git -C r3 add $n &&
echo "This is file: dir1/$n" > r3/dir1/$n &&
git -C r3 add dir1/$n
git -C r3 add dir1/$n || return 1
done &&
git -C r3 commit -m "sparse" &&
echo dir1/ >pattern1 &&
@ -672,7 +672,7 @@ test_expect_success 'rev-list W/ --missing=print' '
for id in `cat expected | sed "s|..|&/|"`
do
rm r1/.git/objects/$id
rm r1/.git/objects/$id || return 1
done &&
git -C r1 rev-list --quiet --missing=print --objects HEAD >revs &&

Просмотреть файл

@ -262,7 +262,7 @@ test_expect_success 'name-rev --all' '
>expect.unsorted &&
for rev in $(git rev-list --all)
do
git name-rev $rev >>expect.unsorted
git name-rev $rev >>expect.unsorted || return 1
done &&
sort <expect.unsorted >expect &&
git name-rev --all >actual.unsorted &&
@ -275,7 +275,7 @@ test_expect_success 'name-rev --stdin' '
for rev in $(git rev-list --all)
do
name=$(git name-rev --name-only $rev) &&
echo "$rev ($name)" >>expect.unsorted
echo "$rev ($name)" >>expect.unsorted || return 1
done &&
sort <expect.unsorted >expect &&
git rev-list --all | git name-rev --stdin >actual.unsorted &&
@ -395,7 +395,7 @@ EOF" &&
then
echo "from refs/heads/main^0"
fi &&
i=$(($i + 1))
i=$(($i + 1)) || return 1
done | git fast-import &&
git checkout main &&
git tag far-far-away HEAD^ &&

Просмотреть файл

@ -11,7 +11,7 @@ test_expect_success 'setup' '
fi &&
: >$p &&
git add $p &&
git commit -m $p
git commit -m $p || return 1
done &&
git log --oneline --format=%s >actual &&
cat <<EOF >expect &&

Просмотреть файл

@ -519,7 +519,7 @@ test_expect_success 'merge-msg lots of commits' '
while test $i -gt 9
do
echo " $i" &&
i=$(($i-1))
i=$(($i-1)) || return 1
done &&
echo " ..."
} >expected &&

Просмотреть файл

@ -1338,7 +1338,7 @@ test_expect_success ':remotename and :remoteref' '
echo "${pair#*=}" >expect &&
git for-each-ref --format="${pair%=*}" \
refs/heads/main >actual &&
test_cmp expect actual
test_cmp expect actual || exit 1
done &&
git branch push-simple &&
git config branch.push-simple.pushRemote from &&

Просмотреть файл

@ -37,18 +37,18 @@ test_rename() {
test_might_fail git branch -D test$n &&
git reset --hard initial &&
for i in $(count $n); do
make_text $i initial initial >$i
make_text $i initial initial >$i || return 1
done &&
git add . &&
git commit -m add=$n &&
for i in $(count $n); do
make_text $i changed initial >$i
make_text $i changed initial >$i || return 1
done &&
git commit -a -m change=$n &&
git checkout -b test$n HEAD^ &&
for i in $(count $n); do
git rm $i &&
make_text $i initial changed >$i.moved
make_text $i initial changed >$i.moved || return 1
done &&
git add . &&
git commit -m change+rename=$n &&
@ -79,7 +79,7 @@ test_expect_success 'setup large simple rename' '
git reset --hard initial &&
for i in $(count 200); do
make_text foo bar baz >$i
make_text foo bar baz >$i || return 1
done &&
git add . &&
git commit -m create-files &&

Просмотреть файл

@ -706,7 +706,7 @@ test_expect_success 'merge-recursive remembers the names of all base trees' '
# more trees than static slots used by oid_to_hex()
for commit in $c0 $c2 $c4 $c5 $c6 $c7
do
git rev-parse "$commit^{tree}"
git rev-parse "$commit^{tree}" || return 1
done >trees &&
# ignore the return code; it only fails because the input is weird...

Просмотреть файл

@ -32,7 +32,7 @@ test_expect_success 'setup' '
do
test_commit "1-$i" &&
git branch -f commit-1-$i &&
git tag -a -m "1-$i" tag-1-$i commit-1-$i
git tag -a -m "1-$i" tag-1-$i commit-1-$i || return 1
done &&
for j in $(test_seq 1 9)
do
@ -46,7 +46,7 @@ test_expect_success 'setup' '
do
git merge commit-$j-$i -m "$x-$i" &&
git branch -f commit-$x-$i &&
git tag -a -m "$x-$i" tag-$x-$i commit-$x-$i
git tag -a -m "$x-$i" tag-$x-$i commit-$x-$i || return 1
done
done &&
git commit-graph write --reachable &&

Просмотреть файл

@ -1981,7 +1981,7 @@ EOF" &&
then
echo "from refs/heads/main^0"
fi &&
i=$(($i + 1))
i=$(($i + 1)) || return 1
done | git fast-import &&
git checkout main &&
git tag far-far-away HEAD^ &&

Просмотреть файл

@ -16,7 +16,7 @@ test_expect_success 'set up commits for rebasing' '
test_commit rebase-b b bb &&
for i in $(test_seq 1 13)
do
test_commit rebase-$i c $i
test_commit rebase-$i c $i || return 1
done &&
git checkout main &&

Просмотреть файл

@ -967,7 +967,7 @@ test_expect_success 'set up mod-256 conflict scenario' '
# 256 near-identical stanzas...
for i in $(test_seq 1 256); do
for j in 1 2 3 4 5; do
echo $i-$j
echo $i-$j || return 1
done
done >file &&
git add file &&

Просмотреть файл

@ -30,7 +30,7 @@ test_expect_success 'merge c1 with c2, c3, c4, ... c29' '
while test $i -le 30
do
refs="$refs c$i" &&
i=$(expr $i + 1)
i=$(expr $i + 1) || return 1
done &&
git merge $refs &&
test "$(git rev-parse c1)" != "$(git rev-parse HEAD)" &&

Просмотреть файл

@ -95,7 +95,7 @@ test_expect_success 'setup' '
echo $i > $i.c &&
git add $i.c &&
git commit -m $i &&
git tag $i
git tag $i || return 1
done &&
git reset --hard A &&
for i in F G H I
@ -103,7 +103,7 @@ test_expect_success 'setup' '
echo $i > $i.c &&
git add $i.c &&
git commit -m $i &&
git tag $i
git tag $i || return 1
done
'

Просмотреть файл

@ -117,7 +117,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
rm alt_objects/pack/$base_name.keep
else
touch alt_objects/pack/$base_name.keep
fi
fi || return 1
done &&
git repack -a -d &&
test_no_missing_in_packs

Просмотреть файл

@ -310,7 +310,7 @@ test_expect_success setup '
echo "$line" >>"$i" &&
git add "$i" &&
test_tick &&
GIT_AUTHOR_NAME="$line_count" git commit -m "$line_count"
GIT_AUTHOR_NAME="$line_count" git commit -m "$line_count" || return 1
done <"a$i"
done &&
@ -318,7 +318,7 @@ test_expect_success setup '
do
# Overwrite the files with the final content.
cp b$i $i &&
git add $i
git add $i || return 1
done &&
test_tick &&

Просмотреть файл

@ -117,7 +117,7 @@ test_expect_success 'follow-parent avoids deleting relevant info' '
mkdir -p import/trunk/subversion/bindings/swig/perl/t &&
for i in a b c ; do \
echo $i > import/trunk/subversion/bindings/swig/perl/$i.pm &&
echo _$i > import/trunk/subversion/bindings/swig/perl/t/$i.t; \
echo _$i > import/trunk/subversion/bindings/swig/perl/t/$i.t || return 1
done &&
echo "bad delete test" > \
import/trunk/subversion/bindings/swig/perl/t/larger-parent &&
@ -134,7 +134,7 @@ test_expect_success 'follow-parent avoids deleting relevant info' '
svn mv t native/t &&
for i in a b c
do
svn mv $i.pm native/$i.pm
svn mv $i.pm native/$i.pm || return 1
done &&
echo z >>native/t/c.t &&
poke native/t/c.t &&

Просмотреть файл

@ -15,7 +15,7 @@ EOF
test_expect_success 'setup svnrepo' '
for i in aa bb cc dd
do
svn_cmd mkdir -m $i --username $i "$svnrepo"/$i
svn_cmd mkdir -m $i --username $i "$svnrepo"/$i || return 1
done
'
@ -60,7 +60,7 @@ test_expect_success 'authors-file against globs' '
for i in bb ee cc
do
branch="aa/branches/$i" &&
svn_cmd mkdir -m "$branch" --username $i "$svnrepo/$branch"
svn_cmd mkdir -m "$branch" --username $i "$svnrepo/$branch" || return 1
done
'

Просмотреть файл

@ -27,7 +27,7 @@ test_expect_success 'setup test repository' '
test_expect_success 'clone an SVN repository with ignored www directory' '
git svn clone --ignore-paths="^www" "$svnrepo" g &&
echo test_qqq > expect &&
for i in g/*/*.txt; do cat $i >> expect2; done &&
for i in g/*/*.txt; do cat $i >> expect2 || return 1; done &&
test_cmp expect expect2
'
@ -36,7 +36,7 @@ test_expect_success 'init+fetch an SVN repository with ignored www directory' '
( cd c && git svn fetch --ignore-paths="^www" ) &&
rm expect2 &&
echo test_qqq > expect &&
for i in c/*/*.txt; do cat $i >> expect2; done &&
for i in c/*/*.txt; do cat $i >> expect2 || return 1; done &&
test_cmp expect expect2
'
@ -62,7 +62,7 @@ test_expect_success 'update git svn-cloned repo (config ignore)' '
cd g &&
git svn rebase &&
printf "test_qqq\nb\n" > expect &&
for i in */*.txt; do cat $i >> expect2; done &&
for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
test_cmp expect2 expect &&
rm expect expect2
)
@ -73,7 +73,7 @@ test_expect_success 'update git svn-cloned repo (option ignore)' '
cd c &&
git svn rebase --ignore-paths="^www" &&
printf "test_qqq\nb\n" > expect &&
for i in */*.txt; do cat $i >> expect2; done &&
for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
test_cmp expect2 expect &&
rm expect expect2
)
@ -94,7 +94,7 @@ test_expect_success 'update git svn-cloned repo (config ignore)' '
cd g &&
git svn rebase &&
printf "test_qqq\nb\n" > expect &&
for i in */*.txt; do cat $i >> expect2; done &&
for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
test_cmp expect2 expect &&
rm expect expect2
)
@ -105,7 +105,7 @@ test_expect_success 'update git svn-cloned repo (option ignore)' '
cd c &&
git svn rebase --ignore-paths="^www" &&
printf "test_qqq\nb\n" > expect &&
for i in */*.txt; do cat $i >> expect2; done &&
for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
test_cmp expect2 expect &&
rm expect expect2
)
@ -127,7 +127,7 @@ test_expect_success 'update git svn-cloned repo again (config ignore)' '
cd g &&
git svn rebase &&
printf "test_qqq\nb\nygg\n" > expect &&
for i in */*.txt; do cat $i >> expect2; done &&
for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
test_cmp expect2 expect &&
rm expect expect2
)
@ -138,7 +138,7 @@ test_expect_success 'update git svn-cloned repo again (option ignore)' '
cd c &&
git svn rebase --ignore-paths="^www" &&
printf "test_qqq\nb\nygg\n" > expect &&
for i in */*.txt; do cat $i >> expect2; done &&
for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
test_cmp expect2 expect &&
rm expect expect2
)

Просмотреть файл

@ -27,7 +27,7 @@ test_expect_success 'svn-authors setup' '
test_expect_success 'setup svnrepo' '
for i in aa bb cc-sub dd-sub ee-foo ff
do
svn mkdir -m $i --username $i "$svnrepo"/$i
svn mkdir -m $i --username $i "$svnrepo"/$i || return 1
done
'

Просмотреть файл

@ -8,7 +8,7 @@ test_description='git svn creates empty directories'
test_expect_success 'initialize repo' '
for i in a b c d d/e d/e/f "weird file name"
do
svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i"
svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i" || return 1
done
'
@ -102,7 +102,7 @@ test_expect_success 'git svn mkdirs -r works' '
test_expect_success 'initialize trunk' '
for i in trunk trunk/a trunk/"weird file name"
do
svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i"
svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i" || return 1
done
'

Просмотреть файл

@ -28,7 +28,7 @@ test_expect_success 'setup test repository' '
test_expect_success 'clone an SVN repository with filter to include qqq directory' '
git svn clone --include-paths="qqq" "$svnrepo" g &&
echo test_qqq > expect &&
for i in g/*/*.txt; do cat $i >> expect2; done &&
for i in g/*/*.txt; do cat $i >> expect2 || return 1; done &&
test_cmp expect expect2
'
@ -38,7 +38,7 @@ test_expect_success 'init+fetch an SVN repository with included qqq directory' '
( cd c && git svn fetch --include-paths="qqq" ) &&
rm expect2 &&
echo test_qqq > expect &&
for i in c/*/*.txt; do cat $i >> expect2; done &&
for i in c/*/*.txt; do cat $i >> expect2 || return 1; done &&
test_cmp expect expect2
'
@ -64,7 +64,7 @@ test_expect_success 'update git svn-cloned repo (config include)' '
cd g &&
git svn rebase &&
printf "test_qqq\nb\n" > expect &&
for i in */*.txt; do cat $i >> expect2; done &&
for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
test_cmp expect2 expect &&
rm expect expect2
)
@ -75,7 +75,7 @@ test_expect_success 'update git svn-cloned repo (option include)' '
cd c &&
git svn rebase --include-paths="qqq" &&
printf "test_qqq\nb\n" > expect &&
for i in */*.txt; do cat $i >> expect2; done &&
for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
test_cmp expect2 expect &&
rm expect expect2
)
@ -96,7 +96,7 @@ test_expect_success 'update git svn-cloned repo (config include)' '
cd g &&
git svn rebase &&
printf "test_qqq\nb\n" > expect &&
for i in */*.txt; do cat $i >> expect2; done &&
for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
test_cmp expect2 expect &&
rm expect expect2
)
@ -107,7 +107,7 @@ test_expect_success 'update git svn-cloned repo (option include)' '
cd c &&
git svn rebase --include-paths="qqq" &&
printf "test_qqq\nb\n" > expect &&
for i in */*.txt; do cat $i >> expect2; done &&
for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
test_cmp expect2 expect &&
rm expect expect2
)
@ -129,7 +129,7 @@ test_expect_success 'update git svn-cloned repo again (config include)' '
cd g &&
git svn rebase &&
printf "test_qqq\nb\nygg\n" > expect &&
for i in */*.txt; do cat $i >> expect2; done &&
for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
test_cmp expect2 expect &&
rm expect expect2
)
@ -140,7 +140,7 @@ test_expect_success 'update git svn-cloned repo again (option include)' '
cd c &&
git svn rebase --include-paths="qqq" &&
printf "test_qqq\nb\nygg\n" > expect &&
for i in */*.txt; do cat $i >> expect2; done &&
for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
test_cmp expect2 expect &&
rm expect expect2
)

Просмотреть файл

@ -8,7 +8,7 @@ test_description='git svn creates empty directories, calls git gc, makes sure th
test_expect_success 'initialize repo' '
for i in a b c d d/e d/e/f "weird file name"
do
svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i"
svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i" || return 1
done
'

Просмотреть файл

@ -16,7 +16,7 @@ test_expect_success 'setup large marks file' '
blob=$(git rev-parse HEAD:one.t) &&
for i in $(test_seq 1024 16384)
do
echo ":$i $blob"
echo ":$i $blob" || return 1
done >>marks
'

Просмотреть файл

@ -338,7 +338,7 @@ test_expect_success 'cvs update (subdirectories)' \
'(for dir in A A/B A/B/C A/D E; do
mkdir $dir &&
echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
git add $dir
git add $dir || exit 1
done) &&
git commit -q -m "deep sub directory structure" &&
git push gitcvs.git >/dev/null &&
@ -381,7 +381,7 @@ test_expect_success 'cvs update (merge)' \
for i in 1 2 3 4 5 6 7
do
echo Line $i >>merge &&
echo Line $i >>expected
echo Line $i >>expected || return 1
done &&
echo Line 8 >>expected &&
git add merge &&

Просмотреть файл

@ -171,7 +171,7 @@ test_expect_success 'clone using non-numeric revision ranges' '
cd "$git" &&
git ls-files >lines &&
test_line_count = 8 lines
)
) || return 1
done
'

Просмотреть файл

@ -92,11 +92,11 @@ test_expect_success 'Add some more files' '
for i in $(test_seq 0 10)
do
p4_add_file "included/x$i" &&
p4_add_file "excluded/x$i"
p4_add_file "excluded/x$i" || return 1
done &&
for i in $(test_seq 0 10)
do
p4_add_file "excluded/y$i"
p4_add_file "excluded/y$i" || return 1
done
'
@ -123,7 +123,7 @@ test_expect_success 'Create a repo with multiple depot paths' '
do
for i in $(test_seq 1 10)
do
p4_add_file "$p/file$p$i"
p4_add_file "$p/file$p$i" || return 1
done
done
'

Просмотреть файл

@ -879,7 +879,7 @@ test_expect_success '__git_refs - unique remote branches for git checkout DWIMer
refs/remotes/remote/branch-in-remote
do
git update-ref $remote_ref main &&
test_when_finished "git update-ref -d $remote_ref"
test_when_finished "git update-ref -d $remote_ref" || return 1
done &&
(
cur= &&
@ -1052,7 +1052,7 @@ test_expect_success '__git_refs - only matching refs - checkout DWIMery' '
refs/remotes/remote/branch-in-remote
do
git update-ref $remote_ref main &&
test_when_finished "git update-ref -d $remote_ref"
test_when_finished "git update-ref -d $remote_ref" || return 1
done &&
(
cur=mat &&