247
git update-index --add "--chmod=$@"
248
}
249
250
+# Use test_set_prereq to tell that a particular prerequisite is available.
251
+# The prerequisite can later be checked for in two ways:
252
+#
253
+# - Explicitly using test_have_prereq.
254
+#
255
+# - Implicitly by specifying the prerequisite tag in the calls to
256
+# test_expect_{success,failure,code}.
257
+#
258
+# The single parameter is the prerequisite tag (a simple word, in all
259
+# capital letters by convention).
260
+
261
+test_set_prereq () {
262
+ satisfied="$satisfied$1 "
263
+}
264
+satisfied=" "
265
+
266
+test_have_prereq () {
267
+ case $satisfied in
268
+ *" $1 "*)
269
+ : yes, have it ;;
270
+ *)
271
+ ! : nope ;;
272
+ esac
273
+}
274
+
275
# You are not expected to call test_ok_ and test_failure_ directly, use
276
# the text_expect_* functions instead.
277
318
to_skip=t
319
esac
320
done
321
+ if test -z "$to_skip" && test -n "$prereq" &&
322
+ ! test_have_prereq "$prereq"
323
+ then
324
+ to_skip=t
325
+ fi
326
case "$to_skip" in
327
t)
328
say_color skip >&3 "skipping test: $@"
336
}
337
338
test_expect_failure () {
339
+ test "$#" = 3 && { prereq=$1; shift; } || prereq=
340
test "$#" = 2 ||
310
- error "bug in the test script: not 2 parameters to test-expect-failure"
341
+ error "bug in the test script: not 2 or 3 parameters to test-expect-failure"
342
if ! test_skip "$@"
343
then
344
say >&3 "checking known breakage: $2"
354
}
355
356
test_expect_success () {
357
+ test "$#" = 3 && { prereq=$1; shift; } || prereq=
358
test "$#" = 2 ||
327
- error "bug in the test script: not 2 parameters to test-expect-success"
359
+ error "bug in the test script: not 2 or 3 parameters to test-expect-success"
360
if ! test_skip "$@"
361
then
362
say >&3 "expecting success: $2"
372
}
373
374
test_expect_code () {
375
+ test "$#" = 4 && { prereq=$1; shift; } || prereq=
376
test "$#" = 3 ||
344
- error "bug in the test script: not 3 parameters to test-expect-code"
377
+ error "bug in the test script: not 3 or 4 parameters to test-expect-code"
378
if ! test_skip "$@"
379
then
380
say >&3 "expecting exit code $1: $3"
398
# Usage: test_external description command arguments...
399
# Example: test_external 'Perl API' perl ../path/to/test.pl
400
test_external () {
368
- test "$#" -eq 3 ||
369
- error >&5 "bug in the test script: not 3 parameters to test_external"
401
+ test "$#" = 4 && { prereq=$1; shift; } || prereq=
402
+ test "$#" = 3 ||
403
+ error >&5 "bug in the test script: not 3 or 4 parameters to test_external"
404
descr="$1"
405
shift
406
if ! test_skip "$descr" "$@"