Skip to content

Commit 6233704

Browse files
committed
Merge branch 'sg/test-BUG'
test framework has been updated to make a bug in the test script (as opposed to bugs in Git that are discovered by running the tests) stand out more prominently. * sg/test-BUG: tests: send "bug in the test script" errors to the script's stderr
2 parents 152cb0c + 165293a commit 6233704

File tree

7 files changed

+26
-23
lines changed

7 files changed

+26
-23
lines changed

t/perf/perf-lib.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ test_perf_do_repo_symlink_config_ () {
8282

8383
test_perf_create_repo_from () {
8484
test "$#" = 2 ||
85-
error "bug in the test script: not 2 parameters to test-create-repo"
85+
BUG "not 2 parameters to test-create-repo"
8686
repo="$1"
8787
source="$2"
8888
source_git="$("$MODERN_GIT" -C "$source" rev-parse --git-dir)"
@@ -184,7 +184,7 @@ test_wrapper_ () {
184184
test_start_
185185
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
186186
test "$#" = 2 ||
187-
error "bug in the test script: not 2 or 3 parameters to test-expect-success"
187+
BUG "not 2 or 3 parameters to test-expect-success"
188188
export test_prereq
189189
if ! test_skip "$@"
190190
then

t/t0001-init.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,14 @@ test_lazy_prereq GETCWD_IGNORES_PERMS '
319319
base=GETCWD_TEST_BASE_DIR &&
320320
mkdir -p $base/dir &&
321321
chmod 100 $base ||
322-
error "bug in test script: cannot prepare $base"
322+
BUG "cannot prepare $base"
323323
324324
(cd $base/dir && /bin/pwd -P)
325325
status=$?
326326
327327
chmod 700 $base &&
328328
rm -rf $base ||
329-
error "bug in test script: cannot clean $base"
329+
BUG "cannot clean $base"
330330
return $status
331331
'
332332

t/t4013-diff-various.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ do
129129
case "$magic" in
130130
noellipses) ;;
131131
*)
132-
die "bug in t4103: unknown magic $magic" ;;
132+
BUG "unknown magic $magic" ;;
133133
esac ;;
134134
*)
135135
cmd="$magic $cmd" magic=

t/t5516-fetch-push.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ mk_child() {
9595

9696
check_push_result () {
9797
test $# -ge 3 ||
98-
error "bug in the test script: check_push_result requires at least 3 parameters"
98+
BUG "check_push_result requires at least 3 parameters"
9999

100100
repo_name="$1"
101101
shift

t/t9902-completion.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ test_expect_success 'teardown after ref completion' '
12491249

12501250
test_path_completion ()
12511251
{
1252-
test $# = 2 || error "bug in the test script: not 2 parameters to test_path_completion"
1252+
test $# = 2 || BUG "not 2 parameters to test_path_completion"
12531253

12541254
local cur="$1" expected="$2"
12551255
echo "$expected" >expected &&

t/test-lib-functions.sh

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -418,14 +418,14 @@ test_declared_prereq () {
418418
test_verify_prereq () {
419419
test -z "$test_prereq" ||
420420
expr >/dev/null "$test_prereq" : '[A-Z0-9_,!]*$' ||
421-
error "bug in the test script: '$test_prereq' does not look like a prereq"
421+
BUG "'$test_prereq' does not look like a prereq"
422422
}
423423

424424
test_expect_failure () {
425425
test_start_
426426
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
427427
test "$#" = 2 ||
428-
error "bug in the test script: not 2 or 3 parameters to test-expect-failure"
428+
BUG "not 2 or 3 parameters to test-expect-failure"
429429
test_verify_prereq
430430
export test_prereq
431431
if ! test_skip "$@"
@@ -445,7 +445,7 @@ test_expect_success () {
445445
test_start_
446446
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
447447
test "$#" = 2 ||
448-
error "bug in the test script: not 2 or 3 parameters to test-expect-success"
448+
BUG "not 2 or 3 parameters to test-expect-success"
449449
test_verify_prereq
450450
export test_prereq
451451
if ! test_skip "$@"
@@ -472,7 +472,7 @@ test_expect_success () {
472472
test_external () {
473473
test "$#" = 4 && { test_prereq=$1; shift; } || test_prereq=
474474
test "$#" = 3 ||
475-
error >&5 "bug in the test script: not 3 or 4 parameters to test_external"
475+
BUG "not 3 or 4 parameters to test_external"
476476
descr="$1"
477477
shift
478478
test_verify_prereq
@@ -613,7 +613,7 @@ test_path_is_missing () {
613613
test_line_count () {
614614
if test $# != 3
615615
then
616-
error "bug in the test script: not 3 parameters to test_line_count"
616+
BUG "not 3 parameters to test_line_count"
617617
elif ! test $(wc -l <"$3") "$1" "$2"
618618
then
619619
echo "test_line_count: line count for $3 !$1 $2"
@@ -793,13 +793,12 @@ test_i18ngrep () {
793793
eval "last_arg=\${$#}"
794794

795795
test -f "$last_arg" ||
796-
error "bug in the test script: test_i18ngrep requires a file" \
797-
"to read as the last parameter"
796+
BUG "test_i18ngrep requires a file to read as the last parameter"
798797

799798
if test $# -lt 2 ||
800799
{ test "x!" = "x$1" && test $# -lt 3 ; }
801800
then
802-
error "bug in the test script: too few parameters to test_i18ngrep"
801+
BUG "too few parameters to test_i18ngrep"
803802
fi
804803

805804
if test_have_prereq !C_LOCALE_OUTPUT
@@ -885,7 +884,7 @@ test_seq () {
885884
case $# in
886885
1) set 1 "$@" ;;
887886
2) ;;
888-
*) error "bug in the test script: not 1 or 2 parameters to test_seq" ;;
887+
*) BUG "not 1 or 2 parameters to test_seq" ;;
889888
esac
890889
test_seq_counter__=$1
891890
while test "$test_seq_counter__" -le "$2"
@@ -923,7 +922,7 @@ test_when_finished () {
923922
# doing so on Bash is better than nothing (the test will
924923
# silently pass on other shells).
925924
test "${BASH_SUBSHELL-0}" = 0 ||
926-
error "bug in test script: test_when_finished does nothing in a subshell"
925+
BUG "test_when_finished does nothing in a subshell"
927926
test_cleanup="{ $*
928927
} && (exit \"\$eval_ret\"); eval_ret=\$?; $test_cleanup"
929928
}
@@ -932,7 +931,7 @@ test_when_finished () {
932931
# Usage: test_create_repo <directory>
933932
test_create_repo () {
934933
test "$#" = 1 ||
935-
error "bug in the test script: not 1 parameter to test-create-repo"
934+
BUG "not 1 parameter to test-create-repo"
936935
repo="$1"
937936
mkdir -p "$repo"
938937
(
@@ -1245,7 +1244,7 @@ test_oid_cache () {
12451244

12461245
if ! expr "$k" : '[a-z0-9][a-z0-9]*$' >/dev/null
12471246
then
1248-
error 'bug in the test script: bad hash algorithm'
1247+
BUG 'bad hash algorithm'
12491248
fi &&
12501249
eval "test_oid_${k}_$tag=\"\$v\""
12511250
done
@@ -1260,7 +1259,7 @@ test_oid () {
12601259
# key-hash pair, so exit with an error.
12611260
if eval "test -z \"\${$var+set}\""
12621261
then
1263-
error "bug in the test script: undefined key '$1'" >&2
1262+
BUG "undefined key '$1'"
12641263
fi &&
12651264
eval "printf '%s' \"\${$var}\""
12661265
}

t/test-lib.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ error () {
402402
exit 1
403403
}
404404

405+
BUG () {
406+
error >&7 "bug in the test script: $*"
407+
}
408+
405409
say () {
406410
say_color info "$*"
407411
}
@@ -729,7 +733,7 @@ test_run_ () {
729733
if $(printf '%s\n' "$1" | sed -f "$GIT_BUILD_DIR/t/chainlint.sed" | grep -q '?![A-Z][A-Z]*?!') ||
730734
test "OK-117" != "$(test_eval_ "(exit 117) && $1${LF}${LF}echo OK-\$?" 3>&1)"
731735
then
732-
error "bug in the test script: broken &&-chain or run-away HERE-DOC: $1"
736+
BUG "broken &&-chain or run-away HERE-DOC: $1"
733737
fi
734738
trace=$trace_tmp
735739
fi
@@ -1231,15 +1235,15 @@ test_lazy_prereq SANITY '
12311235
chmod -w SANETESTD.1 &&
12321236
chmod -r SANETESTD.1/x &&
12331237
chmod -rx SANETESTD.2 ||
1234-
error "bug in test sript: cannot prepare SANETESTD"
1238+
BUG "cannot prepare SANETESTD"
12351239
12361240
! test -r SANETESTD.1/x &&
12371241
! rm SANETESTD.1/x && ! test -f SANETESTD.2/x
12381242
status=$?
12391243
12401244
chmod +rwx SANETESTD.1 SANETESTD.2 &&
12411245
rm -rf SANETESTD.1 SANETESTD.2 ||
1242-
error "bug in test sript: cannot clean SANETESTD"
1246+
BUG "cannot clean SANETESTD"
12431247
return $status
12441248
'
12451249

0 commit comments

Comments
 (0)