view release on metacpan or search on metacpan
examples/tools.pl view on Meta::CPAN
package Test2::Example;
use Scalar::Util qw/blessed/;
use Test2::Util qw/try/;
use Test2 qw/context run_subtest/;
use Test2::Hub::Interceptor();
use Test2::Hub::Interceptor::Terminator();
sub ok($;$@) {
my ($bool, $name, @diag) = @_;
my $ctx = context();
$ctx->ok($bool, $name, \@diag);
$ctx->release;
return $bool ? 1 : 0;
}
sub is($$;$@) {
my ($got, $want, $name, @diag) = @_;
my $ctx = context();
my $bool;
if (defined($got) && defined($want)) {
$bool = "$got" eq "$want";
}
elsif (defined($got) xor defined($want)) {
$bool = 0;
}
lib/Test2/Tools/Basic.pm view on Meta::CPAN
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();
lib/Test2/Tools/ClassicCompare.pm view on Meta::CPAN
use Test2::Compare::OrderedSubset();
use Test2::Compare::Pattern();
use Test2::Compare::Ref();
use Test2::Compare::Regex();
use Test2::Compare::Scalar();
use Test2::Compare::Set();
use Test2::Compare::String();
use Test2::Compare::Undef();
use Test2::Compare::Wildcard();
sub is($$;$@) {
my ($got, $exp, $name, @diag) = @_;
my $ctx = context();
my @caller = caller;
my $delta = compare($got, $exp, \&is_convert);
if ($delta) {
$ctx->fail($name, $delta->diag, @diag);
}
lib/Test2/Tools/Compare.pm view on Meta::CPAN
$module = 'Data::Dumper';
}
my $deparse = $Data::Dumper::Deparse;
$deparse = !!$ENV{'T2_AUTO_DEPARSE'} if exists $ENV{'T2_AUTO_DEPARSE'};
local $Data::Dumper::Deparse = $deparse;
$ctx->diag($module->Dump([$got], ['GOT']));
};
sub is($$;$@) {
my ($got, $exp, $name, @diag) = @_;
my $ctx = context();
my $delta = compare($got, $exp, \&strict_convert);
if ($delta) {
# Temporary thing.
my $count = 0;
my $implicit = 0;
my @deltas = ($delta);
lib/Test2/Tools/Compare.pm view on Meta::CPAN
sub D() {
my @caller = caller;
Test2::Compare::Custom->new(
code => sub { defined $_ ? 1 : 0 }, name => 'DEFINED', operator => 'DEFINED()',
file => $caller[1],
lines => [$caller[2]],
);
}
sub DF() {
my @caller = caller;
Test2::Compare::Custom->new(
code => sub { defined $_ && ( ! ref $_ && ! $_ ) ? 1 : 0 }, name => 'DEFINED BUT FALSE', operator => 'DEFINED() && FALSE()',
file => $caller[1],
lines => [$caller[2]],
);
}
sub DNE() {
my @caller = caller;
lib/Test2/Tools/Tiny.pm view on Meta::CPAN
use Test2::Hub::Interceptor::Terminator();
our $VERSION = '1.302222';
BEGIN { require Exporter; our @ISA = qw(Exporter) }
our @EXPORT = qw{
ok is isnt like unlike is_deeply diag note skip_all todo plan done_testing
warnings exception tests capture
};
sub ok($;$@) {
my ($bool, $name, @diag) = @_;
my $ctx = context();
return $ctx->pass_and_release($name) if $bool;
return $ctx->fail_and_release($name, @diag);
}
sub is($$;$@) {
my ($got, $want, $name, @diag) = @_;
my $ctx = context();
my $bool;
if (defined($got) && defined($want)) {
$bool = "$got" eq "$want";
}
elsif (defined($got) xor defined($want)) {
$bool = 0;
}
t/Test2/acceptance/try_it_done_testing.t view on Meta::CPAN
use Test2::API qw/context/;
sub done_testing {
my $ctx = context();
die "Test Already ended!" if $ctx->hub->ended;
$ctx->hub->finalize($ctx->trace, 1);
$ctx->release;
}
sub ok($;$) {
my ($bool, $name) = @_;
my $ctx = context();
$ctx->ok($bool, $name);
$ctx->release;
}
ok(1, "First");
ok(1, "Second");
done_testing;
t/Test2/acceptance/try_it_fork.t view on Meta::CPAN
use Test2::Util qw/CAN_REALLY_FORK/;
use Test2::IPC;
use Test2::API qw/context/;
sub plan {
my $ctx = context();
$ctx->plan(@_);
$ctx->release;
}
sub ok($;$) {
my ($bool, $name) = @_;
my $ctx = context();
$ctx->ok($bool, $name);
$ctx->release;
}
plan(0, skip_all => 'System cannot fork') unless CAN_REALLY_FORK();
plan(6);
t/Test2/acceptance/try_it_no_plan.t view on Meta::CPAN
use warnings;
use Test2::API qw/context/;
sub plan {
my $ctx = context();
$ctx->plan(@_);
$ctx->release;
}
sub ok($;$) {
my ($bool, $name) = @_;
my $ctx = context();
$ctx->ok($bool, $name);
$ctx->release;
}
plan(0, 'no_plan');
ok(1, "First");
ok(1, "Second");
t/Test2/acceptance/try_it_plan.t view on Meta::CPAN
use warnings;
use Test2::API qw/context/;
sub plan {
my $ctx = context();
$ctx->plan(@_);
$ctx->release;
}
sub ok($;$) {
my ($bool, $name) = @_;
my $ctx = context();
$ctx->ok($bool, $name);
$ctx->release;
}
plan(2);
ok(1, "First");
ok(1, "Second");
t/Test2/acceptance/try_it_threads.t view on Meta::CPAN
use Test2::Util qw/CAN_THREAD/;
use Test2::IPC;
use Test2::API qw/context/;
sub plan {
my $ctx = context();
$ctx->plan(@_);
$ctx->release;
}
sub ok($;$) {
my ($bool, $name) = @_;
my $ctx = context();
$ctx->ok($bool, $name);
$ctx->release;
}
plan(0, skip_all => 'System does not have threads') unless CAN_THREAD();
plan(6);
t/Test2/acceptance/try_it_todo.t view on Meta::CPAN
use Test2::API qw/context test2_stack/;
sub done_testing {
my $ctx = context();
die "Test Already ended!" if $ctx->hub->ended;
$ctx->hub->finalize($ctx->trace, 1);
$ctx->release;
}
sub ok($;$) {
my ($bool, $name) = @_;
my $ctx = context();
$ctx->ok($bool, $name);
$ctx->release;
}
sub diag {
my $ctx = context();
$ctx->diag( join '', @_ );
$ctx->release;
t/Test2/behavior/Taint.t view on Meta::CPAN
#!/usr/bin/env perl -T
# HARNESS-NO-FORMATTER
use Test2::API qw/context/;
sub ok($;$@) {
my ($bool, $name) = @_;
my $ctx = context();
$ctx->ok($bool, $name);
$ctx->release;
return $bool ? 1 : 0;
}
sub done_testing {
my $ctx = context();
$ctx->hub->finalize($ctx->trace, 1);
t/modules/Util/Times.t view on Meta::CPAN
use Test2::Bundle::Extended;
use Test2::Util::Times qw/render_bench/;
imported_ok qw{ render_bench };
sub TM() { 0.5 }
is(
render_bench(0, 2.123456, TM, TM, TM, TM),
"2.12346s on wallclock (0.50 usr 0.50 sys + 0.50 cusr 0.50 csys = 2.00 CPU)",
"Got benchmark with < 10 second duration"
);
is(
render_bench(0, 42.123456, TM, TM, TM, TM),
"42.1235s on wallclock (0.50 usr 0.50 sys + 0.50 cusr 0.50 csys = 2.00 CPU)",