auto-crlf tests: don't lose exit code in loops and outside tests

Change the functions which are called from within
"test_expect_success" to add the "|| return 1" idiom to their
for-loops, so we won't lose the exit code of "cp", "git" etc.

Then for those setup functions that aren't called from a
"test_expect_success" we need to put the setup code in a
"test_expect_success" as well. It would not be enough to properly
&&-chain these, as the calling code is the top-level script itself. As
we don't run the tests with "set -e" we won't report failing commands
at the top-level.

The "checkout" part of this would miss memory leaks under
SANITIZE=leak, this code doesn't leak (the relevant "git checkout"
leak has been fixed), but in a past version of git we'd continue past
this failure under SANITIZE=leak when these invocations had errored
out, even under "--immediate".

For checkout_files() we could run one test_expect_success() instead of
the 5 we run now in a loop.

But as this function added in [1] is already taking pains to split up
its setup into phases (there are 5 more "test_expect_success()" at the
end of it already, see [1]), let's follow that existing convention.

1. 343151dcbd (t0027: combinations of core.autocrlf, core.eol and text, 2014-06-29)

Helped-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Ævar Arnfjörð Bjarmason 2023-02-06 23:44:28 +01:00 committed by Junio C Hamano
parent c48035d29b
commit fb18dd2831

View File

@ -70,7 +70,8 @@ create_NNO_MIX_files () {
cp CRLF ${pfx}_CRLF.txt && cp CRLF ${pfx}_CRLF.txt &&
cp CRLF_mix_LF ${pfx}_CRLF_mix_LF.txt && cp CRLF_mix_LF ${pfx}_CRLF_mix_LF.txt &&
cp LF_mix_CR ${pfx}_LF_mix_CR.txt && cp LF_mix_CR ${pfx}_LF_mix_CR.txt &&
cp CRLF_nul ${pfx}_CRLF_nul.txt cp CRLF_nul ${pfx}_CRLF_nul.txt ||
return 1
done done
done done
done done
@ -101,7 +102,8 @@ commit_check_warn () {
do do
fname=${pfx}_$f.txt && fname=${pfx}_$f.txt &&
cp $f $fname && cp $f $fname &&
git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" ||
return 1
done && done &&
git commit -m "core.autocrlf $crlf" && git commit -m "core.autocrlf $crlf" &&
check_warning "$lfname" ${pfx}_LF.err && check_warning "$lfname" ${pfx}_LF.err &&
@ -121,15 +123,19 @@ commit_chk_wrnNNO () {
lfmixcr=$1 ; shift lfmixcr=$1 ; shift
crlfnul=$1 ; shift crlfnul=$1 ; shift
pfx=NNO_attr_${attr}_aeol_${aeol}_${crlf} pfx=NNO_attr_${attr}_aeol_${aeol}_${crlf}
#Commit files on top of existing file
create_gitattributes "$attr" $aeol && test_expect_success 'setup commit NNO files' '
for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul #Commit files on top of existing file
do create_gitattributes "$attr" $aeol &&
fname=${pfx}_$f.txt && for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
cp $f $fname && do
printf Z >>"$fname" && fname=${pfx}_$f.txt &&
git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" cp $f $fname &&
done printf Z >>"$fname" &&
git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" ||
return 1
done
'
test_expect_success "commit NNO files crlf=$crlf attr=$attr LF" ' test_expect_success "commit NNO files crlf=$crlf attr=$attr LF" '
check_warning "$lfwarn" ${pfx}_LF.err check_warning "$lfwarn" ${pfx}_LF.err
@ -163,15 +169,19 @@ commit_MIX_chkwrn () {
lfmixcr=$1 ; shift lfmixcr=$1 ; shift
crlfnul=$1 ; shift crlfnul=$1 ; shift
pfx=MIX_attr_${attr}_aeol_${aeol}_${crlf} pfx=MIX_attr_${attr}_aeol_${aeol}_${crlf}
#Commit file with CLRF_mix_LF on top of existing file
create_gitattributes "$attr" $aeol && test_expect_success 'setup commit file with mixed EOL' '
for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul #Commit file with CLRF_mix_LF on top of existing file
do create_gitattributes "$attr" $aeol &&
fname=${pfx}_$f.txt && for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
cp CRLF_mix_LF $fname && do
printf Z >>"$fname" && fname=${pfx}_$f.txt &&
git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" cp CRLF_mix_LF $fname &&
done printf Z >>"$fname" &&
git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" ||
return 1
done
'
test_expect_success "commit file with mixed EOL onto LF crlf=$crlf attr=$attr" ' test_expect_success "commit file with mixed EOL onto LF crlf=$crlf attr=$attr" '
check_warning "$lfwarn" ${pfx}_LF.err check_warning "$lfwarn" ${pfx}_LF.err
@ -289,17 +299,17 @@ checkout_files () {
lfmixcrlf=$1 ; shift lfmixcrlf=$1 ; shift
lfmixcr=$1 ; shift lfmixcr=$1 ; shift
crlfnul=$1 ; shift crlfnul=$1 ; shift
create_gitattributes "$attr" $ident $aeol && test_expect_success "setup config for checkout attr=$attr ident=$ident aeol=$aeol core.autocrlf=$crlf" '
git config core.autocrlf $crlf && create_gitattributes "$attr" $ident $aeol &&
git config core.autocrlf $crlf
'
pfx=eol_${ceol}_crlf_${crlf}_attr_${attr}_ && pfx=eol_${ceol}_crlf_${crlf}_attr_${attr}_ &&
for f in LF CRLF LF_mix_CR CRLF_mix_LF LF_nul for f in LF CRLF LF_mix_CR CRLF_mix_LF LF_nul
do do
rm crlf_false_attr__$f.txt && test_expect_success "setup $f checkout ${ceol:+ with -c core.eol=$ceol}" '
if test -z "$ceol"; then rm -f crlf_false_attr__$f.txt &&
git checkout -- crlf_false_attr__$f.txt git ${ceol:+-c core.eol=$ceol} checkout -- crlf_false_attr__$f.txt
else '
git -c core.eol=$ceol checkout -- crlf_false_attr__$f.txt
fi
done done
test_expect_success "ls-files --eol attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol" ' test_expect_success "ls-files --eol attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol" '