Skip to content

Commit 2aae778

Browse files
committed
Merge branch 'ps/test-set-e-clean' into seen
The test suite harness and many individual test scripts have been updated to work correctly when 'set -e' is in effect, which helps detect misspelled test commands. Comments? * ps/test-set-e-clean: 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 b7430cb + 8b507cb commit 2aae778

22 files changed

+85
-66
lines changed

t/lib-git-daemon.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,16 @@ 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+
ret=0; wait "$GIT_DAEMON_PID" >&3 2>&4 || ret=$?
91+
9192
if ! test_match_signal 15 $ret
9293
then
9394
error "git daemon exited with status: $ret"
9495
fi
95-
kill "$(cat "$GIT_DAEMON_PIDFILE")" 2>/dev/null
96+
97+
kill "$(cat "$GIT_DAEMON_PIDFILE")" 2>/dev/null || :
9698
GIT_DAEMON_PID=
9799
rm -f git_daemon_output "$GIT_DAEMON_PIDFILE"
98100
}

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 0 1>&3 || 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 0 1>&3 || 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 '^:: ' || :)
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 || :
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 0 1>&3 || echo $? 1>&3) | :) 3>&1 ) &&
264264
test_match_signal 13 "$OUT" &&
265265
test_path_is_missing .git/index.lock
266266
'

t/t3901-i18n-patch.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ check_encoding () {
2828
8859)
2929
grep "^encoding ISO8859-1" ;;
3030
*)
31-
grep "^encoding ISO8859-1"; test "$?" != 0 ;;
31+
ret=0; grep "^encoding ISO8859-1" || ret=$?
32+
test "$ret" != 0 ;;
3233
esac || return 1
3334
j=$i
3435
i=$(($i+1))

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/t5000-tar-tree.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,8 @@ test_expect_success LONG_IS_64BIT 'set up repository with huge blob' '
503503
# would generate the whole 64GB).
504504
test_expect_success LONG_IS_64BIT 'generate tar with huge size' '
505505
{
506-
git archive HEAD
507-
echo $? >exit-code
506+
{ ret=0 && git archive HEAD || ret=$?; } &&
507+
echo "$ret" >exit-code
508508
} | test_copy_bytes 4096 >huge.tar &&
509509
echo 141 >expect &&
510510
test_cmp expect exit-code

0 commit comments

Comments
 (0)