diff options
-rw-r--r-- | t/README | 6 | ||||
-rwxr-xr-x | t/t0000-basic.sh | 17 | ||||
-rw-r--r-- | t/test-lib.sh | 20 |
3 files changed, 37 insertions, 6 deletions
@@ -350,6 +350,12 @@ library for your script to use. test_expect_success TTY 'git --paginate rev-list uses a pager' \ ' ... ' + You can also supply a comma-separated list of prerequisites, in the + rare case where your test depends on more than one: + + test_expect_success PERL,PYTHON 'yo dawg' \ + ' test $(perl -E 'print eval "1 +" . qx[python -c "print 2"]') == "4" ' + - test_expect_failure [<prereq>] <message> <script> This is NOT the opposite of test_expect_success, but is used diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index f2c73369a5..2887677391 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -73,6 +73,23 @@ then exit 1 fi +test_set_prereq HAVETHIS +haveit=no +test_expect_success HAVETHIS,HAVEIT 'test runs if prerequisites are satisfied' ' + test_have_prereq HAVEIT && + test_have_prereq HAVETHIS && + haveit=yes +' +donthaveit=yes +test_expect_success HAVEIT,DONTHAVEIT 'unmet prerequisites causes test to be skipped' ' + donthaveit=no +' +if test $haveit$donthaveit != yesyes +then + say "bug in test framework: multiple prerequisite tags do not work reliably" + exit 1 +fi + clean=no test_expect_success 'tests clean up after themselves' ' test_when_finished clean=yes diff --git a/t/test-lib.sh b/t/test-lib.sh index 5467cc626b..0b9969ccf7 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -327,12 +327,20 @@ test_set_prereq () { satisfied=" " test_have_prereq () { - case $satisfied in - *" $1 "*) - : yes, have it ;; - *) - ! : nope ;; - esac + # prerequisites can be concatenated with ',' + save_IFS=$IFS + IFS=, + set -- $* + IFS=$save_IFS + for prerequisite + do + case $satisfied in + *" $prerequisite "*) + : yes, have it ;; + *) + ! : nope ;; + esac + done } # You are not expected to call test_ok_ and test_failure_ directly, use |