@matheusbsbs / matheus-bagliano / commits / 93a5724613
Fork 0

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>

Ævar Arnfjörð Bjarmason committed Aug 6, 2010 at 21:19 UTC 93a5724613861e6cd85964c85f2fa0891caab258
3 files changed +37 -6
t/README
+6
@@ -350,6 +350,12 @@ library for your script to use.
350 test_expect_success TTY 'git --paginate rev-list uses a pager' \
351 ' ... '
352
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 +
359 - test_expect_failure [<prereq>] <message> <script>
360
361 This is NOT the opposite of test_expect_success, but is used
t/t0000-basic.sh
+17
@@ -73,6 +73,23 @@ then
73 exit 1
74 fi
75
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 +
93 clean=no
94 test_expect_success 'tests clean up after themselves' '
95 test_when_finished clean=yes
t/test-lib.sh
+14 -6
@@ -327,12 +327,20 @@ test_set_prereq () {
327 satisfied=" "
328
329 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
344 }
345
346 # You are not expected to call test_ok_ and test_failure_ directly, use