Git fork

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. 343151dcbdf (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>

authored by

Ævar Arnfjörð Bjarmason and committed by
Junio C Hamano
fb18dd28 c48035d2

+38 -28
+38 -28
t/t0027-auto-crlf.sh
··· 70 70 cp CRLF ${pfx}_CRLF.txt && 71 71 cp CRLF_mix_LF ${pfx}_CRLF_mix_LF.txt && 72 72 cp LF_mix_CR ${pfx}_LF_mix_CR.txt && 73 - cp CRLF_nul ${pfx}_CRLF_nul.txt 73 + cp CRLF_nul ${pfx}_CRLF_nul.txt || 74 + return 1 74 75 done 75 76 done 76 77 done ··· 101 102 do 102 103 fname=${pfx}_$f.txt && 103 104 cp $f $fname && 104 - git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" 105 + git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" || 106 + return 1 105 107 done && 106 108 git commit -m "core.autocrlf $crlf" && 107 109 check_warning "$lfname" ${pfx}_LF.err && ··· 121 123 lfmixcr=$1 ; shift 122 124 crlfnul=$1 ; shift 123 125 pfx=NNO_attr_${attr}_aeol_${aeol}_${crlf} 124 - #Commit files on top of existing file 125 - create_gitattributes "$attr" $aeol && 126 - for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul 127 - do 128 - fname=${pfx}_$f.txt && 129 - cp $f $fname && 130 - printf Z >>"$fname" && 131 - git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" 132 - done 126 + 127 + test_expect_success 'setup commit NNO files' ' 128 + #Commit files on top of existing file 129 + create_gitattributes "$attr" $aeol && 130 + for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul 131 + do 132 + fname=${pfx}_$f.txt && 133 + cp $f $fname && 134 + printf Z >>"$fname" && 135 + git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" || 136 + return 1 137 + done 138 + ' 133 139 134 140 test_expect_success "commit NNO files crlf=$crlf attr=$attr LF" ' 135 141 check_warning "$lfwarn" ${pfx}_LF.err ··· 163 169 lfmixcr=$1 ; shift 164 170 crlfnul=$1 ; shift 165 171 pfx=MIX_attr_${attr}_aeol_${aeol}_${crlf} 166 - #Commit file with CLRF_mix_LF on top of existing file 167 - create_gitattributes "$attr" $aeol && 168 - for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul 169 - do 170 - fname=${pfx}_$f.txt && 171 - cp CRLF_mix_LF $fname && 172 - printf Z >>"$fname" && 173 - git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" 174 - done 172 + 173 + test_expect_success 'setup commit file with mixed EOL' ' 174 + #Commit file with CLRF_mix_LF on top of existing file 175 + create_gitattributes "$attr" $aeol && 176 + for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul 177 + do 178 + fname=${pfx}_$f.txt && 179 + cp CRLF_mix_LF $fname && 180 + printf Z >>"$fname" && 181 + git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" || 182 + return 1 183 + done 184 + ' 175 185 176 186 test_expect_success "commit file with mixed EOL onto LF crlf=$crlf attr=$attr" ' 177 187 check_warning "$lfwarn" ${pfx}_LF.err ··· 289 299 lfmixcrlf=$1 ; shift 290 300 lfmixcr=$1 ; shift 291 301 crlfnul=$1 ; shift 292 - create_gitattributes "$attr" $ident $aeol && 293 - git config core.autocrlf $crlf && 302 + test_expect_success "setup config for checkout attr=$attr ident=$ident aeol=$aeol core.autocrlf=$crlf" ' 303 + create_gitattributes "$attr" $ident $aeol && 304 + git config core.autocrlf $crlf 305 + ' 294 306 pfx=eol_${ceol}_crlf_${crlf}_attr_${attr}_ && 295 307 for f in LF CRLF LF_mix_CR CRLF_mix_LF LF_nul 296 308 do 297 - rm crlf_false_attr__$f.txt && 298 - if test -z "$ceol"; then 299 - git checkout -- crlf_false_attr__$f.txt 300 - else 301 - git -c core.eol=$ceol checkout -- crlf_false_attr__$f.txt 302 - fi 309 + test_expect_success "setup $f checkout ${ceol:+ with -c core.eol=$ceol}" ' 310 + rm -f crlf_false_attr__$f.txt && 311 + git ${ceol:+-c core.eol=$ceol} checkout -- crlf_false_attr__$f.txt 312 + ' 303 313 done 304 314 305 315 test_expect_success "ls-files --eol attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol" '