| Current Path : /home/emeraadmin/www/4d695/ |
| Current File : /home/emeraadmin/www/4d695/perl-Test-Simple.zip |
PK 1��\���4� � examples/indent.plnu �[��� #!/usr/bin/env perl
use strict;
use warnings;
use lib '../lib';
use Test::Builder;
=head1 NOTES
Must have explicit finalize
Must name nest
Trailing summary test
Pass chunk o'TAP
No builder may have more than one child active
What happens if you call ->finalize with open children
=cut
my $builder = Test::Builder->new;
$builder->plan(tests => 7);
for( 1 .. 3 ) {
$builder->ok( $_, "We're on $_" );
$builder->note("We ran $_");
}
{
my $indented = $builder->child;
$indented->plan('no_plan');
for( 1 .. 1+int(rand(5)) ) {
$indented->ok( 1, "We're on $_" );
}
$indented->finalize;
}
for( 7, 8, 9 ) {
$builder->ok( $_, "We're on $_" );
}
PK 1��\��W\ \ examples/subtest.tnu �[��� #!/usr/bin/env perl
use strict;
use warnings;
use lib '../lib';
use Test::More tests => 3;
ok 1;
subtest 'some name' => sub {
my $num_tests = 2 + int( rand(3) );
plan tests => $num_tests;
ok 1 for 1 .. $num_tests - 1;
subtest 'some name' => sub {
plan 'no_plan';
ok 1 for 1 .. 2 + int( rand(3) );
};
};
ok 1;
PK 1��\�w�Z� � examples/tools.plnu �[��� 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;
}
else { # Both are undef
$bool = 1;
}
unless ($bool) {
$got = '*NOT DEFINED*' unless defined $got;
$want = '*NOT DEFINED*' unless defined $want;
unshift @diag => (
"GOT: $got",
"EXPECTED: $want",
);
}
$ctx->ok($bool, $name, \@diag);
$ctx->release;
return $bool;
}
sub isnt($$;$@) {
my ($got, $want, $name, @diag) = @_;
my $ctx = context();
my $bool;
if (defined($got) && defined($want)) {
$bool = "$got" ne "$want";
}
elsif (defined($got) xor defined($want)) {
$bool = 1;
}
else { # Both are undef
$bool = 0;
}
unshift @diag => "Strings are the same (they should not be)"
unless $bool;
$ctx->ok($bool, $name, \@diag);
$ctx->release;
return $bool;
}
sub like($$;$@) {
my ($thing, $pattern, $name, @diag) = @_;
my $ctx = context();
my $bool;
if (defined($thing)) {
$bool = "$thing" =~ $pattern;
unshift @diag => (
"Value: $thing",
"Does not match: $pattern"
) unless $bool;
}
else {
$bool = 0;
unshift @diag => "Got an undefined value.";
}
$ctx->ok($bool, $name, \@diag);
$ctx->release;
return $bool;
}
sub unlike($$;$@) {
my ($thing, $pattern, $name, @diag) = @_;
my $ctx = context();
my $bool;
if (defined($thing)) {
$bool = "$thing" !~ $pattern;
unshift @diag => (
"Unexpected pattern match (it should not match)",
"Value: $thing",
"Matches: $pattern"
) unless $bool;
}
else {
$bool = 0;
unshift @diag => "Got an undefined value.";
}
$ctx->ok($bool, $name, \@diag);
$ctx->release;
return $bool;
}
sub diag {
my $ctx = context();
$ctx->diag( join '', @_ );
$ctx->release;
}
sub note {
my $ctx = context();
$ctx->note( join '', @_ );
$ctx->release;
}
sub skip_all {
my ($reason) = @_;
my $ctx = context();
$ctx->plan(0, SKIP => $reason);
$ctx->release if $ctx;
}
sub plan {
my ($max) = @_;
my $ctx = context();
$ctx->plan($max);
$ctx->release;
}
sub done_testing {
my $ctx = context();
$ctx->done_testing;
$ctx->release;
}
sub subtest {
my ($name, $code) = @_;
my $ctx = context();
my $bool = run_subtest($name, $code, 1);
$ctx->release;
return $bool;
}
1;
PK 1��\�\: : examples/tools.tnu �[��� use strict;
use warnings;
use Test2::IPC;
BEGIN { require "t/tools.pl" };
use Test2::API qw/context intercept test2_stack/;
ok(__PACKAGE__->can($_), "imported '$_\()'") for qw{
ok
is isnt
like unlike
diag note
is_deeply
warnings
exception
plan
skip_all
done_testing
};
ok(1, "'ok' Test");
is("foo", "foo", "'is' test");
is(undef, undef, "'is' undef test");
isnt("foo", "bar", "'isnt' test");
isnt("foo", undef, "'isnt' undef test 1");
isnt(undef, "foo", "'isnt' undef test 2");
like("foo", qr/o/, "'like' test");
unlike("foo", qr/a/, "'unlike' test");
diag("Testing Diag");
note("Testing Note");
my $str = "abc";
is_deeply(
{ a => 1, b => 2, c => { ref => \$str, obj => bless({x => 1}, 'XXX'), array => [1, 2, 3]}},
{ a => 1, b => 2, c => { ref => \$str, obj => {x => 1}, array => [1, 2, 3]}},
"'is_deeply' test"
);
is_deeply(
warnings { warn "aaa\n"; warn "bbb\n" },
[ "aaa\n", "bbb\n" ],
"Got warnings"
);
is_deeply(
warnings { 1 },
[],
"no warnings"
);
is(exception { die "foo\n" }, "foo\n", "got exception");
is(exception { 1 }, undef, "no exception");
my $events = intercept {
plan 8;
ok(0, "'ok' Test");
is("foo", "bar", "'is' test");
isnt("foo", "foo", "'isnt' test");
like("foo", qr/a/, "'like' test");
unlike("foo", qr/o/, "'unlike' test");
diag("Testing Diag");
note("Testing Note");
is_deeply(
{ a => 1, b => 2, c => {}},
{ a => 1, b => 2, c => []},
"'is_deeply' test"
);
};
is(@$events, 9, "got 9 events");
my ($plan, $ok, $is, $isnt, $like, $unlike, $diag, $note, $is_deeply) = @$events;
ok($plan->isa('Test2::Event::Plan'), "got plan");
is($plan->max, 8, "planned for 8 oks");
ok($ok->isa('Test2::Event::Ok'), "got 'ok' result");
is($ok->pass, 0, "'ok' test failed");
ok($is->isa('Test2::Event::Ok'), "got 'is' result");
is($is->pass, 0, "'is' test failed");
ok($isnt->isa('Test2::Event::Ok'), "got 'isnt' result");
is($isnt->pass, 0, "'isnt' test failed");
ok($like->isa('Test2::Event::Ok'), "got 'like' result");
is($like->pass, 0, "'like' test failed");
ok($unlike->isa('Test2::Event::Ok'), "got 'unlike' result");
is($unlike->pass, 0, "'unlike' test failed");
ok($is_deeply->isa('Test2::Event::Ok'), "got 'is_deeply' result");
is($is_deeply->pass, 0, "'is_deeply' test failed");
ok($diag->isa('Test2::Event::Diag'), "got 'diag' result");
is($diag->message, "Testing Diag", "got diag message");
ok($note->isa('Test2::Event::Note'), "got 'note' result");
is($note->message, "Testing Note", "got note message");
$events = intercept {
skip_all 'because';
ok(0, "should not see me");
die "should not happen";
};
is(@$events, 1, "1 event");
ok($events->[0]->isa('Test2::Event::Plan'), "got plan");
is($events->[0]->directive, 'SKIP', "plan is skip");
is($events->[0]->reason, 'because', "skip reason");
$events = intercept {
is(undef, "");
is("", undef);
isnt(undef, undef);
like(undef, qr//);
unlike(undef, qr//);
};
is(@$events, 5, "5 events");
ok(!$_->pass, "undef test - should not pass") for @$events;
sub tool { context() };
my %params;
my $ctx = context(level => -1);
my $ictx;
$events = intercept {
%params = @_;
$ictx = tool();
$ictx->ok(1, 'pass');
$ictx->ok(0, 'fail');
my $trace = Test2::Context::Trace->new(
frame => [ __PACKAGE__, __FILE__, __LINE__],
);
$ictx->hub->finalize($trace, 1);
};
is_deeply(
\%params,
{
context => $ctx,
hub => $ictx->hub,
},
"Passed in some useful params"
);
ok($ctx != $ictx, "Different context inside intercept");
is(@$events, 3, "got 3 events");
$ctx->release;
$ictx->release;
# Test that a bail-out in an intercept does not exit.
$events = intercept {
$ictx = tool();
$ictx->bail("The world ends");
$ictx->ok(0, "Should not see this");
};
is(@$events, 1, "got 1 event");
ok($events->[0]->isa('Test2::Event::Bail'), "got the bail");
$events = intercept {
$ictx = tool();
};
$ictx->release;
like(
exception { intercept { die 'foo' } },
qr/foo/,
"Exception was propogated"
);
$events = intercept {
test2_stack()->top->set_no_ending(0);
ok(1);
};
is(@$events, 2, "2 events");
ok($events->[0]->isa('Test2::Event::Ok'), "got ok");
ok($events->[1]->isa('Test2::Event::Plan'), "finalize was called");
$events = intercept {
test2_stack()->top->set_no_ending(0);
ok(1);
done_testing;
};
is(@$events, 2, "2 events");
ok($events->[0]->isa('Test2::Event::Ok'), "got ok");
ok($events->[1]->isa('Test2::Event::Plan'), "finalize was called (only 1 plan)");
done_testing;
PK 1��\
��nl l t/Legacy/Bugs/600.tnu �[��� use Test2::API qw/intercept/;
use Test::More;
my $TEST = Test::Builder->new();
sub fake {
$TEST->use_numbers(0);
$TEST->no_ending(1);
$TEST->done_testing(1); # a computed number of tests from its deferred magic
}
my $events = intercept { fake() };
is(@$events, 1, "only 1 event");
is($events->[0]->max, 1, "Plan set to 1, not 0");
done_testing;
PK 1��\,�nC� � t/Legacy/Bugs/629.tnu �[��� use strict;
use warnings;
use Test::More;
use Test2::API qw/intercept/;
my @warnings;
intercept {
SKIP: {
local $SIG{__WARN__} = sub { @warnings = @_ };
skip 'Skipping this test' if 1;
my $var = 'abc';
is $var, 'abc';
}
};
ok(!@warnings, "did not warn when waiting for done_testing");
intercept {
SKIP: {
local $SIG{__WARN__} = sub { @warnings = @_ };
plan 'no_plan';
skip 'Skipping this test' if 1;
my $var = 'abc';
is $var, 'abc';
}
};
ok(!@warnings, "did not warn with 'no_plan'");
intercept {
SKIP: {
local $SIG{__WARN__} = sub { @warnings = @_ };
plan tests => 1;
skip 'Skipping this test' if 1;
my $var = 'abc';
is $var, 'abc';
}
};
is(@warnings, 1, "warned with static plan");
like(
$warnings[0],
qr/skip\(\) needs to know \$how_many tests are in the block/,
"Got expected warning"
);
done_testing;
PK 1��\��͏ � t/Legacy/Builder/Builder.tnu �[��� #!/usr/bin/perl -w
# HARNESS-NO-STREAM
BEGIN {
if( $ENV{PERL_CORE} ) {
chdir 't';
@INC = '../lib';
}
}
use Test::Builder;
my $Test = Test::Builder->new;
$Test->plan( tests => 7 );
my $default_lvl = $Test->level;
$Test->level(0);
$Test->ok( 1, 'compiled and new()' );
$Test->ok( $default_lvl == 1, 'level()' );
$Test->is_eq('foo', 'foo', 'is_eq');
$Test->is_num('23.0', '23', 'is_num');
$Test->is_num( $Test->current_test, 4, 'current_test() get' );
my $test_num = $Test->current_test + 1;
$Test->current_test( $test_num );
print "ok $test_num - current_test() set\n";
$Test->ok( 1, 'counter still good' );
PK 1��\�
|VK K t/Legacy/Builder/carp.tnu �[��� #!/usr/bin/perl
BEGIN {
if( $ENV{PERL_CORE} ) {
chdir 't';
@INC = '../lib';
}
}
use Test::More tests => 3;
use Test::Builder;
my $tb = Test::Builder->create;
sub foo { $tb->croak("foo") }
sub bar { $tb->carp("bar") }
eval { foo() };
is $@, sprintf "foo at %s line %s.\n", $0, __LINE__ - 1;
eval { $tb->croak("this") };
is $@, sprintf "this at %s line %s.\n", $0, __LINE__ - 1;
{
my $warning = '';
local $SIG{__WARN__} = sub {
$warning .= join '', @_;
};
bar();
is $warning, sprintf "bar at %s line %s.\n", $0, __LINE__ - 1;
}
PK 1��\دL�2 2 t/Legacy/Builder/create.tnu �[��� #!/usr/bin/perl -w
BEGIN {
if( $ENV{PERL_CORE} ) {
chdir 't';
@INC = ('../lib', 'lib');
}
else {
unshift @INC, 't/lib';
}
}
use Test::More tests => 7;
use Test::Builder;
use Test::Builder::NoOutput;
my $more_tb = Test::More->builder;
isa_ok $more_tb, 'Test::Builder';
is $more_tb, Test::More->builder, 'create does not interfere with ->builder';
is $more_tb, Test::Builder->new, ' does not interfere with ->new';
{
my $new_tb = Test::Builder::NoOutput->create;
isa_ok $new_tb, 'Test::Builder';
isnt $more_tb, $new_tb, 'Test::Builder->create makes a new object';
$new_tb->plan(tests => 1);
$new_tb->ok(1, "a test");
is $new_tb->read, <<'OUT';
1..1
ok 1 - a test
OUT
}
pass("Changing output() of new TB doesn't interfere with singleton");
PK 1��\R��F t/Legacy/Builder/current_test.tnu �[��� #!/usr/bin/perl -w
# Dave Rolsky found a bug where if current_test() is used and no
# tests are run via Test::Builder it will blow up.
use Test::Builder;
$TB = Test::Builder->new;
$TB->plan(tests => 2);
print "ok 1\n";
print "ok 2\n";
$TB->current_test(2);
PK 1��\�p�*� � , t/Legacy/Builder/current_test_without_plan.tnu �[��� #!/usr/bin/perl -w
# Test that current_test() will work without a declared plan.
use Test::Builder;
my $tb = Test::Builder->new;
$tb->current_test(2);
print <<'END';
ok 1
ok 2
END
$tb->ok(1, "Third test");
$tb->done_testing(3);
PK 1��\ �|� � t/Legacy/Builder/details.tnu �[��� #!/usr/bin/perl -w
# HARNESS-NO-STREAM
BEGIN {
if( $ENV{PERL_CORE} ) {
chdir 't';
@INC = ('../lib', 'lib');
}
else {
unshift @INC, 't/lib';
}
}
use Test::More;
use Test::Builder;
my $Test = Test::Builder->new;
$Test->plan( tests => 9 );
$Test->level(0);
my @Expected_Details;
$Test->is_num( scalar $Test->summary(), 0, 'no tests yet, no summary' );
push @Expected_Details, { 'ok' => 1,
actual_ok => 1,
name => 'no tests yet, no summary',
type => '',
reason => ''
};
# Inline TODO tests will confuse pre 1.20 Test::Harness, so we
# should just avoid the problem and not print it out.
my $start_test = $Test->current_test + 1;
my $output = '';
$Test->output(\$output);
$Test->todo_output(\$output);
SKIP: {
$Test->skip( 'just testing skip' );
}
push @Expected_Details, { 'ok' => 1,
actual_ok => 1,
name => '',
type => 'skip',
reason => 'just testing skip',
};
TODO: {
local $TODO = 'i need a todo';
$Test->ok( 0, 'a test to todo!' );
push @Expected_Details, { 'ok' => 1,
actual_ok => 0,
name => 'a test to todo!',
type => 'todo',
reason => 'i need a todo',
};
$Test->todo_skip( 'i need both' );
}
push @Expected_Details, { 'ok' => 1,
actual_ok => 0,
name => '',
type => 'todo_skip',
reason => 'i need both'
};
for ($start_test..$Test->current_test) { print "ok $_\n" }
$Test->reset_outputs;
$Test->is_num( scalar $Test->summary(), 4, 'summary' );
push @Expected_Details, { 'ok' => 1,
actual_ok => 1,
name => 'summary',
type => '',
reason => '',
};
$Test->current_test(6);
print "ok 6 - current_test incremented\n";
push @Expected_Details, { 'ok' => 1,
actual_ok => undef,
name => undef,
type => 'unknown',
reason => 'incrementing test number',
};
my @details = $Test->details();
$Test->is_num( scalar @details, 6,
'details() should return a list of all test details');
$Test->level(1);
is_deeply( \@details, \@Expected_Details );
# This test has to come last because it thrashes the test details.
{
my $curr_test = $Test->current_test;
$Test->current_test(4);
my @details = $Test->details();
$Test->current_test($curr_test);
$Test->is_num( scalar @details, 4 );
}
PK 1��\ �I�� � t/Legacy/Builder/done_testing.tnu �[��� #!/usr/bin/perl -w
use strict;
use Test::Builder;
my $tb = Test::Builder->new;
$tb->level(0);
$tb->ok(1, "testing done_testing() with no arguments");
$tb->ok(1, " another test so we're not testing just one");
$tb->done_testing();
PK 1��\+x� � &