test: validate prerequistes syntax
Brian Carson noticed that a test piece in t5601 had a pair of single quotes in the body, which made it into 4 parameter call to test_expect_success, as if its test title were a prerequisite. As the prerequisites have a specific syntax (i.e. comma separated tokens spelled in capital letters, possibly prefixed with ! for negation), validate them to catch such a mistake in the future. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Apr 26, 2015 at 15:18 UTC
d93d5d51e3d104f4466f2081dd45b9670dc28744
1 file changed
+9
t/test-lib-functions.sh
+9
@@ -348,11 +348,18 @@ test_declared_prereq () {
348
return 1
349
}
350
351
+test_verify_prereq () {
352
+ test -z "$test_prereq" ||
353
+ expr >/dev/null "$test_prereq" : '[A-Z0-9_,!]*$' ||
354
+ error "bug in the test script: '$test_prereq' does not look like a prereq"
355
+}
356
+
357
test_expect_failure () {
358
test_start_
359
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
360
test "$#" = 2 ||
361
error "bug in the test script: not 2 or 3 parameters to test-expect-failure"
362
+ test_verify_prereq
363
export test_prereq
364
if ! test_skip "$@"
365
then
@@ -372,6 +379,7 @@ test_expect_success () {
379
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
380
test "$#" = 2 ||
381
error "bug in the test script: not 2 or 3 parameters to test-expect-success"
382
+ test_verify_prereq
383
export test_prereq
384
if ! test_skip "$@"
385
then
@@ -400,6 +408,7 @@ test_external () {
408
error >&5 "bug in the test script: not 3 or 4 parameters to test_external"
409
descr="$1"
410
shift
411
+ test_verify_prereq
412
export test_prereq
413
if ! test_skip "$descr" "$@"
414
then