File tree Expand file tree Collapse file tree 10 files changed +84
-13
lines changed Expand file tree Collapse file tree 10 files changed +84
-13
lines changed Original file line number Diff line number Diff line change 156
156
157
157
export DEVELOPER=1
158
158
export DEFAULT_TEST_TARGET=prove
159
- export GIT_TEST_CLONE_2GB=YesPlease
159
+ export GIT_TEST_CLONE_2GB=true
160
160
161
161
case " $jobname " in
162
162
linux-clang|linux-gcc)
Original file line number Diff line number Diff line change @@ -982,6 +982,15 @@ library for your script to use.
982
982
output to the downstream---unlike the real version, it generates
983
983
only up to 99 lines.
984
984
985
+ - test_bool_env <env-variable-name> <default-value>
986
+
987
+ Given the name of an environment variable with a bool value,
988
+ normalize its value to a 0 (true) or 1 (false or empty string)
989
+ return code. Return with code corresponding to the given default
990
+ value if the variable is unset.
991
+ Abort the test script if either the value of the variable or the
992
+ default are not valid bool values.
993
+
985
994
986
995
Prerequisites
987
996
-------------
Original file line number Diff line number Diff line change 15
15
#
16
16
# test_done
17
17
18
- if ! git env--helper --type=bool --default= true --exit-code GIT_TEST_GIT_DAEMON
18
+ if ! test_bool_env GIT_TEST_GIT_DAEMON true
19
19
then
20
20
skip_all=" git-daemon testing disabled (unset GIT_TEST_GIT_DAEMON to enable)"
21
21
test_done
Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ svn_cmd () {
69
69
maybe_start_httpd () {
70
70
loc=${1-svn}
71
71
72
- if git env--helper --type=bool --default= false --exit-code GIT_TEST_SVN_HTTPD
72
+ if test_bool_env GIT_TEST_SVN_HTTPD false
73
73
then
74
74
. " $TEST_DIRECTORY " /lib-httpd.sh
75
75
LIB_HTTPD_SVN=" $loc "
104
104
}
105
105
106
106
require_svnserve () {
107
- if ! git env--helper --type=bool --default= false --exit-code GIT_TEST_SVNSERVE
107
+ if ! test_bool_env GIT_TEST_SVNSERVE false
108
108
then
109
109
skip_all=' skipping svnserve test. (set $GIT_TEST_SVNSERVE to enable)'
110
110
test_done
Original file line number Diff line number Diff line change 41
41
test_done
42
42
fi
43
43
44
- if ! git env--helper --type=bool --default= true --exit-code GIT_TEST_HTTPD
44
+ if ! test_bool_env GIT_TEST_HTTPD true
45
45
then
46
46
skip_all=" Network testing disabled (unset GIT_TEST_HTTPD to enable)"
47
47
test_done
Original file line number Diff line number Diff line change @@ -917,6 +917,40 @@ test_expect_success 'test_oid can look up data for SHA-256' '
917
917
test "$hexsz" -eq 64
918
918
'
919
919
920
+ test_expect_success ' test_bool_env' '
921
+ (
922
+ sane_unset envvar &&
923
+
924
+ test_bool_env envvar true &&
925
+ ! test_bool_env envvar false &&
926
+
927
+ envvar= &&
928
+ export envvar &&
929
+ ! test_bool_env envvar true &&
930
+ ! test_bool_env envvar false &&
931
+
932
+ envvar=true &&
933
+ test_bool_env envvar true &&
934
+ test_bool_env envvar false &&
935
+
936
+ envvar=false &&
937
+ ! test_bool_env envvar true &&
938
+ ! test_bool_env envvar false &&
939
+
940
+ envvar=invalid &&
941
+ # When encountering an invalid bool value, test_bool_env
942
+ # prints its error message to the original stderr of the
943
+ # test script, hence the redirection of fd 7, and aborts
944
+ # with "exit 1", hence the subshell.
945
+ ! ( test_bool_env envvar true ) 7>err &&
946
+ grep "error: test_bool_env requires bool values" err &&
947
+
948
+ envvar=true &&
949
+ ! ( test_bool_env envvar invalid ) 7>err &&
950
+ grep "error: test_bool_env requires bool values" err
951
+ )
952
+ '
953
+
920
954
# ###############################################################
921
955
# Basics of the basics
922
956
Original file line number Diff line number Diff line change @@ -267,7 +267,7 @@ test_expect_success 'ls-remote --symref omits filtered-out matches' '
267
267
'
268
268
269
269
test_lazy_prereq GIT_DAEMON '
270
- git env--helper --type=bool --default= true --exit-code GIT_TEST_GIT_DAEMON
270
+ test_bool_env GIT_TEST_GIT_DAEMON true
271
271
'
272
272
273
273
# This test spawns a daemon, so run it only if the user would be OK with
Original file line number Diff line number Diff line change 3
3
test_description=' Test cloning a repository larger than 2 gigabyte'
4
4
. ./test-lib.sh
5
5
6
- if test -z " $ GIT_TEST_CLONE_2GB"
6
+ if ! test_bool_env GIT_TEST_CLONE_2GB false
7
7
then
8
8
say ' Skipping expensive 2GB clone test; enable it with GIT_TEST_CLONE_2GB=t'
9
9
else
Original file line number Diff line number Diff line change @@ -1186,6 +1186,34 @@ perl () {
1186
1186
command " $PERL_PATH " " $@ " 2>&7
1187
1187
} 7>&2 2>&4
1188
1188
1189
+ # Given the name of an environment variable with a bool value, normalize
1190
+ # its value to a 0 (true) or 1 (false or empty string) return code.
1191
+ #
1192
+ # test_bool_env GIT_TEST_HTTPD <default-value>
1193
+ #
1194
+ # Return with code corresponding to the given default value if the variable
1195
+ # is unset.
1196
+ # Abort the test script if either the value of the variable or the default
1197
+ # are not valid bool values.
1198
+
1199
+ test_bool_env () {
1200
+ if test $# ! = 2
1201
+ then
1202
+ BUG " test_bool_env requires two parameters (variable name and default value)"
1203
+ fi
1204
+
1205
+ git env--helper --type=bool --default=" $2 " --exit-code " $1 "
1206
+ ret=$?
1207
+ case $ret in
1208
+ 0|1) # unset or valid bool value
1209
+ ;;
1210
+ * ) # invalid bool value or something unexpected
1211
+ error >&7 " test_bool_env requires bool values both for \$ $1 and for the default fallback"
1212
+ ;;
1213
+ esac
1214
+ return $ret
1215
+ }
1216
+
1189
1217
# Exit the test suite, either by skipping all remaining tests or by
1190
1218
# exiting with an error. If our prerequisite variable $1 falls back
1191
1219
# on a default assume we were opportunistically trying to set up some
@@ -1194,7 +1222,7 @@ perl () {
1194
1222
# The error/skip message should be given by $2.
1195
1223
#
1196
1224
test_skip_or_die () {
1197
- if ! git env--helper --type=bool --default=false --exit-code $1
1225
+ if ! test_bool_env " $1 " false
1198
1226
then
1199
1227
skip_all=$2
1200
1228
test_done
Original file line number Diff line number Diff line change @@ -1406,19 +1406,19 @@ yes () {
1406
1406
# The GIT_TEST_FAIL_PREREQS code hooks into test_set_prereq(), and
1407
1407
# thus needs to be set up really early, and set an internal variable
1408
1408
# for convenience so the hot test_set_prereq() codepath doesn't need
1409
- # to call "git env--helper". Only do that work if needed by seeing if
1410
- # GIT_TEST_FAIL_PREREQS is set at all.
1409
+ # to call "git env--helper" (via test_bool_env) . Only do that work
1410
+ # if needed by seeing if GIT_TEST_FAIL_PREREQS is set at all.
1411
1411
GIT_TEST_FAIL_PREREQS_INTERNAL=
1412
1412
if test -n " $GIT_TEST_FAIL_PREREQS "
1413
1413
then
1414
- if git env--helper --type=bool --default=0 --exit-code GIT_TEST_FAIL_PREREQS
1414
+ if test_bool_env GIT_TEST_FAIL_PREREQS false
1415
1415
then
1416
1416
GIT_TEST_FAIL_PREREQS_INTERNAL=true
1417
1417
test_set_prereq FAIL_PREREQS
1418
1418
fi
1419
1419
else
1420
1420
test_lazy_prereq FAIL_PREREQS '
1421
- git env--helper --type=bool --default=0 --exit-code GIT_TEST_FAIL_PREREQS
1421
+ test_bool_env GIT_TEST_FAIL_PREREQS false
1422
1422
'
1423
1423
fi
1424
1424
@@ -1477,7 +1477,7 @@ then
1477
1477
fi
1478
1478
1479
1479
test_lazy_prereq C_LOCALE_OUTPUT '
1480
- ! git env--helper --type=bool --default=0 --exit-code GIT_TEST_GETTEXT_POISON
1480
+ ! test_bool_env GIT_TEST_GETTEXT_POISON false
1481
1481
'
1482
1482
1483
1483
if test -z " $GIT_TEST_CHECK_CACHE_TREE "
You can’t perform that action at this time.
0 commit comments