On Jan 24, 2007, at 9:42 AM, Nik Clayton wrote:

Has anyone ever used Test::More and Fatal together?

I have a test script, where each test builds upon the work of the previous step (it's part of the Subversion Perl bindings test suite, and it checks out files, makes changes to them, commits them, and so on).

If any of these tests fails I need to abort the whole .t file (but not necessarily the entire test run, so BAIL_OUT isn't appropriate).

I thought something like:

  use Test::More;
  use Fatal qw(ok is isa_ok open print close ...);

should do the trick. Anyone used this approach before, or done anything similar?

N

I don't like that very much. The implicit die() on test functions will probably confuse subsequent readers of the code. Furthermore, I cannot believe that ALL of your tests are critical. It's better, IMHO, to explicitly mention the critical tests and abort explicitly on failure. For example, I do the following (in your case, change BAIL_OUT to die):

  use Test::More tests => 348;
  sub bail { BAIL_OUT('Failed a critical test'); }
  my $mech = Test::WWW::Mechanize->new();
  $mech->get_ok('http://localhost/', 'get home page') || bail;
  $mech->content_contains('Home');
  ...

In this example, failing to fetch HTML is clearly bad news for all subsequent tests and the C< || bail> is good self-documentation. Other tests are less critical, so should not fail.

Chris

--
Chris Dolan, Software Developer, http://www.chrisdolan.net/
Public key: http://www.chrisdolan.net/public.key
vCard: http://www.chrisdolan.net/ChrisDolan.vcf



Reply via email to