Skip to content

Commit 2859079

Browse files
committed
Merge branch 'fs/test-prereq'
The test framework learns to list unsatisfied test prerequisites, and optionally error out when prerequisites that are expected to be satisfied are not. * fs/test-prereq: test-lib: make BAIL_OUT() work in tests and prereq test-lib: introduce required prereq for test runs test-lib: show missing prereq summary
2 parents f346fcb + a671408 commit 2859079

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

t/README

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,12 @@ explicitly providing repositories when accessing submodule objects is
466466
complete or needs to be abandoned for whatever reason (in which case the
467467
migrated codepaths still retain their performance benefits).
468468

469+
GIT_TEST_REQUIRE_PREREQ=<list> allows specifying a space speparated list of
470+
prereqs that are required to succeed. If a prereq in this list is triggered by
471+
a test and then fails then the whole test run will abort. This can help to make
472+
sure the expected tests are executed and not silently skipped when their
473+
dependency breaks or is simply not present in a new environment.
474+
469475
Naming Tests
470476
------------
471477

t/aggregate-results.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ success=0
66
failed=0
77
broken=0
88
total=0
9+
missing_prereq=
910

1011
while read file
1112
do
@@ -30,10 +31,26 @@ do
3031
broken=$(($broken + $value)) ;;
3132
total)
3233
total=$(($total + $value)) ;;
34+
missing_prereq)
35+
missing_prereq="$missing_prereq,$value" ;;
3336
esac
3437
done <"$file"
3538
done
3639

40+
if test -n "$missing_prereq"
41+
then
42+
unique_missing_prereq=$(
43+
echo $missing_prereq |
44+
tr -s "," "\n" |
45+
grep -v '^$' |
46+
sort -u |
47+
paste -s -d ' ')
48+
if test -n "$unique_missing_prereq"
49+
then
50+
printf "\nmissing prereq: $unique_missing_prereq\n\n"
51+
fi
52+
fi
53+
3754
if test -n "$failed_tests"
3855
then
3956
printf "\nfailed test(s):$failed_tests\n\n"

t/test-lib-functions.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,17 @@ test_have_prereq () {
680680
# Keep a list of missing prerequisites; restore
681681
# the negative marker if necessary.
682682
prerequisite=${negative_prereq:+!}$prerequisite
683+
684+
# Abort if this prereq was marked as required
685+
if test -n "$GIT_TEST_REQUIRE_PREREQ"
686+
then
687+
case " $GIT_TEST_REQUIRE_PREREQ " in
688+
*" $prerequisite "*)
689+
BAIL_OUT "required prereq $prerequisite failed"
690+
;;
691+
esac
692+
fi
693+
683694
if test -z "$missing_prereq"
684695
then
685696
missing_prereq=$prerequisite

t/test-lib.sh

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,15 @@ USER_TERM="$TERM"
589589
TERM=dumb
590590
export TERM USER_TERM
591591

592+
# What is written by tests to stdout and stderr is sent to different places
593+
# depending on the test mode (e.g. /dev/null in non-verbose mode, piped to tee
594+
# with --tee option, etc.). We save the original stdin to FD #6 and stdout and
595+
# stderr to #5 and #7, so that the test framework can use them (e.g. for
596+
# printing errors within the test framework) independently of the test mode.
597+
exec 5>&1
598+
exec 6<&0
599+
exec 7>&2
600+
592601
_error_exit () {
593602
finalize_junit_xml
594603
GIT_EXIT_OK=t
@@ -612,7 +621,7 @@ BAIL_OUT () {
612621
local bail_out="Bail out! "
613622
local message="$1"
614623

615-
say_color error $bail_out "$message"
624+
say_color >&5 error $bail_out "$message"
616625
_error_exit
617626
}
618627

@@ -637,9 +646,6 @@ then
637646
exit 0
638647
fi
639648

640-
exec 5>&1
641-
exec 6<&0
642-
exec 7>&2
643649
if test "$verbose_log" = "t"
644650
then
645651
exec 3>>"$GIT_TEST_TEE_OUTPUT_FILE" 4>&3
@@ -669,6 +675,8 @@ test_fixed=0
669675
test_broken=0
670676
test_success=0
671677

678+
test_missing_prereq=
679+
672680
test_external_has_tap=0
673681

674682
die () {
@@ -1069,6 +1077,14 @@ test_skip () {
10691077
of_prereq=" of $test_prereq"
10701078
fi
10711079
skipped_reason="missing $missing_prereq${of_prereq}"
1080+
1081+
# Keep a list of all the missing prereq for result aggregation
1082+
if test -z "$missing_prereq"
1083+
then
1084+
test_missing_prereq=$missing_prereq
1085+
else
1086+
test_missing_prereq="$test_missing_prereq,$missing_prereq"
1087+
fi
10721088
fi
10731089

10741090
case "$to_skip" in
@@ -1175,6 +1191,7 @@ test_done () {
11751191
fixed $test_fixed
11761192
broken $test_broken
11771193
failed $test_failure
1194+
missing_prereq $test_missing_prereq
11781195
11791196
EOF
11801197
fi

0 commit comments

Comments
 (0)