Skip to content

Commit 6f54213

Browse files
committed
Merge branch 'ab/avoid-losing-exit-codes-in-tests'
Test clean-up. * ab/avoid-losing-exit-codes-in-tests: tests: don't lose misc "git" exit codes tests: don't lose exit status with "test <op> $(git ...)" tests: don't lose "git" exit codes in "! ( git ... | grep )" tests: don't lose exit status with "(cd ...; test <op> $(git ...))" t/lib-patch-mode.sh: fix ignored exit codes auto-crlf tests: don't lose exit code in loops and outside tests
2 parents 9502646 + 9fdc79e commit 6f54213

21 files changed

+245
-112
lines changed

t/lib-httpd.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,12 @@ test_http_push_nonff () {
228228
git commit -a -m path2 --amend &&
229229
230230
test_must_fail git push -v origin >output 2>&1 &&
231-
(cd "$REMOTE_REPO" &&
232-
test $HEAD = $(git rev-parse --verify HEAD))
231+
(
232+
cd "$REMOTE_REPO" &&
233+
echo "$HEAD" >expect &&
234+
git rev-parse --verify HEAD >actual &&
235+
test_cmp expect actual
236+
)
233237
'
234238

235239
test_expect_success 'non-fast-forward push show ref status' '

t/lib-patch-mode.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ set_and_save_state () {
2929

3030
# verify_state <path> <expected-worktree-content> <expected-index-content>
3131
verify_state () {
32-
test "$(cat "$1")" = "$2" &&
33-
test "$(git show :"$1")" = "$3"
32+
echo "$2" >expect &&
33+
test_cmp expect "$1" &&
34+
35+
echo "$3" >expect &&
36+
git show :"$1" >actual &&
37+
test_cmp expect actual
3438
}
3539

3640
# verify_saved_state <path>
@@ -46,5 +50,6 @@ save_head () {
4650
}
4751

4852
verify_saved_head () {
49-
test "$(cat _head)" = "$(git rev-parse HEAD)"
53+
git rev-parse HEAD >actual &&
54+
test_cmp _head actual
5055
}

t/lib-submodule-update.sh

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -168,28 +168,26 @@ replace_gitfile_with_git_dir () {
168168
# Note that this only supports submodules at the root level of the
169169
# superproject, with the default name, i.e. same as its path.
170170
test_git_directory_is_unchanged () {
171-
(
172-
cd ".git/modules/$1" &&
173-
# does core.worktree point at the right place?
174-
test "$(git config core.worktree)" = "../../../$1" &&
175-
# remove it temporarily before comparing, as
176-
# "$1/.git/config" lacks it...
177-
git config --unset core.worktree
178-
) &&
171+
# does core.worktree point at the right place?
172+
echo "../../../$1" >expect &&
173+
git -C ".git/modules/$1" config core.worktree >actual &&
174+
test_cmp expect actual &&
175+
# remove it temporarily before comparing, as
176+
# "$1/.git/config" lacks it...
177+
git -C ".git/modules/$1" config --unset core.worktree &&
179178
diff -r ".git/modules/$1" "$1/.git" &&
180-
(
181-
# ... and then restore.
182-
cd ".git/modules/$1" &&
183-
git config core.worktree "../../../$1"
184-
)
179+
# ... and then restore.
180+
git -C ".git/modules/$1" config core.worktree "../../../$1"
185181
}
186182

187183
test_git_directory_exists () {
188184
test -e ".git/modules/$1" &&
189185
if test -f sub1/.git
190186
then
191187
# does core.worktree point at the right place?
192-
test "$(git -C .git/modules/$1 config core.worktree)" = "../../../$1"
188+
echo "../../../$1" >expect &&
189+
git -C ".git/modules/$1" config core.worktree >actual &&
190+
test_cmp expect actual
193191
fi
194192
}
195193

t/t0001-init.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,9 +598,14 @@ test_expect_success 'invalid default branch name' '
598598
test_expect_success 'branch -m with the initial branch' '
599599
git init rename-initial &&
600600
git -C rename-initial branch -m renamed &&
601-
test renamed = $(git -C rename-initial symbolic-ref --short HEAD) &&
601+
echo renamed >expect &&
602+
git -C rename-initial symbolic-ref --short HEAD >actual &&
603+
test_cmp expect actual &&
604+
602605
git -C rename-initial branch -m renamed again &&
603-
test again = $(git -C rename-initial symbolic-ref --short HEAD)
606+
echo again >expect &&
607+
git -C rename-initial symbolic-ref --short HEAD >actual &&
608+
test_cmp expect actual
604609
'
605610

606611
test_done

t/t0002-gitfile.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ test_expect_success 'bad setup: invalid .git file path' '
3333

3434
test_expect_success 'final setup + check rev-parse --git-dir' '
3535
echo "gitdir: $REAL" >.git &&
36-
test "$REAL" = "$(git rev-parse --git-dir)"
36+
echo "$REAL" >expect &&
37+
git rev-parse --git-dir >actual &&
38+
test_cmp expect actual
3739
'
3840

3941
test_expect_success 'check hash-object' '

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" '

t/t0055-beyond-symlinks.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,22 @@ test_expect_success SYMLINKS setup '
1515

1616
test_expect_success SYMLINKS 'update-index --add beyond symlinks' '
1717
test_must_fail git update-index --add c/d &&
18-
! ( git ls-files | grep c/d )
18+
cat >expect <<-\EOF &&
19+
a
20+
b/d
21+
EOF
22+
git ls-files >actual &&
23+
test_cmp expect actual
1924
'
2025

2126
test_expect_success SYMLINKS 'add beyond symlinks' '
2227
test_must_fail git add c/d &&
23-
! ( git ls-files | grep c/d )
28+
cat >expect <<-\EOF &&
29+
a
30+
b/d
31+
EOF
32+
git ls-files >actual &&
33+
test_cmp expect actual
2434
'
2535

2636
test_done

0 commit comments

Comments
 (0)