Skip to content

Commit fb18dd2

Browse files
avargitster
authored andcommitted
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. 343151d (t0027: combinations of core.autocrlf, core.eol and text, 2014-06-29) Helped-by: René Scharfe <[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c48035d commit fb18dd2

File tree

1 file changed

+38
-28
lines changed

1 file changed

+38
-28
lines changed

t/t0027-auto-crlf.sh

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ create_NNO_MIX_files () {
7070
cp CRLF ${pfx}_CRLF.txt &&
7171
cp CRLF_mix_LF ${pfx}_CRLF_mix_LF.txt &&
7272
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
7475
done
7576
done
7677
done
@@ -101,7 +102,8 @@ commit_check_warn () {
101102
do
102103
fname=${pfx}_$f.txt &&
103104
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
105107
done &&
106108
git commit -m "core.autocrlf $crlf" &&
107109
check_warning "$lfname" ${pfx}_LF.err &&
@@ -121,15 +123,19 @@ commit_chk_wrnNNO () {
121123
lfmixcr=$1 ; shift
122124
crlfnul=$1 ; shift
123125
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+
'
133139

134140
test_expect_success "commit NNO files crlf=$crlf attr=$attr LF" '
135141
check_warning "$lfwarn" ${pfx}_LF.err
@@ -163,15 +169,19 @@ commit_MIX_chkwrn () {
163169
lfmixcr=$1 ; shift
164170
crlfnul=$1 ; shift
165171
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+
'
175185

176186
test_expect_success "commit file with mixed EOL onto LF crlf=$crlf attr=$attr" '
177187
check_warning "$lfwarn" ${pfx}_LF.err
@@ -289,17 +299,17 @@ checkout_files () {
289299
lfmixcrlf=$1 ; shift
290300
lfmixcr=$1 ; shift
291301
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+
'
294306
pfx=eol_${ceol}_crlf_${crlf}_attr_${attr}_ &&
295307
for f in LF CRLF LF_mix_CR CRLF_mix_LF LF_nul
296308
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+
'
303313
done
304314

305315
test_expect_success "ls-files --eol attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol" '

0 commit comments

Comments
 (0)