diff options
author | Simon Bertrang <simon@cvs.openbsd.org> | 2009-05-16 21:42:59 +0000 |
---|---|---|
committer | Simon Bertrang <simon@cvs.openbsd.org> | 2009-05-16 21:42:59 +0000 |
commit | 59bc964e807242b76fde9da2faf3ca8e58685397 (patch) | |
tree | 9464e7372d5e25a3e729f4e6701d3f09e4279115 /gnu/usr.bin/perl | |
parent | bc2e6738e1d0fc17e539b955497736cc6e612179 (diff) |
import perl 5.10.1
Diffstat (limited to 'gnu/usr.bin/perl')
36 files changed, 1630 insertions, 0 deletions
diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/BEGIN_require_ok.t b/gnu/usr.bin/perl/lib/Test/Simple/t/BEGIN_require_ok.t new file mode 100644 index 00000000000..c8566ab4afa --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/BEGIN_require_ok.t @@ -0,0 +1,25 @@ +#!/usr/bin/perl -w +# $Id: BEGIN_require_ok.t,v 1.1 2009/05/16 21:42:57 simon Exp $ + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = ('../lib', 'lib'); + } + else { + unshift @INC, 't/lib'; + } +} + +use Test::More; + +my $result; +BEGIN { + eval { + require_ok("Wibble"); + }; + $result = $@; +} + +plan tests => 1; +like $result, '/^You tried to run a test without a plan/'; diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/BEGIN_use_ok.t b/gnu/usr.bin/perl/lib/Test/Simple/t/BEGIN_use_ok.t new file mode 100644 index 00000000000..c339138a82c --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/BEGIN_use_ok.t @@ -0,0 +1,29 @@ +#!/usr/bin/perl -w +# $Id: BEGIN_use_ok.t,v 1.1 2009/05/16 21:42:57 simon Exp $ + +# [rt.cpan.org 28345] +# +# A use_ok() inside a BEGIN block lacking a plan would be silently ignored. + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = ('../lib', 'lib'); + } + else { + unshift @INC, 't/lib'; + } +} + +use Test::More; + +my $result; +BEGIN { + eval { + use_ok("Wibble"); + }; + $result = $@; +} + +plan tests => 1; +like $result, '/^You tried to run a test without a plan/'; diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/Builder.t b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/Builder.t new file mode 100644 index 00000000000..0320212d83f --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/Builder.t @@ -0,0 +1,31 @@ +#!/usr/bin/perl -w +# $Id: Builder.t,v 1.1 2009/05/16 21:42:57 simon Exp $ + +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' ); diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/carp.t b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/carp.t new file mode 100644 index 00000000000..4b9fd1e631f --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/carp.t @@ -0,0 +1,33 @@ +#!/usr/bin/perl +# $Id: carp.t,v 1.1 2009/05/16 21:42:57 simon Exp $ + +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; +} diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/create.t b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/create.t new file mode 100644 index 00000000000..3ecf08f8751 --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/create.t @@ -0,0 +1,46 @@ +#!/usr/bin/perl -w +# $Id: create.t,v 1.1 2009/05/16 21:42:57 simon Exp $ + +#!perl -w + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = ('../lib', 'lib'); + } + else { + unshift @INC, 't/lib'; + } +} + +use Test::More tests => 8; +use Test::Builder; + +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->create; + + isa_ok $new_tb, 'Test::Builder'; + isnt $more_tb, $new_tb, 'Test::Builder->create makes a new object'; + + $new_tb->output("some_file"); + END { 1 while unlink "some_file" } + + $new_tb->plan(tests => 1); + $new_tb->ok(1); +} + +pass("Changing output() of new TB doesn't interfere with singleton"); + +ok open FILE, "some_file"; +is join("", <FILE>), <<OUT; +1..1 +ok 1 +OUT + +close FILE; diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/details.t b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/details.t new file mode 100644 index 00000000000..de05361fa51 --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/details.t @@ -0,0 +1,108 @@ +#!/usr/bin/perl -w +# $Id: details.t,v 1.1 2009/05/16 21:42:57 simon Exp $ + +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 $out_fh = $Test->output; +my $todo_fh = $Test->todo_output; +my $start_test = $Test->current_test + 1; +require TieOut; +tie *FH, 'TieOut'; +$Test->output(\*FH); +$Test->todo_output(\*FH); + +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->output($out_fh); +$Test->todo_output($todo_fh); + +$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 ); +} diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/has_plan.t b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/has_plan.t new file mode 100644 index 00000000000..bd21c5fbb47 --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/has_plan.t @@ -0,0 +1,24 @@ +#!/usr/bin/perl -w +# $Id: has_plan.t,v 1.1 2009/05/16 21:42:57 simon Exp $ + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = ('../lib'); + } +} + +use strict; +use Test::Builder; + +my $unplanned; + +BEGIN { + $unplanned = 'oops'; + $unplanned = Test::Builder->new->has_plan; +}; + +use Test::More tests => 2; + +is($unplanned, undef, 'no plan yet defined'); +is(Test::Builder->new->has_plan, 2, 'has fixed plan'); diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/has_plan2.t b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/has_plan2.t new file mode 100644 index 00000000000..ee760f17172 --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/has_plan2.t @@ -0,0 +1,23 @@ +#!/usr/bin/perl -w +# $Id: has_plan2.t,v 1.1 2009/05/16 21:42:57 simon Exp $ + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = '../lib'; + } +} + +use Test::More; + +BEGIN { + if( !$ENV{HARNESS_ACTIVE} && $ENV{PERL_CORE} ) { + plan skip_all => "Won't work with t/TEST"; + } +} + +use strict; +use Test::Builder; + +plan 'no_plan'; +is(Test::Builder->new->has_plan, 'no_plan', 'has no_plan'); diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/is_fh.t b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/is_fh.t new file mode 100644 index 00000000000..7c6dd2e5e1e --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/is_fh.t @@ -0,0 +1,49 @@ +#!/usr/bin/perl -w +# $Id: is_fh.t,v 1.1 2009/05/16 21:42:57 simon Exp $ + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = ('../lib', 'lib'); + } + else { + unshift @INC, 't/lib'; + } +} + +use strict; +use Test::More tests => 11; +use TieOut; + +ok( !Test::Builder->is_fh("foo"), 'string is not a filehandle' ); +ok( !Test::Builder->is_fh(''), 'empty string' ); +ok( !Test::Builder->is_fh(undef), 'undef' ); + +ok( open(FILE, '>foo') ); +END { close FILE; 1 while unlink 'foo' } + +ok( Test::Builder->is_fh(*FILE) ); +ok( Test::Builder->is_fh(\*FILE) ); +ok( Test::Builder->is_fh(*FILE{IO}) ); + +tie *OUT, 'TieOut'; +ok( Test::Builder->is_fh(*OUT) ); +ok( Test::Builder->is_fh(\*OUT) ); + +SKIP: { + skip "*TIED_HANDLE{IO} doesn't work in this perl", 1 + unless defined *OUT{IO}; + ok( Test::Builder->is_fh(*OUT{IO}) ); +} + + +package Lying::isa; + +sub isa { + my $self = shift; + my $parent = shift; + + return 1 if $parent eq 'IO::Handle'; +} + +::ok( Test::Builder->is_fh(bless {}, "Lying::isa")); diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/maybe_regex.t b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/maybe_regex.t new file mode 100644 index 00000000000..97c2afae392 --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/maybe_regex.t @@ -0,0 +1,61 @@ +#!/usr/bin/perl -w +# $Id: maybe_regex.t,v 1.1 2009/05/16 21:42:57 simon Exp $ + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = ('../lib', 'lib'); + } + else { + unshift @INC, 't/lib'; + } +} + +use strict; +use Test::More tests => 16; + +use Test::Builder; +my $Test = Test::Builder->new; + +my $r = $Test->maybe_regex(qr/^FOO$/i); +ok(defined $r, 'qr// detected'); +ok(('foo' =~ /$r/), 'qr// good match'); +ok(('bar' !~ /$r/), 'qr// bad match'); + +SKIP: { + skip "blessed regex checker added in 5.10", 3 if $] < 5.010; + + my $obj = bless qr/foo/, 'Wibble'; + my $re = $Test->maybe_regex($obj); + ok( defined $re, "blessed regex detected" ); + ok( ('foo' =~ /$re/), 'blessed qr/foo/ good match' ); + ok( ('bar' !~ /$re/), 'blessed qr/foo/ bad math' ); +} + +{ + my $r = $Test->maybe_regex('/^BAR$/i'); + ok(defined $r, '"//" detected'); + ok(('bar' =~ m/$r/), '"//" good match'); + ok(('foo' !~ m/$r/), '"//" bad match'); +}; + +{ + my $r = $Test->maybe_regex('not a regex'); + ok(!defined $r, 'non-regex detected'); +}; + + +{ + my $r = $Test->maybe_regex('/0/'); + ok(defined $r, 'non-regex detected'); + ok(('f00' =~ m/$r/), '"//" good match'); + ok(('b4r' !~ m/$r/), '"//" bad match'); +}; + + +{ + my $r = $Test->maybe_regex('m,foo,i'); + ok(defined $r, 'm,, detected'); + ok(('fOO' =~ m/$r/), '"//" good match'); + ok(('bar' !~ m/$r/), '"//" bad match'); +}; diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/no_diag.t b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/no_diag.t new file mode 100644 index 00000000000..76684398a42 --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/no_diag.t @@ -0,0 +1,9 @@ +#!/usr/bin/perl -w +# $Id: no_diag.t,v 1.1 2009/05/16 21:42:57 simon Exp $ + +use Test::More 'no_diag', tests => 2; + +pass('foo'); +diag('This should not be displayed'); + +is(Test::More->builder->no_diag, 1); diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/no_ending.t b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/no_ending.t new file mode 100644 index 00000000000..9f2623e6343 --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/no_ending.t @@ -0,0 +1,22 @@ +# $Id: no_ending.t,v 1.1 2009/05/16 21:42:57 simon Exp $ +use Test::Builder; + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = '../lib'; + } +} + +BEGIN { + my $t = Test::Builder->new; + $t->no_ending(1); +} + +use Test::More tests => 3; + +# Normally, Test::More would yell that we ran too few tests, but we +# supressed the ending diagnostics. +pass; +print "ok 2\n"; +print "ok 3\n"; diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/no_header.t b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/no_header.t new file mode 100644 index 00000000000..cc39315bb55 --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/no_header.t @@ -0,0 +1,22 @@ +# $Id: no_header.t,v 1.1 2009/05/16 21:42:57 simon Exp $ +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = '../lib'; + } +} + +use Test::Builder; + +# STDOUT must be unbuffered else our prints might come out after +# Test::More's. +$| = 1; + +BEGIN { + Test::Builder->new->no_header(1); +} + +use Test::More tests => 1; + +print "1..1\n"; +pass; diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/ok_obj.t b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/ok_obj.t new file mode 100644 index 00000000000..d0bcfb9897d --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/ok_obj.t @@ -0,0 +1,30 @@ +#!/usr/bin/perl -w +# $Id: ok_obj.t,v 1.1 2009/05/16 21:42:58 simon Exp $ + +# Testing to make sure Test::Builder doesn't accidentally store objects +# passed in as test arguments. + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = '../lib'; + } +} + +use Test::More tests => 4; + +package Foo; +my $destroyed = 0; +sub new { bless {}, shift } + +sub DESTROY { + $destroyed++; +} + +package main; + +for (1..3) { + ok(my $foo = Foo->new, 'created Foo object'); +} +is $destroyed, 3, "DESTROY called 3 times"; + diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/output.t b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/output.t new file mode 100644 index 00000000000..41748e5f1f6 --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/output.t @@ -0,0 +1,96 @@ +#!perl -w +# $Id: output.t,v 1.1 2009/05/16 21:42:58 simon Exp $ + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = ('../lib', 'lib'); + } + else { + unshift @INC, 't/lib'; + } +} +chdir 't'; + + +# Can't use Test.pm, that's a 5.005 thing. +print "1..4\n"; + +my $test_num = 1; +# Utility testing functions. +sub ok ($;$) { + my($test, $name) = @_; + my $ok = ''; + $ok .= "not " unless $test; + $ok .= "ok $test_num"; + $ok .= " - $name" if defined $name; + $ok .= "\n"; + print $ok; + $test_num++; + + return $test; +} + +use TieOut; +use Test::Builder; +my $Test = Test::Builder->new(); + +my $result; +my $tmpfile = 'foo.tmp'; +my $out = $Test->output($tmpfile); +END { 1 while unlink($tmpfile) } + +ok( defined $out ); + +print $out "hi!\n"; +close *$out; + +undef $out; +open(IN, $tmpfile) or die $!; +chomp(my $line = <IN>); +close IN; + +ok($line eq 'hi!'); + +open(FOO, ">>$tmpfile") or die $!; +$out = $Test->output(\*FOO); +$old = select *$out; +print "Hello!\n"; +close *$out; +undef $out; +select $old; +open(IN, $tmpfile) or die $!; +my @lines = <IN>; +close IN; + +ok($lines[1] =~ /Hello!/); + + + +# Ensure stray newline in name escaping works. +$out = tie *FAKEOUT, 'TieOut'; +$Test->output(\*FAKEOUT); +$Test->exported_to(__PACKAGE__); +$Test->no_ending(1); +$Test->plan(tests => 5); + +$Test->ok(1, "ok"); +$Test->ok(1, "ok\n"); +$Test->ok(1, "ok, like\nok"); +$Test->skip("wibble\nmoof"); +$Test->todo_skip("todo\nskip\n"); + +my $output = $out->read; +ok( $output eq <<OUTPUT ) || print STDERR $output; +1..5 +ok 1 - ok +ok 2 - ok +# +ok 3 - ok, like +# ok +ok 4 # skip wibble +# moof +not ok 5 # TODO & SKIP todo +# skip +# +OUTPUT diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/reset.t b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/reset.t new file mode 100644 index 00000000000..f2bc9970a98 --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/reset.t @@ -0,0 +1,90 @@ +#!/usr/bin/perl -w +# $Id: reset.t,v 1.1 2009/05/16 21:42:58 simon Exp $ + +# Test Test::Builder->reset; + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = ('../lib', 'lib'); + } + else { + unshift @INC, 't/lib'; + } +} +chdir 't'; + + +use Test::Builder; +my $tb = Test::Builder->new; + +my %Original_Output; +$Original_Output{$_} = $tb->$_ for qw(output failure_output todo_output); + + +$tb->plan(tests => 14); +$tb->level(0); + +# Alter the state of Test::Builder as much as possible. +$tb->ok(1, "Running a test to alter TB's state"); + +my $tmpfile = 'foo.tmp'; + +$tb->output($tmpfile); +$tb->failure_output($tmpfile); +$tb->todo_output($tmpfile); +END { 1 while unlink $tmpfile } + +# This won't print since we just sent output off to oblivion. +$tb->ok(0, "And a failure for fun"); + +$Test::Builder::Level = 3; + +$tb->exported_to('Foofer'); + +$tb->use_numbers(0); +$tb->no_header(1); +$tb->no_ending(1); + + +# Now reset it. +$tb->reset; + +my $test_num = 2; # since we already printed 1 +# Utility testing functions. +sub ok ($;$) { + my($test, $name) = @_; + my $ok = ''; + $ok .= "not " unless $test; + $ok .= "ok $test_num"; + $ok .= " - $name" if defined $name; + $ok .= "\n"; + print $ok; + $test_num++; + + return $test; +} + + +ok( !defined $tb->exported_to, 'exported_to' ); +ok( $tb->expected_tests == 0, 'expected_tests' ); +ok( $tb->level == 1, 'level' ); +ok( $tb->use_numbers == 1, 'use_numbers' ); +ok( $tb->no_header == 0, 'no_header' ); +ok( $tb->no_ending == 0, 'no_ending' ); +ok( fileno $tb->output == fileno $Original_Output{output}, + 'output' ); +ok( fileno $tb->failure_output == fileno $Original_Output{failure_output}, + 'failure_output' ); +ok( fileno $tb->todo_output == fileno $Original_Output{todo_output}, + 'todo_output' ); +ok( $tb->current_test == 0, 'current_test' ); +ok( $tb->summary == 0, 'summary' ); +ok( $tb->details == 0, 'details' ); + +$tb->no_ending(1); +$tb->no_header(1); +$tb->plan(tests => 14); +$tb->current_test(13); +$tb->level(0); +$tb->ok(1, 'final test to make sure output was reset'); diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/try.t b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/try.t new file mode 100644 index 00000000000..658c4ed7d67 --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/Builder/try.t @@ -0,0 +1,43 @@ +#!perl -w +# $Id: try.t,v 1.1 2009/05/16 21:42:58 simon Exp $ + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = ('../lib', 'lib'); + } + else { + unshift @INC, 't/lib'; + } +} + +use strict; + +use Test::More 'no_plan'; + +require Test::Builder; +my $tb = Test::Builder->new; + + +# Test that _try() has no effect on $@ and $! and is not effected by +# __DIE__ +{ + local $SIG{__DIE__} = sub { fail("DIE handler called: @_") }; + local $@ = 42; + local $! = 23; + + is $tb->_try(sub { 2 }), 2; + is $tb->_try(sub { return '' }), ''; + + is $tb->_try(sub { die; }), undef; + + is_deeply [$tb->_try(sub { die "Foo\n" })], [undef, "Foo\n"]; + + is $@, 42; + cmp_ok $!, '==', 23; +} + +ok !eval { + $tb->_try(sub { die "Died\n" }, die_on_fail => 1); +}; +is $@, "Died\n"; diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/Tester/tbt_01basic.t b/gnu/usr.bin/perl/lib/Test/Simple/t/Tester/tbt_01basic.t new file mode 100644 index 00000000000..174a4498af8 --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/Tester/tbt_01basic.t @@ -0,0 +1,56 @@ +#!/usr/bin/perl +# $Id: tbt_01basic.t,v 1.1 2009/05/16 21:42:58 simon Exp $ + +use Test::Builder::Tester tests => 9; +use Test::More; + +ok(1,"This is a basic test"); + +test_out("ok 1 - tested"); +ok(1,"tested"); +test_test("captured okay on basic"); + +test_out("ok 1 - tested"); +ok(1,"tested"); +test_test("captured okay again without changing number"); + +ok(1,"test unrelated to Test::Builder::Tester"); + +test_out("ok 1 - one"); +test_out("ok 2 - two"); +ok(1,"one"); +ok(2,"two"); +test_test("multiple tests"); + +test_out("not ok 1 - should fail"); +test_err("# Failed test ($0 at line 29)"); +test_err("# got: 'foo'"); +test_err("# expected: 'bar'"); +is("foo","bar","should fail"); +test_test("testing failing"); + + +test_out("not ok 1"); +test_out("not ok 2"); +test_fail(+2); +test_fail(+1); +fail(); fail(); +test_test("testing failing on the same line with no name"); + + +test_out("not ok 1 - name"); +test_out("not ok 2 - name"); +test_fail(+2); +test_fail(+1); +fail("name"); fail("name"); +test_test("testing failing on the same line with the same name"); + + +test_out("not ok 1 - name # TODO Something"); +test_err("# Failed (TODO) test ($0 at line 53)"); +TODO: { + local $TODO = "Something"; + fail("name"); +} +test_test("testing failing with todo"); + diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/Tester/tbt_02fhrestore.t b/gnu/usr.bin/perl/lib/Test/Simple/t/Tester/tbt_02fhrestore.t new file mode 100644 index 00000000000..360730aef95 --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/Tester/tbt_02fhrestore.t @@ -0,0 +1,59 @@ +#!/usr/bin/perl +# $Id: tbt_02fhrestore.t,v 1.1 2009/05/16 21:42:58 simon Exp $ + +use Test::Builder::Tester tests => 4; +use Test::More; +use Symbol; + +# create temporary file handles that still point indirectly +# to the right place + +my $orig_o = gensym; +my $orig_t = gensym; +my $orig_f = gensym; + +tie *$orig_o, "My::Passthru", \*STDOUT; +tie *$orig_t, "My::Passthru", \*STDERR; +tie *$orig_f, "My::Passthru", \*STDERR; + +# redirect the file handles to somewhere else for a mo + +use Test::Builder; +my $t = Test::Builder->new(); + +$t->output($orig_o); +$t->failure_output($orig_f); +$t->todo_output($orig_t); + +# run a test + +test_out("ok 1 - tested"); +ok(1,"tested"); +test_test("standard test okay"); + +# now check that they were restored okay + +ok($orig_o == $t->output(), "output file reconnected"); +ok($orig_t == $t->todo_output(), "todo output file reconnected"); +ok($orig_f == $t->failure_output(), "failure output file reconnected"); + +##################################################################### + +package My::Passthru; + +sub PRINT { + my $self = shift; + my $handle = $self->[0]; + print $handle @_; +} + +sub TIEHANDLE { + my $class = shift; + my $self = [shift()]; + return bless $self, $class; +} + +sub READ {} +sub READLINE {} +sub GETC {} +sub FILENO {} diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/Tester/tbt_03die.t b/gnu/usr.bin/perl/lib/Test/Simple/t/Tester/tbt_03die.t new file mode 100644 index 00000000000..e9c29cfeb13 --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/Tester/tbt_03die.t @@ -0,0 +1,13 @@ +#!/usr/bin/perl +# $Id: tbt_03die.t,v 1.1 2009/05/16 21:42:58 simon Exp $ + +use Test::Builder::Tester tests => 1; +use Test::More; + +eval { + test_test("foo"); +}; +like($@, + "/Not testing\. You must declare output with a test function first\./", + "dies correctly on error"); + diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/Tester/tbt_04line_num.t b/gnu/usr.bin/perl/lib/Test/Simple/t/Tester/tbt_04line_num.t new file mode 100644 index 00000000000..8713ac4a30d --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/Tester/tbt_04line_num.t @@ -0,0 +1,9 @@ +#!/usr/bin/perl +# $Id: tbt_04line_num.t,v 1.1 2009/05/16 21:42:58 simon Exp $ + +use Test::More tests => 3; +use Test::Builder::Tester; + +is(line_num(),7,"normal line num"); +is(line_num(-1),7,"line number minus one"); +is(line_num(+2),11,"line number plus two"); diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/Tester/tbt_05faildiag.t b/gnu/usr.bin/perl/lib/Test/Simple/t/Tester/tbt_05faildiag.t new file mode 100644 index 00000000000..a4887c0b4eb --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/Tester/tbt_05faildiag.t @@ -0,0 +1,45 @@ +#!/usr/bin/perl +# $Id: tbt_05faildiag.t,v 1.1 2009/05/16 21:42:58 simon Exp $ + +use Test::Builder::Tester tests => 5; +use Test::More; + +# test_fail + +test_out("not ok 1 - one"); +test_fail(+1); +ok(0,"one"); + +test_out("not ok 2 - two"); +test_fail(+2); + +ok(0,"two"); + +test_test("test fail"); + +test_fail(+2); +test_out("not ok 1 - one"); +ok(0,"one"); +test_test("test_fail first"); + +# test_diag + +use Test::Builder; +my $test = new Test::Builder; + +test_diag("this is a test string","so is this"); +$test->diag("this is a test string\n", "so is this\n"); +test_test("test diag"); + +test_diag("this is a test string","so is this"); +$test->diag("this is a test string\n"); +$test->diag("so is this\n"); +test_test("test diag multi line"); + +test_diag("this is a test string"); +test_diag("so is this"); +$test->diag("this is a test string\n"); +$test->diag("so is this\n"); +test_test("test diag multiple"); + + diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/Tester/tbt_06errormess.t b/gnu/usr.bin/perl/lib/Test/Simple/t/Tester/tbt_06errormess.t new file mode 100644 index 00000000000..f8f20bdd53b --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/Tester/tbt_06errormess.t @@ -0,0 +1,121 @@ +#!/usr/bin/perl -w +# $Id: tbt_06errormess.t,v 1.1 2009/05/16 21:42:58 simon Exp $ + +use Test::More tests => 8; +use Symbol; +use Test::Builder; +use Test::Builder::Tester; + +use strict; + +# argh! now we need to test the thing we're testing. Basically we need +# to pretty much reimplement the whole code again. This is very +# annoying but can't be avoided. And onwards with the cut and paste + +# My brain is melting. My brain is melting. ETOOMANYLAYERSOFTESTING + +# create some private file handles +my $output_handle = gensym; +my $error_handle = gensym; + +# and tie them to this package +my $out = tie *$output_handle, "Test::Builder::Tester::Tie", "STDOUT"; +my $err = tie *$error_handle, "Test::Builder::Tester::Tie", "STDERR"; + +# ooooh, use the test suite +my $t = Test::Builder->new; + +# remember the testing outputs +my $original_output_handle; +my $original_failure_handle; +my $original_todo_handle; +my $original_harness_env; +my $testing_num; + +sub start_testing +{ + # remember what the handles were set to + $original_output_handle = $t->output(); + $original_failure_handle = $t->failure_output(); + $original_todo_handle = $t->todo_output(); + $original_harness_env = $ENV{HARNESS_ACTIVE}; + + # switch out to our own handles + $t->output($output_handle); + $t->failure_output($error_handle); + $t->todo_output($error_handle); + + $ENV{HARNESS_ACTIVE} = 0; + + # clear the expected list + $out->reset(); + $err->reset(); + + # remeber that we're testing + $testing_num = $t->current_test; + $t->current_test(0); +} + +# each test test is actually two tests. This is bad and wrong +# but makes blood come out of my ears if I don't at least simplify +# it a little this way + +sub my_test_test +{ + my $text = shift; + local $^W = 0; + + # reset the outputs + $t->output($original_output_handle); + $t->failure_output($original_failure_handle); + $t->todo_output($original_todo_handle); + $ENV{HARNESS_ACTIVE} = $original_harness_env; + + # reset the number of tests + $t->current_test($testing_num); + + # check we got the same values + my $got; + my $wanted; + + # stdout + $t->ok($out->check, "STDOUT $text"); + + # stderr + $t->ok($err->check, "STDERR $text"); +} + +#################################################################### +# Meta meta tests +#################################################################### + +# this is a quick test to check the hack that I've just implemented +# actually does a cut down version of Test::Builder::Tester + +start_testing(); +$out->expect("ok 1 - foo"); +pass("foo"); +my_test_test("basic meta meta test"); + +start_testing(); +$out->expect("not ok 1 - foo"); +$err->expect("# Failed test ($0 at line ".line_num(+1).")"); +fail("foo"); +my_test_test("basic meta meta test 2"); + +start_testing(); +$out->expect("ok 1 - bar"); +test_out("ok 1 - foo"); +pass("foo"); +test_test("bar"); +my_test_test("meta meta test with tbt"); + +start_testing(); +$out->expect("ok 1 - bar"); +test_out("not ok 1 - foo"); +test_err("# Failed test ($0 at line ".line_num(+1).")"); +fail("foo"); +test_test("bar"); +my_test_test("meta meta test with tbt2 "); + +#################################################################### diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/Tester/tbt_07args.t b/gnu/usr.bin/perl/lib/Test/Simple/t/Tester/tbt_07args.t new file mode 100644 index 00000000000..2fa02fa7504 --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/Tester/tbt_07args.t @@ -0,0 +1,216 @@ +#!/usr/bin/perl -w +# $Id: tbt_07args.t,v 1.1 2009/05/16 21:42:58 simon Exp $ + +use Test::More tests => 18; +use Symbol; +use Test::Builder; +use Test::Builder::Tester; + +use strict; + +# argh! now we need to test the thing we're testing. Basically we need +# to pretty much reimplement the whole code again. This is very +# annoying but can't be avoided. And onwards with the cut and paste + +# My brain is melting. My brain is melting. ETOOMANYLAYERSOFTESTING + +# create some private file handles +my $output_handle = gensym; +my $error_handle = gensym; + +# and tie them to this package +my $out = tie *$output_handle, "Test::Builder::Tester::Tie", "STDOUT"; +my $err = tie *$error_handle, "Test::Builder::Tester::Tie", "STDERR"; + +# ooooh, use the test suite +my $t = Test::Builder->new; + +# remember the testing outputs +my $original_output_handle; +my $original_failure_handle; +my $original_todo_handle; +my $testing_num; +my $original_harness_env; + +sub start_testing +{ + # remember what the handles were set to + $original_output_handle = $t->output(); + $original_failure_handle = $t->failure_output(); + $original_todo_handle = $t->todo_output(); + $original_harness_env = $ENV{HARNESS_ACTIVE}; + + # switch out to our own handles + $t->output($output_handle); + $t->failure_output($error_handle); + $t->todo_output($error_handle); + + $ENV{HARNESS_ACTIVE} = 0; + + # clear the expected list + $out->reset(); + $err->reset(); + + # remeber that we're testing + $testing_num = $t->current_test; + $t->current_test(0); +} + +# each test test is actually two tests. This is bad and wrong +# but makes blood come out of my ears if I don't at least simplify +# it a little this way + +sub my_test_test +{ + my $text = shift; + local $^W = 0; + + # reset the outputs + $t->output($original_output_handle); + $t->failure_output($original_failure_handle); + $t->todo_output($original_todo_handle); + $ENV{HARNESS_ACTIVE} = $original_harness_env; + + # reset the number of tests + $t->current_test($testing_num); + + # check we got the same values + my $got; + my $wanted; + + # stdout + $t->ok($out->check, "STDOUT $text"); + + # stderr + $t->ok($err->check, "STDERR $text"); +} + +#################################################################### +# Meta meta tests +#################################################################### + +# this is a quick test to check the hack that I've just implemented +# actually does a cut down version of Test::Builder::Tester + +start_testing(); +$out->expect("ok 1 - foo"); +pass("foo"); +my_test_test("basic meta meta test"); + +start_testing(); +$out->expect("not ok 1 - foo"); +$err->expect("# Failed test ($0 at line ".line_num(+1).")"); +fail("foo"); +my_test_test("basic meta meta test 2"); + +start_testing(); +$out->expect("ok 1 - bar"); +test_out("ok 1 - foo"); +pass("foo"); +test_test("bar"); +my_test_test("meta meta test with tbt"); + +start_testing(); +$out->expect("ok 1 - bar"); +test_out("not ok 1 - foo"); +test_err("# Failed test ($0 at line ".line_num(+1).")"); +fail("foo"); +test_test("bar"); +my_test_test("meta meta test with tbt2 "); + +#################################################################### +# Actual meta tests +#################################################################### + +# set up the outer wrapper again +start_testing(); +$out->expect("ok 1 - bar"); + +# set up what the inner wrapper expects +test_out("ok 1 - foo"); + +# the actual test function that we are testing +ok("1","foo"); + +# test the name +test_test(name => "bar"); + +# check that passed +my_test_test("meta test name"); + +#################################################################### + +# set up the outer wrapper again +start_testing(); +$out->expect("ok 1 - bar"); + +# set up what the inner wrapper expects +test_out("ok 1 - foo"); + +# the actual test function that we are testing +ok("1","foo"); + +# test the name +test_test(title => "bar"); + +# check that passed +my_test_test("meta test title"); + +#################################################################### + +# set up the outer wrapper again +start_testing(); +$out->expect("ok 1 - bar"); + +# set up what the inner wrapper expects +test_out("ok 1 - foo"); + +# the actual test function that we are testing +ok("1","foo"); + +# test the name +test_test(label => "bar"); + +# check that passed +my_test_test("meta test title"); + +#################################################################### + +# set up the outer wrapper again +start_testing(); +$out->expect("ok 1 - bar"); + +# set up what the inner wrapper expects +test_out("not ok 1 - foo this is wrong"); +test_fail(+3); + +# the actual test function that we are testing +ok("0","foo"); + +# test that we got what we expect, ignoring our is wrong +test_test(skip_out => 1, name => "bar"); + +# check that that passed +my_test_test("meta test skip_out"); + +#################################################################### + +# set up the outer wrapper again +start_testing(); +$out->expect("ok 1 - bar"); + +# set up what the inner wrapper expects +test_out("not ok 1 - foo"); +test_err("this is wrong"); + +# the actual test function that we are testing +ok("0","foo"); + +# test that we got what we expect, ignoring err is wrong +test_test(skip_err => 1, name => "bar"); + +# diagnostics failing out +# check that that passed +my_test_test("meta test skip_err"); + +#################################################################### diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/c_flag.t b/gnu/usr.bin/perl/lib/Test/Simple/t/c_flag.t new file mode 100644 index 00000000000..a33963415ed --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/c_flag.t @@ -0,0 +1,21 @@ +#!/usr/bin/perl -w + +# Test::More should not print anything when Perl is only doing +# a compile as with the -c flag or B::Deparse or perlcc. + +# HARNESS_ACTIVE=1 was causing an error with -c +{ + local $ENV{HARNESS_ACTIVE} = 1; + local $^C = 1; + + require Test::More; + Test::More->import(tests => 1); + + fail("This should not show up"); +} + +Test::More->builder->no_ending(1); + +print "1..1\n"; +print "ok 1\n"; + diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/died.t b/gnu/usr.bin/perl/lib/Test/Simple/t/died.t new file mode 100644 index 00000000000..d8f317ddd95 --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/died.t @@ -0,0 +1,46 @@ +#!perl -w +# $Id: died.t,v 1.1 2009/05/16 21:42:57 simon Exp $ + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = '../lib'; + } +} + +# Can't use Test.pm, that's a 5.005 thing. +package My::Test; + +# This has to be a require or else the END block below runs before +# Test::Builder's own and the ending diagnostics don't come out right. +require Test::Builder; +my $TB = Test::Builder->create; +$TB->plan(tests => 3); + + +package main; + +require Test::Simple; + +chdir 't'; +push @INC, '../t/lib/'; +require Test::Simple::Catch; +my($out, $err) = Test::Simple::Catch::caught(); +local $ENV{HARNESS_ACTIVE} = 0; + +Test::Simple->import(tests => 1); +exit 250; + +END { + $TB->is_eq($out->read, <<OUT); +1..1 +OUT + + $TB->is_eq($err->read, <<ERR); +# Looks like your test exited with 250 before it could output anything. +ERR + + $TB->is_eq($?, 250, "exit code"); + + exit grep { !$_ } $TB->summary; +} diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/dont_overwrite_die_handler.t b/gnu/usr.bin/perl/lib/Test/Simple/t/dont_overwrite_die_handler.t new file mode 100644 index 00000000000..356a8470323 --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/dont_overwrite_die_handler.t @@ -0,0 +1,20 @@ +#!/usr/bin/perl -w +# $Id: dont_overwrite_die_handler.t,v 1.1 2009/05/16 21:42:57 simon Exp $ + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = '../lib'; + } +} + +# Make sure this is in place before Test::More is loaded. +my $handler_called; +BEGIN { + $SIG{__DIE__} = sub { $handler_called++ }; +} + +use Test::More tests => 2; + +ok !eval { die }; +is $handler_called, 1, 'existing DIE handler not overridden'; diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/explain.t b/gnu/usr.bin/perl/lib/Test/Simple/t/explain.t new file mode 100644 index 00000000000..6be781ca28c --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/explain.t @@ -0,0 +1,28 @@ +#!/usr/bin/perl -w +# $Id: explain.t,v 1.1 2009/05/16 21:42:57 simon Exp $ + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = ('../lib', 'lib'); + } + else { + unshift @INC, 't/lib'; + } +} + +use strict; +use warnings; + +use Test::More tests => 5; + +can_ok "main", "explain"; + +is_deeply [explain("foo")], ["foo"]; +is_deeply [explain("foo", "bar")], ["foo", "bar"]; + +# Avoid future dump formatting changes from breaking tests by just eval'ing +# the dump +is_deeply [map { eval $_ } explain([], {})], [[], {}]; + +is_deeply [map { eval $_ } explain(23, [42,91], 99)], [23, [42, 91], 99]; diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/lib/NoExporter.pm b/gnu/usr.bin/perl/lib/Test/Simple/t/lib/NoExporter.pm new file mode 100644 index 00000000000..5d60b315e72 --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/lib/NoExporter.pm @@ -0,0 +1,12 @@ +package NoExporter; +# $Id: NoExporter.pm,v 1.1 2009/05/16 21:42:58 simon Exp $ + +$VERSION = 1.02; + +sub import { + shift; + die "NoExporter exports nothing. You asked for: @_" if @_; +} + +1; + diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/lib/SigDie.pm b/gnu/usr.bin/perl/lib/Test/Simple/t/lib/SigDie.pm new file mode 100644 index 00000000000..f954e2db785 --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/lib/SigDie.pm @@ -0,0 +1,6 @@ +package SigDie; + +use vars qw($DIE); +$SIG{__DIE__} = sub { $DIE = $@ }; + +1; diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/new_ok.t b/gnu/usr.bin/perl/lib/Test/Simple/t/new_ok.t new file mode 100644 index 00000000000..d53f535d1c0 --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/new_ok.t @@ -0,0 +1,42 @@ +#!/usr/bin/perl -w + +use strict; + +use Test::More tests => 13; + +{ + package Bar; + + sub new { + my $class = shift; + return bless {@_}, $class; + } + + + package Foo; + our @ISA = qw(Bar); +} + +{ + my $obj = new_ok("Foo"); + is_deeply $obj, {}; + isa_ok $obj, "Foo"; + + $obj = new_ok("Bar"); + is_deeply $obj, {}; + isa_ok $obj, "Bar"; + + $obj = new_ok("Foo", [this => 42]); + is_deeply $obj, { this => 42 }; + isa_ok $obj, "Foo"; + + $obj = new_ok("Foo", [], "Foo"); + is_deeply $obj, {}; + isa_ok $obj, "Foo"; +} + +# And what if we give it nothing? +eval { + new_ok(); +}; +is $@, sprintf "new_ok() must be given at least a class at %s line %d.\n", $0, __LINE__ - 2; diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/no_tests.t b/gnu/usr.bin/perl/lib/Test/Simple/t/no_tests.t new file mode 100644 index 00000000000..278ebc32189 --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/no_tests.t @@ -0,0 +1,45 @@ +#!perl -w +# $Id: no_tests.t,v 1.1 2009/05/16 21:42:57 simon Exp $ + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = '../lib'; + } +} + +# Can't use Test.pm, that's a 5.005 thing. +package My::Test; + +# This has to be a require or else the END block below runs before +# Test::Builder's own and the ending diagnostics don't come out right. +require Test::Builder; +my $TB = Test::Builder->create; +$TB->plan(tests => 3); + + +package main; + +require Test::Simple; + +chdir 't'; +push @INC, '../t/lib/'; +require Test::Simple::Catch; +my($out, $err) = Test::Simple::Catch::caught(); +local $ENV{HARNESS_ACTIVE} = 0; + +Test::Simple->import(tests => 1); + +END { + $TB->is_eq($out->read, <<OUT); +1..1 +OUT + + $TB->is_eq($err->read, <<ERR); +# No tests run! +ERR + + $TB->is_eq($?, 255, "exit code"); + + exit grep { !$_ } $TB->summary; +} diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/note.t b/gnu/usr.bin/perl/lib/Test/Simple/t/note.t new file mode 100644 index 00000000000..55646e2a6fb --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/note.t @@ -0,0 +1,36 @@ +#!/usr/bin/perl -w +# $Id: note.t,v 1.1 2009/05/16 21:42:57 simon Exp $ + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = ('../lib', 'lib'); + } + else { + unshift @INC, 't/lib'; + } +} + +use strict; +use warnings; + +use TieOut; + +use Test::More tests => 2; + +{ + my $test = Test::More->builder; + + my $output = tie *FAKEOUT, "TieOut"; + my $fail_output = tie *FAKEERR, "TieOut"; + $test->output (*FAKEOUT); + $test->failure_output(*FAKEERR); + + note("foo"); + + $test->reset_outputs; + + is $output->read, "# foo\n"; + is $fail_output->read, ''; +} + diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/tbm_doesnt_set_exported_to.t b/gnu/usr.bin/perl/lib/Test/Simple/t/tbm_doesnt_set_exported_to.t new file mode 100644 index 00000000000..94ee4e0bd33 --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/tbm_doesnt_set_exported_to.t @@ -0,0 +1,25 @@ +#!/usr/bin/perl -w +# $Id: tbm_doesnt_set_exported_to.t,v 1.1 2009/05/16 21:42:57 simon Exp $ + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = '../lib'; + } +} + +use strict; +use warnings; + +# Can't use Test::More, that would set exported_to() +use Test::Builder; +use Test::Builder::Module; + +my $TB = Test::Builder->create; +$TB->plan( tests => 1 ); +$TB->level(0); + +$TB->is_eq( Test::Builder::Module->builder->exported_to, + undef, + 'using Test::Builder::Module does not set exported_to()' +); diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/utf8.t b/gnu/usr.bin/perl/lib/Test/Simple/t/utf8.t new file mode 100644 index 00000000000..8c205ef029f --- /dev/null +++ b/gnu/usr.bin/perl/lib/Test/Simple/t/utf8.t @@ -0,0 +1,70 @@ +#!/usr/bin/perl -w +# $Id: utf8.t,v 1.1 2009/05/16 21:42:57 simon Exp $ + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = '../lib'; + } +} + +use strict; +use warnings; + +use Test::More skip_all => 'Not yet implemented'; + +my $have_perlio; +BEGIN { + # All together so Test::More sees the open discipline + $have_perlio = eval q[ + use PerlIO; + use open ':std', ':locale'; + use Test::More; + 1; + ]; +} + +use Test::More; + +if( !$have_perlio ) { + plan skip_all => "Don't have PerlIO"; +} +else { + plan tests => 5; +} + +SKIP: { + skip( "Need PerlIO for this feature", 3 ) + unless $have_perlio; + + my %handles = ( + output => \*STDOUT, + failure_output => \*STDERR, + todo_output => \*STDOUT + ); + + for my $method (keys %handles) { + my $src = $handles{$method}; + + my $dest = Test::More->builder->$method; + + is_deeply { map { $_ => 1 } PerlIO::get_layers($dest) }, + { map { $_ => 1 } PerlIO::get_layers($src) }, + "layers copied to $method"; + } +} + +SKIP: { + skip( "Can't test in general because their locale is unknown", 2 ) + unless $ENV{AUTHOR_TESTING}; + + my $uni = "\x{11e}"; + + my @warnings; + local $SIG{__WARN__} = sub { + push @warnings, @_; + }; + + is( $uni, $uni, "Testing $uni" ); + is_deeply( \@warnings, [] ); +} diff --git a/gnu/usr.bin/perl/t/lib/Test/Simple/sample_tests/death_with_handler.plx b/gnu/usr.bin/perl/t/lib/Test/Simple/sample_tests/death_with_handler.plx new file mode 100644 index 00000000000..935ab36ac70 --- /dev/null +++ b/gnu/usr.bin/perl/t/lib/Test/Simple/sample_tests/death_with_handler.plx @@ -0,0 +1,19 @@ +require Test::Simple; +# $Id: death_with_handler.plx,v 1.1 2009/05/16 21:42:58 simon Exp $ + +push @INC, 't/lib'; +require Test::Simple::Catch; +my($out, $err) = Test::Simple::Catch::caught(); + +Test::Simple->import(tests => 2); + +# Test we still get the right exit code despite having a die +# handler. +$SIG{__DIE__} = sub {}; + +require Dev::Null; +tie *STDERR, 'Dev::Null'; + +ok(1); +ok(1); +die "This is a test"; |