Skip to content

Commit aa13593

Browse files
committed
Merge branch 'ps/test-set-e-clean' into seen
* ps/test-set-e-clean: SQUASH??? t: detect errors outside of test cases t9902: fix use of `read` with `set -e` t6002: fix use of `expr` with `set -e` t1301: don't fail in case setfacl(1) doesn't exist or fails t0008: silence error in subshell when using `grep -v` t: prepare `test_when_finished ()`/`test_atexit()` for `set -e` t: prepare execution of potentially failing commands for `set -e` t: prepare conditional test execution for `set -e` t: prepare `git config --unset` calls for `set -e` t: prepare `stop_git_daemon ()` for `set -e` t: prepare `test_must_fail ()` for `set -e` t: prepare `test_match_signal ()` calls for `set -e`
2 parents ad8b884 + 1b0b27e commit aa13593

19 files changed

+78
-58
lines changed

t/lib-git-daemon.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,21 @@ stop_git_daemon() {
8585

8686
# kill git-daemon child of git
8787
say >&3 "Stopping git daemon ..."
88+
8889
kill "$GIT_DAEMON_PID"
89-
wait "$GIT_DAEMON_PID" >&3 2>&4
90-
ret=$?
90+
if wait "$GIT_DAEMON_PID" >&3 2>&4
91+
then
92+
ret=0
93+
else
94+
ret=$?
95+
fi
96+
9197
if ! test_match_signal 15 $ret
9298
then
9399
error "git daemon exited with status: $ret"
94100
fi
95-
kill "$(cat "$GIT_DAEMON_PIDFILE")" 2>/dev/null
101+
102+
kill "$(cat "$GIT_DAEMON_PIDFILE")" 2>/dev/null || :
96103
GIT_DAEMON_PID=
97104
rm -f git_daemon_output "$GIT_DAEMON_PIDFILE"
98105
}

t/lib-git-svn.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ GIT_SVN_DIR=$GIT_DIR/svn/refs/remotes/git-svn
1515
SVN_TREE=$GIT_SVN_DIR/svn-tree
1616
test_set_port SVNSERVE_PORT
1717

18-
svn >/dev/null 2>&1
19-
if test $? -ne 1
18+
if ! svn help >/dev/null 2>&1
2019
then
2120
skip_all='skipping git svn tests, svn not found'
2221
test_done
@@ -27,13 +26,13 @@ export svnrepo
2726
svnconf=$PWD/svnconf
2827
export svnconf
2928

29+
x=0
3030
perl -w -e "
3131
use SVN::Core;
3232
use SVN::Repos;
3333
\$SVN::Core::VERSION gt '1.1.0' or exit(42);
3434
system(qw/svnadmin create --fs-type fsfs/, \$ENV{svnrepo}) == 0 or exit(41);
35-
" >&3 2>&4
36-
x=$?
35+
" >&3 2>&4 || x=$?
3736
if test $x -ne 0
3837
then
3938
if test $x -eq 42; then

t/lib-httpd.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,10 @@ start_httpd() {
235235

236236
test_atexit stop_httpd
237237

238-
"$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
238+
if ! "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
239239
-f "$TEST_PATH/apache.conf" $HTTPD_PARA \
240240
-c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start \
241241
>&3 2>&4
242-
if test $? -ne 0
243242
then
244243
cat "$HTTPD_ROOT_PATH"/error.log >&4 2>/dev/null
245244
test_skip_or_die GIT_TEST_HTTPD "web server setup failed"

t/t0005-signals.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ test_expect_success 'create blob' '
4242
'
4343

4444
test_expect_success !MINGW 'a constipated git dies with SIGPIPE' '
45-
OUT=$( ((large_git; echo $? 1>&3) | :) 3>&1 ) &&
45+
OUT=$( ((large_git || echo $? 1>&3) | :) 3>&1 ) &&
4646
test_match_signal 13 "$OUT"
4747
'
4848

4949
test_expect_success !MINGW 'a constipated git dies with SIGPIPE even if parent ignores it' '
50-
OUT=$( ((trap "" PIPE && large_git; echo $? 1>&3) | :) 3>&1 ) &&
50+
OUT=$( ((trap "" PIPE && large_git || echo $? 1>&3) | :) 3>&1 ) &&
5151
test_match_signal 13 "$OUT"
5252
'
5353

t/t0008-ignores.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ test_expect_success_multiple () {
122122
fi
123123
testname="$1" expect_all="$2" code="$3"
124124

125-
expect_verbose=$( echo "$expect_all" | grep -v '^:: ' )
126-
expect=$( echo "$expect_verbose" | sed -e 's/.* //' )
125+
expect_verbose=$(echo "$expect_all" | grep -v '^:: ' || true)
126+
expect=$(echo "$expect_verbose" | sed -e 's/.* //')
127127

128128
test_expect_success $prereq "$testname${no_index_opt:+ with $no_index_opt}" '
129129
expect "$expect" &&

t/t1301-shared-repo.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ TEST_CREATE_REPO_NO_TEMPLATE=1
1212
. ./test-lib.sh
1313

1414
# Remove a default ACL from the test dir if possible.
15-
setfacl -k . 2>/dev/null
15+
setfacl -k . 2>/dev/null || true
1616

1717
# User must have read permissions to the repo -> failure on --shared=0400
1818
test_expect_success 'shared = 0400 (faulty permission u-w)' '

t/t3600-rm.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ test_expect_success 'choking "git rm" should not let it die with cruft (induce S
260260

261261
test_expect_success !MINGW 'choking "git rm" should not let it die with cruft (induce and check SIGPIPE)' '
262262
choke_git_rm_setup &&
263-
OUT=$( ((trap "" PIPE && git rm -n "some-file-*"; echo $? 1>&3) | :) 3>&1 ) &&
263+
OUT=$( ((trap "" PIPE && git rm -n "some-file-*" || echo $? 1>&3) | :) 3>&1 ) &&
264264
test_match_signal 13 "$OUT" &&
265265
test_path_is_missing .git/index.lock
266266
'

t/t4032-diff-inter-hunk-context.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ f() {
1717

1818
t() {
1919
use_config=
20-
git config --unset diff.interHunkContext
20+
git config --unset diff.interHunkContext || :
2121

2222
case $# in
2323
4) hunks=$4; cmd="diff -U$3";;
@@ -40,11 +40,13 @@ t() {
4040
test $(git $cmd $file | grep '^@@ ' | wc -l) = $hunks
4141
"
4242

43-
test -f $expected &&
44-
test_expect_success "$label: check output" "
45-
git $cmd $file | grep -v '^index ' >actual &&
46-
test_cmp $expected actual
47-
"
43+
if test -f $expected
44+
then
45+
test_expect_success "$label: check output" "
46+
git $cmd $file | grep -v '^index ' >actual &&
47+
test_cmp $expected actual
48+
"
49+
fi
4850
}
4951

5052
cat <<EOF >expected.f1.0.1 || exit 1

t/t6002-rev-list-bisect.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@ test_bisection_diff()
2727
# Test if bisection size is close to half of list size within
2828
# tolerance.
2929
#
30-
_bisect_err=$(expr $_list_size - $_bisection_size \* 2)
31-
test "$_bisect_err" -lt 0 && _bisect_err=$(expr 0 - $_bisect_err)
32-
_bisect_err=$(expr $_bisect_err / 2) ; # floor
33-
34-
test_expect_success \
35-
"bisection diff $_bisect_option $_head $* <= $_max_diff" \
36-
'test $_bisect_err -le $_max_diff'
30+
_bisect_err=$(($_list_size - $_bisection_size * 2))
31+
if test "$_bisect_err" -lt 0
32+
then
33+
_bisect_err=$((0 - $_bisect_err))
34+
fi
35+
_bisect_err=$(($_bisect_err / 2)) ; # floor
36+
37+
test_expect_success "bisection diff $_bisect_option $_head $* <= $_max_diff" '
38+
test $_bisect_err -le $_max_diff
39+
'
3740
}
3841

3942
date >path0

t/t7450-bad-git-dotfiles.sh

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,19 @@ check_dotx_symlink () {
220220
)
221221
'
222222

223-
test -n "$refuse_index" &&
224-
test_expect_success "refuse to load symlinked $name into index ($type)" '
225-
test_must_fail \
226-
git -C $dir \
227-
-c core.protectntfs \
228-
-c core.protecthfs \
229-
read-tree $tree 2>err &&
230-
grep "invalid path.*$name" err &&
231-
git -C $dir ls-files -s >out &&
232-
test_must_be_empty out
233-
'
223+
if test -n "$refuse_index"
224+
then
225+
test_expect_success "refuse to load symlinked $name into index ($type)" '
226+
test_must_fail \
227+
git -C $dir \
228+
-c core.protectntfs \
229+
-c core.protecthfs \
230+
read-tree $tree 2>err &&
231+
grep "invalid path.*$name" err &&
232+
git -C $dir ls-files -s >out &&
233+
test_must_be_empty out
234+
'
235+
fi
234236
}
235237

236238
check_dotx_symlink gitmodules vanilla .gitmodules

0 commit comments

Comments
 (0)