Skip to content

Commit dc46886

Browse files
pks-tgitster
authored andcommitted
t: prepare execution of potentially failing commands for set -e
Several of our tests verify whether a certain binary can be executed, potentially skipping tests in case we cannot, for example because the binary doesn't exist. In those cases we often run the binary outside of any conditionally. This will start to fail once we enable `set -e`, as that will cause us to bail out the test immediately. Improve these tests by executing them inside of a conditional instead. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 56758a2 commit dc46886

11 files changed

Lines changed: 24 additions & 24 deletions

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/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/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

t/t7422-submodule-output.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ test_expect_success !MINGW 'git submodule status --recursive propagates SIGPIPE'
198198
(
199199
cd repo &&
200200
GIT_ALLOW_PROTOCOL=file git submodule add "$(pwd)"/../submodule &&
201-
{ git submodule status --recursive 2>err; echo $?>status; } |
201+
{ { ret=0 && git submodule status --recursive 2>err || ret=$?; } && echo $ret >status; } |
202202
grep -q recursive-submodule-path-1 &&
203203
test_must_be_empty err &&
204204
test_match_signal 13 "$(cat status)"

t/t9200-git-cvsexportcommit.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ if ! test_have_prereq PERL; then
1111
test_done
1212
fi
1313

14-
cvs >/dev/null 2>&1
15-
if test $? -ne 1
14+
if ! cvs version >/dev/null 2>&1
1615
then
1716
skip_all='skipping git cvsexportcommit tests, cvs not found'
1817
test_done

t/t9400-git-cvsserver-server.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ if ! test_have_prereq PERL; then
1717
skip_all='skipping git cvsserver tests, perl not available'
1818
test_done
1919
fi
20-
cvs >/dev/null 2>&1
21-
if test $? -ne 1
20+
21+
if ! cvs version >/dev/null 2>&1
2222
then
2323
skip_all='skipping git-cvsserver tests, cvs not found'
2424
test_done
2525
fi
26+
2627
perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
2728
skip_all='skipping git-cvsserver tests, Perl SQLite interface unavailable'
2829
test_done

t/t9401-git-cvsserver-crlf.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ check_status_options() {
6060
return $stat
6161
}
6262

63-
cvs >/dev/null 2>&1
64-
if test $? -ne 1
63+
if ! cvs version >/dev/null 2>&1
6564
then
6665
skip_all='skipping git-cvsserver tests, cvs not found'
6766
test_done
6867
fi
68+
6969
if ! test_have_prereq PERL
7070
then
7171
skip_all='skipping git-cvsserver tests, perl not available'

t/t9402-git-cvsserver-refs.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ check_diff() {
6868

6969
#########
7070

71-
cvs >/dev/null 2>&1
72-
if test $? -ne 1
71+
if ! cvs version >/dev/null 2>&1
7372
then
7473
skip_all='skipping git-cvsserver tests, cvs not found'
7574
test_done
7675
fi
76+
7777
if ! test_have_prereq PERL
7878
then
7979
skip_all='skipping git-cvsserver tests, perl not available'

t/test-lib-functions.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,8 +1248,7 @@ test_might_fail () {
12481248
test_expect_code () {
12491249
want_code=$1
12501250
shift
1251-
"$@" 2>&7
1252-
exit_code=$?
1251+
exit_code=0; "$@" 2>&7 || exit_code=$?
12531252
if test $exit_code = $want_code
12541253
then
12551254
return 0

0 commit comments

Comments
 (0)