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