diff options
author | Nicholas Clark <nick@ccl4.org> | 2008-08-26 13:29:49 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2008-08-26 13:29:49 +0000 |
commit | 6dcddb8726532c0ca8ed36e0327e2ff80954f12c (patch) | |
tree | ab28eccd60d4f775a9745317a81c552ce2b02ef8 /ext | |
parent | 45f2a18c3b37907ac3044fb3fe75b6bb198022a5 (diff) | |
download | perl-6dcddb8726532c0ca8ed36e0327e2ff80954f12c.tar.gz |
Move all of Test::Harness's test modules into ext/Test/Harness/t/lib
p4raw-id: //depot/perl@34229
Diffstat (limited to 'ext')
24 files changed, 428 insertions, 10 deletions
diff --git a/ext/Test/Harness/t/compat/inc_taint.t b/ext/Test/Harness/t/compat/inc_taint.t index bdb0d73e19..234dca0ee9 100644 --- a/ext/Test/Harness/t/compat/inc_taint.t +++ b/ext/Test/Harness/t/compat/inc_taint.t @@ -3,7 +3,7 @@ BEGIN { if ( $ENV{PERL_CORE} ) { chdir 't'; - @INC = ( '../lib', 'lib' ); + @INC = ( '../lib', '../ext/Test/Harness/t/lib' ); } else { use lib 't/lib'; diff --git a/ext/Test/Harness/t/grammar.t b/ext/Test/Harness/t/grammar.t index f1521ede5e..d880f1b41d 100644 --- a/ext/Test/Harness/t/grammar.t +++ b/ext/Test/Harness/t/grammar.t @@ -5,7 +5,7 @@ use strict; BEGIN { if ( $ENV{PERL_CORE} ) { chdir 't'; - @INC = ( '../lib', 'lib' ); + @INC = ( '../lib', '../ext/Test/Harness/t/lib' ); } else { unshift @INC, 't/lib'; diff --git a/ext/Test/Harness/t/harness.t b/ext/Test/Harness/t/harness.t index 716ea59f02..32b91627b8 100644 --- a/ext/Test/Harness/t/harness.t +++ b/ext/Test/Harness/t/harness.t @@ -3,7 +3,7 @@ BEGIN { if ( $ENV{PERL_CORE} ) { chdir 't'; - @INC = ( '../lib', 'lib' ); + @INC = ( '../lib', '../ext/Test/Harness/t/lib' ); } else { unshift @INC, 't/lib'; diff --git a/ext/Test/Harness/t/lib/App/Prove/Plugin/Dummy.pm b/ext/Test/Harness/t/lib/App/Prove/Plugin/Dummy.pm new file mode 100644 index 0000000000..7e285bdc7f --- /dev/null +++ b/ext/Test/Harness/t/lib/App/Prove/Plugin/Dummy.pm @@ -0,0 +1,7 @@ +package App::Prove::Plugin::Dummy; + +sub import { + main::test_log_import(@_); +} + +1; diff --git a/ext/Test/Harness/t/lib/Dev/Null.pm b/ext/Test/Harness/t/lib/Dev/Null.pm new file mode 100644 index 0000000000..09ca5d6627 --- /dev/null +++ b/ext/Test/Harness/t/lib/Dev/Null.pm @@ -0,0 +1,18 @@ +# For shutting up Test::Harness. +# Has to work on 5.004 which doesn't have Tie::StdHandle. +package Dev::Null; + +sub WRITE { } +sub PRINT { } +sub PRINTF { } + +sub TIEHANDLE { + my $class = shift; + my $fh = do { local *HANDLE; \*HANDLE }; + return bless $fh, $class; +} +sub READ { } +sub READLINE { } +sub GETC { } + +1; diff --git a/ext/Test/Harness/t/lib/EmptyParser.pm b/ext/Test/Harness/t/lib/EmptyParser.pm new file mode 100644 index 0000000000..2f7ec2428e --- /dev/null +++ b/ext/Test/Harness/t/lib/EmptyParser.pm @@ -0,0 +1,30 @@ +package EmptyParser; + +use strict; +use vars qw(@ISA); + +use TAP::Parser (); + +@ISA = qw(TAP::Parser); + +sub _initialize { + shift->_set_defaults; +} + +# this should really be in TAP::Parser itself... +sub _set_defaults { + my $self = shift; + + for my $key ( + qw( source_class perl_source_class grammar_class + iterator_factory_class result_factory_class ) + ) + { + my $default_method = "_default_$key"; + $self->$key( $self->$default_method() ); + } + + return $self; +} + +1; diff --git a/ext/Test/Harness/t/lib/IO/c55Capture.pm b/ext/Test/Harness/t/lib/IO/c55Capture.pm new file mode 100644 index 0000000000..ecbcb49ba7 --- /dev/null +++ b/ext/Test/Harness/t/lib/IO/c55Capture.pm @@ -0,0 +1,120 @@ +package IO::c55Capture; + +use IO::Handle; + +=head1 Name + +t/lib/IO::c55Capture - a wafer-thin test support package + +=head1 Why!? + +Compatibility with 5.5.3 and no external dependencies. + +=head1 Usage + +Works with a global filehandle: + + # set a spool to write to + tie local *STDOUT, 'IO::c55Capture'; + ... + # clear and retrieve buffer list + my @spooled = tied(*STDOUT)->dump(); + +Or, a lexical (and autocreated) filehandle: + + my $capture = IO::c55Capture->new_handle; + ... + my @output = tied($$capture)->dump; + +Note the '$$' dereference. + +=cut + +# XXX actually returns an IO::Handle :-/ +sub new_handle { + my $class = shift; + my $handle = IO::Handle->new; + tie $$handle, $class; + return ($handle); +} + +sub TIEHANDLE { + return bless [], __PACKAGE__; +} + +sub PRINT { + my $self = shift; + + push @$self, @_; +} + +sub PRINTF { + my $self = shift; + push @$self, sprintf(@_); +} + +sub dump { + my $self = shift; + my @got = @$self; + @$self = (); + return @got; +} + +package util; + +use IO::File; + +# mostly stolen from Module::Build MBTest.pm + +{ # backwards compatible temp filename recipe adapted from perlfaq + my $tmp_count = 0; + my $tmp_base_name = sprintf( "%d-%d", $$, time() ); + + sub temp_file_name { + sprintf( "%s-%04d", $tmp_base_name, ++$tmp_count ); + } +} +######################################################################## + +sub save_handle { + my ( $handle, $subr ) = @_; + my $outfile = temp_file_name(); + + local *SAVEOUT; + open SAVEOUT, ">&" . fileno($handle) + or die "Can't save output handle: $!"; + open $handle, "> $outfile" or die "Can't create $outfile: $!"; + + eval { $subr->() }; + my $err = $@; + open $handle, ">&SAVEOUT" or die "Can't restore output: $!"; + + my $ret = slurp($outfile); + 1 while unlink $outfile; + $err and die $err; + return $ret; +} + +sub stdout_of { save_handle( \*STDOUT, @_ ) } +sub stderr_of { save_handle( \*STDERR, @_ ) } + +sub stdout_stderr_of { + my $subr = shift; + my ( $stdout, $stderr ); + $stdout = stdout_of( + sub { + $stderr = stderr_of($subr); + } + ); + return ( $stdout, $stderr ); +} + +sub slurp { + my $fh = IO::File->new( $_[0] ) or die "Can't open $_[0]: $!"; + local $/; + return scalar <$fh>; +} + +1; + +# vim:ts=4:sw=4:et:sta diff --git a/ext/Test/Harness/t/lib/MyCustom.pm b/ext/Test/Harness/t/lib/MyCustom.pm new file mode 100644 index 0000000000..2402312edc --- /dev/null +++ b/ext/Test/Harness/t/lib/MyCustom.pm @@ -0,0 +1,12 @@ +# avoid cut-n-paste exhaustion with this mixin + +package MyCustom; +use strict; + +sub custom { + my $self = shift; + $main::CUSTOM{ ref($self) }++; + return $self; +} + +1; diff --git a/ext/Test/Harness/t/lib/MyGrammar.pm b/ext/Test/Harness/t/lib/MyGrammar.pm new file mode 100644 index 0000000000..ef93f9dfc1 --- /dev/null +++ b/ext/Test/Harness/t/lib/MyGrammar.pm @@ -0,0 +1,21 @@ +# subclass for testing customizing & subclassing + +package MyGrammar; + +use strict; +use vars '@ISA'; + +use MyCustom; +use TAP::Parser::Grammar; + +@ISA = qw( TAP::Parser::Grammar MyCustom ); + +sub _initialize { + my $self = shift; + $self->SUPER::_initialize(@_); + $main::INIT{ ref($self) }++; + $self->{initialized} = 1; + return $self; +} + +1; diff --git a/ext/Test/Harness/t/lib/MyIterator.pm b/ext/Test/Harness/t/lib/MyIterator.pm new file mode 100644 index 0000000000..561f6e2c78 --- /dev/null +++ b/ext/Test/Harness/t/lib/MyIterator.pm @@ -0,0 +1,26 @@ +# subclass for testing customizing & subclassing + +package MyIterator; + +use strict; +use vars '@ISA'; + +use MyCustom; +use TAP::Parser::Iterator; + +@ISA = qw( TAP::Parser::Iterator MyCustom ); + +sub _initialize { + my $self = shift; + $self->SUPER::_initialize(@_); + $main::INIT{ ref($self) }++; + $self->{initialized} = 1; + $self->{content} = [ 'whats TAP all about then?', '1..1', 'ok 1' ]; + return $self; +} + +sub next { + return shift @{ $_[0]->{content} }; +} + +1; diff --git a/ext/Test/Harness/t/lib/MyIteratorFactory.pm b/ext/Test/Harness/t/lib/MyIteratorFactory.pm new file mode 100644 index 0000000000..d8c3269cda --- /dev/null +++ b/ext/Test/Harness/t/lib/MyIteratorFactory.pm @@ -0,0 +1,19 @@ +# subclass for testing customizing & subclassing + +package MyIteratorFactory; + +use strict; +use vars '@ISA'; + +use MyCustom; +use MyIterator; +use TAP::Parser::IteratorFactory; + +@ISA = qw( TAP::Parser::IteratorFactory MyCustom ); + +sub make_iterator { + my $class = shift; + return MyIterator->new(@_); +} + +1; diff --git a/ext/Test/Harness/t/lib/MyPerlSource.pm b/ext/Test/Harness/t/lib/MyPerlSource.pm new file mode 100644 index 0000000000..6193db97df --- /dev/null +++ b/ext/Test/Harness/t/lib/MyPerlSource.pm @@ -0,0 +1,27 @@ +# subclass for testing customizing & subclassing + +package MyPerlSource; + +use strict; +use vars '@ISA'; + +use MyCustom; +use TAP::Parser::Source::Perl; + +@ISA = qw( TAP::Parser::Source::Perl MyCustom ); + +sub _initialize { + my $self = shift; + $self->SUPER::_initialize(@_); + $main::INIT{ ref($self) }++; + $self->{initialized} = 1; + return $self; +} + +sub source { + my $self = shift; + return $self->SUPER::source(@_); +} + +1; + diff --git a/ext/Test/Harness/t/lib/MyResult.pm b/ext/Test/Harness/t/lib/MyResult.pm new file mode 100644 index 0000000000..ab4845dedf --- /dev/null +++ b/ext/Test/Harness/t/lib/MyResult.pm @@ -0,0 +1,21 @@ +# subclass for testing customizing & subclassing + +package MyResult; + +use strict; +use vars '@ISA'; + +use MyCustom; +use TAP::Parser::Result; + +@ISA = qw( TAP::Parser::Result MyCustom ); + +sub _initialize { + my $self = shift; + $self->SUPER::_initialize(@_); + $main::INIT{ ref($self) }++; + $self->{initialized} = 1; + return $self; +} + +1; diff --git a/ext/Test/Harness/t/lib/MyResultFactory.pm b/ext/Test/Harness/t/lib/MyResultFactory.pm new file mode 100644 index 0000000000..371bba632b --- /dev/null +++ b/ext/Test/Harness/t/lib/MyResultFactory.pm @@ -0,0 +1,23 @@ +# subclass for testing customizing & subclassing + +package MyResultFactory; + +use strict; +use vars '@ISA'; + +use MyCustom; +use MyResult; +use TAP::Parser::ResultFactory; + +@ISA = qw( TAP::Parser::ResultFactory MyCustom ); + +sub make_result { + my $class = shift; + + # I know, this is not really being initialized, but + # for consistency's sake, deal with it :) + $main::INIT{$class}++; + return MyResult->new(@_); +} + +1; diff --git a/ext/Test/Harness/t/lib/MySource.pm b/ext/Test/Harness/t/lib/MySource.pm new file mode 100644 index 0000000000..5e41b829ae --- /dev/null +++ b/ext/Test/Harness/t/lib/MySource.pm @@ -0,0 +1,34 @@ +# subclass for testing customizing & subclassing + +package MySource; + +use strict; +use vars '@ISA'; + +use MyCustom; +use TAP::Parser::Source; + +@ISA = qw( TAP::Parser::Source MyCustom ); + +sub _initialize { + my $self = shift; + $self->SUPER::_initialize(@_); + $main::INIT{ ref($self) }++; + $self->{initialized} = 1; + return $self; +} + +sub source { + my $self = shift; + return $self->SUPER::source(@_); +} + +sub get_stream { + my $self = shift; + my $stream = $self->SUPER::get_stream(@_); + + # re-bless it: + bless $stream, 'MyIterator'; +} + +1; diff --git a/ext/Test/Harness/t/lib/NoFork.pm b/ext/Test/Harness/t/lib/NoFork.pm new file mode 100644 index 0000000000..0225e9628d --- /dev/null +++ b/ext/Test/Harness/t/lib/NoFork.pm @@ -0,0 +1,21 @@ +package NoFork; + +BEGIN { + *CORE::GLOBAL::fork = sub { die "you should not fork" }; +} +use Config; +tied(%Config)->{d_fork} = 0; # blatant lie + +=begin TEST + +Assuming not to much chdir: + + PERL5OPT='-It/lib -MNoFork' perl -Ilib bin/prove -r t + +=end TEST + +=cut + +1; + +# vim:ts=4:sw=4:et:sta diff --git a/ext/Test/Harness/t/lib/TAP/Parser/SubclassTest.pm b/ext/Test/Harness/t/lib/TAP/Parser/SubclassTest.pm new file mode 100644 index 0000000000..84becee932 --- /dev/null +++ b/ext/Test/Harness/t/lib/TAP/Parser/SubclassTest.pm @@ -0,0 +1,39 @@ +# subclass for testing subclassing + +package TAP::Parser::SubclassTest; + +use strict; +use vars qw(@ISA); + +use TAP::Parser; + +use MyCustom; +use MySource; +use MyPerlSource; +use MyGrammar; +use MyIteratorFactory; +use MyResultFactory; + +@ISA = qw( TAP::Parser MyCustom ); + +sub _default_source_class {'MySource'} +sub _default_perl_source_class {'MyPerlSource'} +sub _default_grammar_class {'MyGrammar'} +sub _default_iterator_factory_class {'MyIteratorFactory'} +sub _default_result_factory_class {'MyResultFactory'} + +sub make_source { shift->SUPER::make_source(@_)->custom } +sub make_perl_source { shift->SUPER::make_perl_source(@_)->custom } +sub make_grammar { shift->SUPER::make_grammar(@_)->custom } +sub make_iterator { shift->SUPER::make_iterator(@_)->custom } +sub make_result { shift->SUPER::make_result(@_)->custom } + +sub _initialize { + my $self = shift; + $self->SUPER::_initialize(@_); + $main::INIT{ ref($self) }++; + $self->{initialized} = 1; + return $self; +} + +1; diff --git a/ext/Test/Harness/t/nofork-mux.t b/ext/Test/Harness/t/nofork-mux.t index 5751945076..d2df8d0f1e 100644 --- a/ext/Test/Harness/t/nofork-mux.t +++ b/ext/Test/Harness/t/nofork-mux.t @@ -3,7 +3,7 @@ BEGIN { if ( $ENV{PERL_CORE} ) { chdir 't'; - @INC = ( '../lib', 'lib' ); + @INC = ( '../lib', '../ext/Test/Harness/t/lib' ); } else { use lib 't/lib'; diff --git a/ext/Test/Harness/t/nofork.t b/ext/Test/Harness/t/nofork.t index 7f2782059d..72a2adb33c 100755 --- a/ext/Test/Harness/t/nofork.t +++ b/ext/Test/Harness/t/nofork.t @@ -6,7 +6,7 @@ BEGIN { if ( $ENV{PERL_CORE} ) { chdir 't'; - @INC = ( '../lib', 'lib' ); + @INC = ( '../lib', '../ext/Test/Harness/t/lib' ); } else { use lib 't/lib'; diff --git a/ext/Test/Harness/t/parse.t b/ext/Test/Harness/t/parse.t index 39f2c380c9..b52f2c5fe7 100755 --- a/ext/Test/Harness/t/parse.t +++ b/ext/Test/Harness/t/parse.t @@ -5,7 +5,7 @@ use strict; BEGIN { if ( $ENV{PERL_CORE} ) { chdir 't'; - @INC = ( '../lib', 'lib' ); + @INC = ( '../lib', '../ext/Test/Harness/t/lib' ); } else { use lib 't/lib'; diff --git a/ext/Test/Harness/t/parser-config.t b/ext/Test/Harness/t/parser-config.t index 0c74427fa6..5f8b03feac 100644 --- a/ext/Test/Harness/t/parser-config.t +++ b/ext/Test/Harness/t/parser-config.t @@ -3,7 +3,7 @@ BEGIN { if ( $ENV{PERL_CORE} ) { chdir 't'; - @INC = ( '../lib', 'lib' ); + @INC = ( '../lib', '../ext/Test/Harness/t/lib' ); } else { unshift @INC, 't/lib'; diff --git a/ext/Test/Harness/t/parser-subclass.t b/ext/Test/Harness/t/parser-subclass.t index 2817751714..f86c058c28 100644 --- a/ext/Test/Harness/t/parser-subclass.t +++ b/ext/Test/Harness/t/parser-subclass.t @@ -3,7 +3,7 @@ BEGIN { if ( $ENV{PERL_CORE} ) { chdir 't'; - @INC = ( '../lib', 'lib' ); + @INC = ( '../lib', '../ext/Test/Harness/t/lib' ); } else { unshift @INC, 't/lib'; diff --git a/ext/Test/Harness/t/prove.t b/ext/Test/Harness/t/prove.t index 38b9b85097..5dbbe0ed5a 100644 --- a/ext/Test/Harness/t/prove.t +++ b/ext/Test/Harness/t/prove.t @@ -3,7 +3,7 @@ BEGIN { if ( $ENV{PERL_CORE} ) { chdir 't'; - @INC = ( '../lib', 'lib' ); + @INC = ( '../lib', '../ext/Test/Harness/t/lib' ); } else { unshift @INC, 't/lib'; diff --git a/ext/Test/Harness/t/source.t b/ext/Test/Harness/t/source.t index a6441a5242..99d81f9b16 100644 --- a/ext/Test/Harness/t/source.t +++ b/ext/Test/Harness/t/source.t @@ -3,7 +3,7 @@ BEGIN { if ( $ENV{PERL_CORE} ) { chdir 't'; - @INC = ( '../lib', 'lib' ); + @INC = ( '../lib', '../ext/Test/Harness/t/lib' ); } else { unshift @INC, 't/lib'; |