1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
package MyTests;
use strict;
use warnings;
use Test::More ();
sub import {
my $class = shift;
my $caller = caller;
no strict 'refs';
*{"${caller}::exception"} = \&exception;
local $" = ", ";
use Data::Dumper;
$Data::Dumper::Terse = 1;
@_ = Dumper(@_);
eval <<" END";
package $caller;
no strict;
use Test::More @_;
END
die $@ if $@;
}
sub exception (&) {
my ($code) = @_;
my $result;
eval {
$code->();
$result = undef;
1;
}
or do {
if ( $result = $@ ) {
# do nothing
}
else {
my $problem = defined $_ ? 'false' : 'undef';
Carp::confess("$problem exception caught by Test::Fatal::exception");
}
};
return $result;
}
1;
|