diff options
Diffstat (limited to 't/lib/TestUtils.pm')
-rw-r--r-- | t/lib/TestUtils.pm | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/t/lib/TestUtils.pm b/t/lib/TestUtils.pm new file mode 100644 index 0000000..c66b8b3 --- /dev/null +++ b/t/lib/TestUtils.pm @@ -0,0 +1,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; |