summaryrefslogtreecommitdiff
path: root/t/lib/TestUtils.pm
blob: c66b8b33da3e3ba6557ed75925c4d4d64764101c (plain)
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
use 5.006;
use strict;
use warnings;
package TestUtils;

use Carp;

use Exporter;
our @ISA = qw/Exporter/;
our @EXPORT = qw(
    exception
);

# If we have Test::FailWarnings, use it
BEGIN {
    eval { require Test::FailWarnings; 1 } and do { Test::FailWarnings->import };
}

sub exception(&) {
    my $code = shift;
    my $success = eval { $code->(); 1 };
    my $err = $@;
    return '' if $success;
    croak "Execution died, but the error was lost" unless $@;
    return $@;
}

1;