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>

Ævar Arnfjörð Bjarmason committed Feb 6, 2023 at 23:44 UTC fb18dd2831323d5dece711cdbcaa9dcd8bf4edab
1 file changed +38 -28
t/t0027-auto-crlf.sh
+38 -28
@@ -70,7 +70,8 @@ create_NNO_MIX_files () {
70 cp CRLF ${pfx}_CRLF.txt &&
71 cp CRLF_mix_LF ${pfx}_CRLF_mix_LF.txt &&
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
75 done
76 done
77 done
@@ -101,7 +102,8 @@ commit_check_warn () {
102 do
103 fname=${pfx}_$f.txt &&
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
107 done &&
108 git commit -m "core.autocrlf $crlf" &&
109 check_warning "$lfname" ${pfx}_LF.err &&
@@ -121,15 +123,19 @@ commit_chk_wrnNNO () {
123 lfmixcr=$1 ; shift
124 crlfnul=$1 ; shift
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 + '
139
140 test_expect_success "commit NNO files crlf=$crlf attr=$attr LF" '
141 check_warning "$lfwarn" ${pfx}_LF.err
@@ -163,15 +169,19 @@ commit_MIX_chkwrn () {
169 lfmixcr=$1 ; shift
170 crlfnul=$1 ; shift
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 + '
185
186 test_expect_success "commit file with mixed EOL onto LF crlf=$crlf attr=$attr" '
187 check_warning "$lfwarn" ${pfx}_LF.err
@@ -289,17 +299,17 @@ checkout_files () {
299 lfmixcrlf=$1 ; shift
300 lfmixcr=$1 ; shift
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 + '
306 pfx=eol_${ceol}_crlf_${crlf}_attr_${attr}_ &&
307 for f in LF CRLF LF_mix_CR CRLF_mix_LF LF_nul
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 + '
313 done
314
315 test_expect_success "ls-files --eol attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol" '