File: TestUtils.pm

package info (click to toggle)
libclass-tiny-perl 1.008-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 284 kB
  • sloc: perl: 442; makefile: 2
file content (28 lines) | stat: -rw-r--r-- 486 bytes parent folder | download | duplicates (4)
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;