File: MyTests.pm

package info (click to toggle)
librole-basic-perl 0.13-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 268 kB
  • ctags: 56
  • sloc: perl: 1,806; makefile: 2
file content (42 lines) | stat: -rw-r--r-- 721 bytes parent folder | download | duplicates (6)
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
package MyTests;

use strict;
use warnings;

use Test::More ();
use Try::Tiny;

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) = @_;

    return try {
        $code->();
        return undef;
    }
    catch {
        return $_ if $_;

        my $problem = defined $_ ? 'false' : 'undef';
        Carp::confess("$problem exception caught by Test::Fatal::exception");
    };
}

1;