Test-Simple
view release on metacpan or search on metacpan
lib/Test2/Tools/Basic.pm view on Meta::CPAN
package Test2::Tools::Basic;
use strict;
use warnings;
our $VERSION = '1.302222';
use Carp qw/croak/;
use Test2::API qw/context/;
our @EXPORT = qw{
ok pass fail diag note todo skip
plan skip_all done_testing bail_out
};
use base 'Exporter';
sub ok($;$@) {
my ($bool, $name, @diag) = @_;
my $ctx = context();
$ctx->ok($bool, $name, \@diag);
$ctx->release;
return $bool ? 1 : 0;
}
sub pass {
my ($name) = @_;
my $ctx = context();
$ctx->ok(1, $name);
$ctx->release;
return 1;
}
sub fail {
my ($name, @diag) = @_;
my $ctx = context();
$ctx->ok(0, $name, \@diag);
$ctx->release;
return 0;
}
sub diag {
my $ctx = context();
$ctx->diag( join '', grep { defined $_ } @_ );
$ctx->release;
return 0;
}
sub note {
my $ctx = context();
$ctx->note( join '', grep { defined $_ } @_ );
$ctx->release;
}
sub todo {
my $reason = shift;
my $code = shift;
require Test2::Todo unless $INC{'Test2/Todo.pm'};
my $todo = Test2::Todo->new(reason => $reason);
return $code->() if $code;
croak "Cannot use todo() in a void context without a codeblock"
unless defined wantarray;
return $todo;
}
sub skip {
my ($why, $num) = @_;
$num ||= 1;
my $ctx = context();
$ctx->skip("skipped test", $why) for 1 .. $num;
$ctx->release;
no warnings 'exiting';
last SKIP;
}
( run in 0.409 second using v1.01-cache-2.11-cpan-524268b4103 )