* Ovid <publiustemp-perl...@yahoo.com> [2012-04-11 16:35]:
>     my $ok;
>     END { BAIL_OUT "Could not load all modules" unless $ok }
      [...]
>     ok 1, 'All modules loaded successfully';
>     $ok = 1;

Ah d’uh! Now I feel stupid.

This could so easily be packaged in a handful of lines:

    package Test::AutoBailOut;
    use parent 'Test::Builder::Module';
    sub _tb { __PACKAGE__->builder }

    my $reason = 'Tests must succeeded';
    sub import {
        my %arg = @_;
        $reason = $arg{'reason'} if exists $arg{'reason'};
    }

    my $ok;
    sub no_bailout ($) { _tb->ok( $ok = 1, @_ ) }
    END { _tb->BAIL_OUT( $reason ) unless $ok }

    @EXPORT = 'no_bailout';

Then you simply do this:

    use Test::More tests => 1;
    use Test::AutoBailOut reason => 'Could not load prerequisites';
    use Config;

    use Test::Trap::Builder::TempFile;
    use Test::Trap::Builder::SystemSafe;
    use Test::Trap::Builder;
    use Test::Trap;
    use if $Config{'useperlio'}, 'Test::Trap::Builder::PerlIO';

    no_bailout 'All prerequisites loaded';

Dead simple. Huge swathes of complexity, *puff* – vanished.

Schwern, care to ship that in Test::More to deprecate `use_ok`? :)

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

Reply via email to