Test-Exception-LessClever
view release on metacpan or search on metacpan
lib/Test/Exception/LessClever.pm view on Meta::CPAN
return ( 0, $msg );
}
}
=item lives_ok( sub { ... }, $name )
Test passes if the sub does not die, false if it does.
=cut
sub lives_ok(&;$) {
my ( $code, $name ) = @_;
my $ok = live_or_die( $code );
$TB->ok( $ok, $name );
return $ok;
}
=item dies_ok( sub { ... }, $name )
Test passes if the sub dies, false if it does not.
=cut
sub dies_ok(&;$) {
my ( $code, $name ) = @_;
my $ok = live_or_die( $code );
$TB->ok( !$ok, $name );
return !$ok;
}
=item throws_ok( sub { ... }, qr/message/, $name )
Check that the sub dies, and that it throws an error that matches the regex.
Test fails is the sub does not die, or if the message does not match the regex.
=cut
sub throws_ok(&$;$) {
my ( $code, $reg, $name ) = @_;
my ( $ok, $msg ) = live_or_die( $code );
my ( $pkg, $file, $number ) = caller;
# If we lived
if ( $ok ) {
$TB->diag( "Test did not die as expected at $file line $number." );
return $TB->ok( !$ok, $name );
}
lib/Test/Exception/LessClever.pm view on Meta::CPAN
}
=item lives_and( sub {...}, $name )
Fails with $name if the sub dies, otherwise is passive. This is useful for
running a test that could die. If it dies there is a failure, if it lives it is
responsible for itself.
=cut
sub lives_and(&;$) {
my ( $code, $name ) = @_;
my ( $ok, $msg )= live_or_die( $code );
my ( $pkg, $file, $number ) = caller;
chomp( $msg );
$msg =~ s/\n/ /g;
$TB->diag( "Test unexpectedly died: '$msg' at $file line $number." ) unless $ok;
$TB->ok( $ok, $name ) if !$ok;
return $ok;
}
( run in 0.729 second using v1.01-cache-2.11-cpan-49f99fa48dc )