Skip to content

Commit 93a5724

Browse files
avargitster
authored andcommitted
test-lib: Add support for multiple test prerequisites
Change the test_have_prereq function in test-lib.sh to support a comma-separated list of prerequisites. This is useful for tests that need e.g. both POSIXPERM and SANITY. The implementation was stolen from Junio C Hamano and Johannes Sixt, the tests and documentation were not. See the "Tests in Cygwin" thread in May 2009 for the originals: http://thread.gmane.org/gmane.comp.version-control.git/116729/focus=118385 http://thread.gmane.org/gmane.comp.version-control.git/116729/focus=118434 Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 8ef1abe commit 93a5724

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

t/README

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,12 @@ library for your script to use.
350350
test_expect_success TTY 'git --paginate rev-list uses a pager' \
351351
' ... '
352352

353+
You can also supply a comma-separated list of prerequisites, in the
354+
rare case where your test depends on more than one:
355+
356+
test_expect_success PERL,PYTHON 'yo dawg' \
357+
' test $(perl -E 'print eval "1 +" . qx[python -c "print 2"]') == "4" '
358+
353359
- test_expect_failure [<prereq>] <message> <script>
354360

355361
This is NOT the opposite of test_expect_success, but is used

t/t0000-basic.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,23 @@ then
7373
exit 1
7474
fi
7575

76+
test_set_prereq HAVETHIS
77+
haveit=no
78+
test_expect_success HAVETHIS,HAVEIT 'test runs if prerequisites are satisfied' '
79+
test_have_prereq HAVEIT &&
80+
test_have_prereq HAVETHIS &&
81+
haveit=yes
82+
'
83+
donthaveit=yes
84+
test_expect_success HAVEIT,DONTHAVEIT 'unmet prerequisites causes test to be skipped' '
85+
donthaveit=no
86+
'
87+
if test $haveit$donthaveit != yesyes
88+
then
89+
say "bug in test framework: multiple prerequisite tags do not work reliably"
90+
exit 1
91+
fi
92+
7693
clean=no
7794
test_expect_success 'tests clean up after themselves' '
7895
test_when_finished clean=yes

t/test-lib.sh

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,20 @@ test_set_prereq () {
327327
satisfied=" "
328328

329329
test_have_prereq () {
330-
case $satisfied in
331-
*" $1 "*)
332-
: yes, have it ;;
333-
*)
334-
! : nope ;;
335-
esac
330+
# prerequisites can be concatenated with ','
331+
save_IFS=$IFS
332+
IFS=,
333+
set -- $*
334+
IFS=$save_IFS
335+
for prerequisite
336+
do
337+
case $satisfied in
338+
*" $prerequisite "*)
339+
: yes, have it ;;
340+
*)
341+
! : nope ;;
342+
esac
343+
done
336344
}
337345

338346
# You are not expected to call test_ok_ and test_failure_ directly, use

0 commit comments

Comments
 (0)