Perl's Test::More
doesn't seem to offer built-in way to say "bail out of just this test script, and continue with the next one".
You can exit()
or die()
but it doesn't give you very useful TAP output or prove
output, just something like
t/foo.pl (Wstat: 256 Tests: 5 Failed: 0)
Non-zero exit status: 1
Parse errors: Bad plan. You planned 38 tests but ran 5.
which isn't super helpful.
If you BAIL_OUT("reason")
you get more useful output, but all tests get aborted, not just the current test script.
Is there a sensible way to print a diagnostic message that'll be seen on prove
's stderr and in the summary output when the harness exits, then jump to the next test script?
Many times I just wrap my tests inside
subtest 'name' => sub { ... }
and usereturn
inside like the following:This works, because passing tests return 'true' and failing test return 'false' and thus the 2nd part of the
or
gets evaluated.This won't break TAP, you can 'bail out' of subtest, or the entire test (if wrapped) and keep running the rest of the tests.
My use case is that if I can not instantiate a test-object to be further tested, the remaining tests in that subtest are just useless, non of those test would make sense, and I only get cluttered test reports.
You could potentially do:
to be more explicit that you do exit there.