r729 - in packages: . libtest-builder-tester-perl
libtest-builder-tester-perl/branches
libtest-builder-tester-perl/branches/upstream
libtest-builder-tester-perl/branches/upstream/current
libtest-builder-tester-perl/branches/upstream/current/lib
libtest-builder-tester-perl/branches/upstream/current/lib/Test
libtest-builder-tester-perl/branches/upstream/current/lib/Test/Builder
libtest-builder-tester-perl/branches/upstream/current/lib/Test/Builder/Tester
libtest-builder-tester-perl/branches/upstream/current/t
Allard Hoeve
hoeve-guest at costa.debian.org
Sun Jul 17 08:08:47 UTC 2005
Author: hoeve-guest
Date: 2005-03-10 13:40:47 +0100 (Thu, 10 Mar 2005)
New Revision: 729
Added:
packages/libtest-builder-tester-perl/
packages/libtest-builder-tester-perl/branches/
packages/libtest-builder-tester-perl/branches/upstream/
packages/libtest-builder-tester-perl/branches/upstream/current/
packages/libtest-builder-tester-perl/branches/upstream/current/Build.PL
packages/libtest-builder-tester-perl/branches/upstream/current/CHANGES
packages/libtest-builder-tester-perl/branches/upstream/current/MANIFEST
packages/libtest-builder-tester-perl/branches/upstream/current/META.yml
packages/libtest-builder-tester-perl/branches/upstream/current/Makefile.PL
packages/libtest-builder-tester-perl/branches/upstream/current/lib/
packages/libtest-builder-tester-perl/branches/upstream/current/lib/Test/
packages/libtest-builder-tester-perl/branches/upstream/current/lib/Test/Builder/
packages/libtest-builder-tester-perl/branches/upstream/current/lib/Test/Builder/Tester.pm
packages/libtest-builder-tester-perl/branches/upstream/current/lib/Test/Builder/Tester/
packages/libtest-builder-tester-perl/branches/upstream/current/lib/Test/Builder/Tester/Color.pm
packages/libtest-builder-tester-perl/branches/upstream/current/t/
packages/libtest-builder-tester-perl/branches/upstream/current/t/01basic.t
packages/libtest-builder-tester-perl/branches/upstream/current/t/02fhrestore.t
packages/libtest-builder-tester-perl/branches/upstream/current/t/03die.t
packages/libtest-builder-tester-perl/branches/upstream/current/t/04line_num.t
packages/libtest-builder-tester-perl/branches/upstream/current/t/05faildiag.t
packages/libtest-builder-tester-perl/branches/upstream/current/t/06errormess.t
packages/libtest-builder-tester-perl/branches/upstream/current/t/07args.t
packages/libtest-builder-tester-perl/tags/
Log:
[svn-inject] Installing original source of libtest-builder-tester-perl
Added: packages/libtest-builder-tester-perl/branches/upstream/current/Build.PL
===================================================================
--- packages/libtest-builder-tester-perl/branches/upstream/current/Build.PL 2005-03-10 06:08:37 UTC (rev 728)
+++ packages/libtest-builder-tester-perl/branches/upstream/current/Build.PL 2005-03-10 12:40:47 UTC (rev 729)
@@ -0,0 +1,51 @@
+use Module::Build;
+my $build = new Module::Build
+(
+ module_name => 'Test::Builder::Tester',
+ license => 'perl',
+ requires => {
+ 'Test::Builder' => 0.12,
+ },
+ recommends => {
+ },
+ create_makefile_pl => 'traditional',
+);
+$build->create_build_script;
+
+__END__
+
+This is old code from the Makefile.PL. It should probably
+ be converted to run under Module::Build at some point
+
+# this code stolen from Test-More-0.41 in order to test on multiple
+# perls. If you want to run a multiple perl test do
+
+# bash$ export PERL_TEST_ALL=1
+# bash$ perl Makefile.PL; make; make test
+
+{
+ package MY;
+
+ sub test_via_harness {
+ my($self, $orig_perl, $tests) = @_;
+
+ my @perls = ($orig_perl);
+ push @perls, qw(perl
+ perl5.7.3
+ perl5.6.1
+ perl5.6.0
+ perl5.005_03
+ perl5.004_05
+ perl5.004
+ )
+ if $ENV{PERL_TEST_ALL};
+
+ my $out;
+ foreach my $perl (@perls) {
+ $out .= $self->SUPER::test_via_harness($perl, $tests) . "\n";
+ }
+ $out =~ s{-I\$\(PERL_\w*LIB\)}{}g;
+
+ return $out;
+ }
+}
Added: packages/libtest-builder-tester-perl/branches/upstream/current/CHANGES
===================================================================
--- packages/libtest-builder-tester-perl/branches/upstream/current/CHANGES 2005-03-10 06:08:37 UTC (rev 728)
+++ packages/libtest-builder-tester-perl/branches/upstream/current/CHANGES 2005-03-10 12:40:47 UTC (rev 729)
@@ -0,0 +1,72 @@
+1.01
+
+ - Schwern's prototype of Test::Builder adds an extra newline
+ when running under Test::Harness. We now fake not running under
+ Test::Harness during the testing (we twiddle the ENV variable)
+
+1.00
+
+ - prepped for release after testing at Fotango
+
+ - Added additional test name argument 'label'
+
+0.99_01
+
+ - Convert to Module::Build
+
+ - Add ability to ignore test_err, test_out
+
+ - Added test name arguments 'name' and 'title'
+
+0.09
+
+ - Make the code work on 5.004 (now works on all known perls greater
+ and including 5.004,)
+ fixes http://rt.cpan.org/NoAuth/Bug.html?id=456
+
+ - Improve documentation readability
+
+ - Change colouring scheme to use background colouring rather than
+ foreground colouring (makes it easyier to see spare spaces)
+ fixes http://rt.cpan.org/NoAuth/Bug.html?id=386
+
+ - Added this changelog file.
+
+0.08
+
+ - Changes to work with new version of Test::Builder that has
+ a differing diag text
+ fixes http://rt.cpan.org/NoAuth/Bug.html?id=379
+
+ - Fix missing files from the distribution
+ fixes http://rt.cpan.org/NoAuth/Bug.html?id=384
+
+0.07 (First release to CPAN)
+
+ - colouring added
+
+0.06
+
+ - test_diag and test_fail added
+
+ - better tests added
+
+0.05
+
+ - line_num added
+
+0.04
+
+ - More tests added.
+
+0.03
+
+ - Minor documentation change
+
+0.02
+
+ - Solved problem with running extra tests with no_ending
+
+ - Got permission from schwern to steal his code
+
+0.01 Prototype version
Added: packages/libtest-builder-tester-perl/branches/upstream/current/MANIFEST
===================================================================
--- packages/libtest-builder-tester-perl/branches/upstream/current/MANIFEST 2005-03-10 06:08:37 UTC (rev 728)
+++ packages/libtest-builder-tester-perl/branches/upstream/current/MANIFEST 2005-03-10 12:40:47 UTC (rev 729)
@@ -0,0 +1,14 @@
+Build.PL
+Makefile.PL
+CHANGES
+lib/Test/Builder/Tester.pm
+lib/Test/Builder/Tester/Color.pm
+MANIFEST This list of files
+META.yml
+t/01basic.t
+t/02fhrestore.t
+t/03die.t
+t/04line_num.t
+t/05faildiag.t
+t/06errormess.t
+t/07args.t
Added: packages/libtest-builder-tester-perl/branches/upstream/current/META.yml
===================================================================
--- packages/libtest-builder-tester-perl/branches/upstream/current/META.yml 2005-03-10 06:08:37 UTC (rev 728)
+++ packages/libtest-builder-tester-perl/branches/upstream/current/META.yml 2005-03-10 12:40:47 UTC (rev 729)
@@ -0,0 +1,10 @@
+#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
+name: Test-Builder-Tester
+version: 1.01
+version_from: lib/Test/Builder/Tester.pm
+installdirs: site
+requires:
+ Test::Builder: 0.12
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.12
Added: packages/libtest-builder-tester-perl/branches/upstream/current/Makefile.PL
===================================================================
--- packages/libtest-builder-tester-perl/branches/upstream/current/Makefile.PL 2005-03-10 06:08:37 UTC (rev 728)
+++ packages/libtest-builder-tester-perl/branches/upstream/current/Makefile.PL 2005-03-10 12:40:47 UTC (rev 729)
@@ -0,0 +1,13 @@
+# Note: this file was auto-generated by Module::Build::Compat version 0.03
+use ExtUtils::MakeMaker;
+WriteMakefile
+(
+ 'NAME' => 'Test::Builder::Tester',
+ 'VERSION_FROM' => 'lib/Test/Builder/Tester.pm',
+ 'PREREQ_PM' => {
+ 'Test::Builder' => '0.12'
+ },
+ 'INSTALLDIRS' => 'site',
+ 'PL_FILES' => {}
+ )
+;
Added: packages/libtest-builder-tester-perl/branches/upstream/current/lib/Test/Builder/Tester/Color.pm
===================================================================
--- packages/libtest-builder-tester-perl/branches/upstream/current/lib/Test/Builder/Tester/Color.pm 2005-03-10 06:08:37 UTC (rev 728)
+++ packages/libtest-builder-tester-perl/branches/upstream/current/lib/Test/Builder/Tester/Color.pm 2005-03-10 12:40:47 UTC (rev 729)
@@ -0,0 +1,50 @@
+package Test::Builder::Tester::Color;
+
+use strict;
+
+require Test::Builder::Tester;
+
+=head1 NAME
+
+Test::Builder::Tester::Color - turn on colour in Test::Builder::Tester
+
+=head1 SYNOPSIS
+
+ When running a test script
+
+ perl -MTest::Builder::Tester::Color test.t
+
+=head1 DESCRIPTION
+
+Importing this module causes the subroutine color in Test::Builder::Tester
+to be called with a true value causing colour highlighting to be turned
+on in debug output.
+
+The sole purpose of this module is to enable colour highlighting
+from the command line.
+
+=cut
+
+sub import
+{
+ Test::Builder::Tester::color(1);
+}
+
+=head1 AUTHOR
+
+Copyright Mark Fowler E<lt>mark at twoshortplanks.comE<gt> 2002.
+
+This program is free software; you can redistribute it
+and/or modify it under the same terms as Perl itself.
+
+=head1 BUGS
+
+This module will have no effect unless Term::ANSIColor is installed.
+
+=head1 SEE ALSO
+
+L<Test::Builder::Tester>, L<Term::ANSIColor>
+
+=cut
+
+1;
Added: packages/libtest-builder-tester-perl/branches/upstream/current/lib/Test/Builder/Tester.pm
===================================================================
--- packages/libtest-builder-tester-perl/branches/upstream/current/lib/Test/Builder/Tester.pm 2005-03-10 06:08:37 UTC (rev 728)
+++ packages/libtest-builder-tester-perl/branches/upstream/current/lib/Test/Builder/Tester.pm 2005-03-10 12:40:47 UTC (rev 729)
@@ -0,0 +1,590 @@
+package Test::Builder::Tester;
+
+use strict;
+use vars qw(@EXPORT $VERSION @ISA);
+$VERSION = "1.01";
+
+use Test::Builder;
+use Symbol;
+use Carp;
+
+=head1 NAME
+
+Test::Builder::Tester - test testsuites that have been built with
+Test::Builder
+
+=head1 SYNOPSIS
+
+ use Test::Builder::Tester tests => 1;
+ use Test::More;
+
+ test_out("not ok 1 - foo");
+ test_err("# Failed test ($0 at line ".line_num(+1).")");
+ fail("foo");
+ test_test("fail works");
+
+=head1 DESCRIPTION
+
+A module that helps you test testing modules that are built with
+B<Test::Builder>.
+
+The testing system is designed to be used by performing a three step
+process for each test you wish to test. This process starts with using
+C<test_out> and C<test_err> in advance to declare what the testsuite you
+are testing will output with B<Test::Builder> to stdout and stderr.
+
+You then can run the test(s) from your test suite that call
+B<Test::Builder>. At this point the output of B<Test::Builder> is
+safely captured by B<Test::Builder::Tester> rather than being
+interpreted as real test output.
+
+The final stage is to call C<test_test> that will simply compare what you
+predeclared to what B<Test::Builder> actually outputted, and report the
+results back with a "ok" or "not ok" (with debugging) to the normal
+output.
+
+=cut
+
+####
+# set up testing
+####
+
+my $t = Test::Builder->new;
+
+###
+# make us an exporter
+###
+
+use Exporter;
+ at ISA = qw(Exporter);
+
+ at EXPORT = qw(test_out test_err test_fail test_diag test_test line_num);
+
+# _export_to_level and import stolen directly from Test::More. I am
+# the king of cargo cult programming ;-)
+
+# 5.004's Exporter doesn't have export_to_level.
+sub _export_to_level
+{
+ my $pkg = shift;
+ my $level = shift;
+ (undef) = shift; # XXX redundant arg
+ my $callpkg = caller($level);
+ $pkg->export($callpkg, @_);
+}
+
+sub import {
+ my $class = shift;
+ my(@plan) = @_;
+
+ my $caller = caller;
+
+ $t->exported_to($caller);
+ $t->plan(@plan);
+
+ my @imports = ();
+ foreach my $idx (0..$#plan) {
+ if( $plan[$idx] eq 'import' ) {
+ @imports = @{$plan[$idx+1]};
+ last;
+ }
+ }
+
+ __PACKAGE__->_export_to_level(1, __PACKAGE__, @imports);
+}
+
+###
+# set up file handles
+###
+
+# 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::Tester::Tie", "STDOUT";
+my $err = tie *$error_handle, "Test::Tester::Tie", "STDERR";
+
+####
+# exported functions
+####
+
+# for remembering that we're testing and where we're testing at
+my $testing = 0;
+my $testing_num;
+
+# remembering where the file handles were originally connected
+my $original_output_handle;
+my $original_failure_handle;
+my $original_todo_handle;
+
+my $original_test_number;
+my $original_harness_state;
+
+my $original_harness_env;
+
+# function that starts testing and redirects the filehandles for now
+sub _start_testing
+{
+ # even if we're running under Test::Harness pretend we're not
+ # for now. This needed so Test::Builder doesn't add extra spaces
+ $original_harness_env = $ENV{HARNESS_ACTIVE};
+ $ENV{HARNESS_ACTIVE} = 0;
+
+ # remember what the handles were set to
+ $original_output_handle = $t->output();
+ $original_failure_handle = $t->failure_output();
+ $original_todo_handle = $t->todo_output();
+
+ # switch out to our own handles
+ $t->output($output_handle);
+ $t->failure_output($error_handle);
+ $t->todo_output($error_handle);
+
+ # clear the expected list
+ $out->reset();
+ $err->reset();
+
+ # remeber that we're testing
+ $testing = 1;
+ $testing_num = $t->current_test;
+ $t->current_test(0);
+
+ # look, we shouldn't do the ending stuff
+ $t->no_ending(1);
+}
+
+=head2 Methods
+
+These are the six methods that are exported as default.
+
+=over 4
+
+=item test_out
+
+=item test_err
+
+Procedures for predeclaring the output that your test suite is
+expected to produce until C<test_test> is called. These procedures
+automatically assume that each line terminates with "\n". So
+
+ test_out("ok 1","ok 2");
+
+is the same as
+
+ test_out("ok 1\nok 2");
+
+which is even the same as
+
+ test_out("ok 1");
+ test_out("ok 2");
+
+Once C<test_out> or C<test_err> (or C<test_fail> or C<test_diag>) have
+been called once all further output from B<Test::Builder> will be
+captured by B<Test::Builder::Tester>. This means that your will not
+be able perform further tests to the normal output in the normal way
+until you call C<test_test> (well, unless you manually meddle with the
+output filehandles)
+
+=cut
+
+sub test_out(@)
+{
+ # do we need to do any setup?
+ _start_testing() unless $testing;
+
+ $out->expect(@_)
+}
+
+sub test_err(@)
+{
+ # do we need to do any setup?
+ _start_testing() unless $testing;
+
+ $err->expect(@_)
+}
+
+=item test_fail
+
+Because the standard failure message that B<Test::Builder> produces
+whenever a test fails will be a common occurrence in your test error
+output, rather than forcing you to call C<test_err> with the string
+all the time like so
+
+ test_err("# Failed test ($0 at line ".line_num(+1).")");
+
+C<test_fail> exists as a convenience method that can be called
+instead. It takes one argument, the offset from the current line that
+the line that causes the fail is on.
+
+ test_fail(+1);
+
+This means that the example in the synopsis could be rewritten
+more simply as:
+
+ test_out("not ok 1 - foo");
+ test_fail(+1);
+ fail("foo");
+ test_test("fail works");
+
+=cut
+
+sub test_fail
+{
+ # do we need to do any setup?
+ _start_testing() unless $testing;
+
+ # work out what line we should be on
+ my ($package, $filename, $line) = caller;
+ $line = $line + (shift() || 0); # prevent warnings
+
+ # expect that on stderr
+ $err->expect("# Failed test ($0 at line $line)");
+}
+
+=item test_diag
+
+As most of the remaining expected output to the error stream will be
+created by Test::Builder's C<diag> function, B<Test::Builder::Tester>
+provides a convience function C<test_diag> that you can use instead of
+C<test_err>.
+
+The C<test_diag> function prepends comment hashes and spacing to the
+start and newlines to the end of the expected output passed to it and
+adds it to the list of expected error output. So, instead of writing
+
+ test_err("# Couldn't open file");
+
+you can write
+
+ test_diag("Couldn't open file");
+
+Remember that B<Test::Builder>'s diag function will not add newlines to
+the end of output and test_diag will. So to check
+
+ Test::Builder->new->diag("foo\n","bar\n");
+
+You would do
+
+ test_diag("foo","bar")
+
+without the newlines.
+
+=cut
+
+sub test_diag
+{
+ # do we need to do any setup?
+ _start_testing() unless $testing;
+
+ # expect the same thing, but prepended with "# "
+ local $_;
+ $err->expect(map {"# $_"} @_)
+}
+
+=item test_test
+
+Actually performs the output check testing the tests, comparing the
+data (with C<eq>) that we have captured from B<Test::Builder> against
+that that was declared with C<test_out> and C<test_err>.
+
+This takes name/value pairs that effect how the test is run.
+
+=over
+
+=item title (synonym 'name', 'label')
+
+The name of the test that will be displayed after the C<ok> or C<not
+ok>.
+
+=item skip_out
+
+Setting this to a true value will cause the test to ignore if the
+output sent by the test to the output stream does not match that
+declared with C<test_out>.
+
+=item skip_err
+
+Setting this to a true value will cause the test to ignore if the
+output sent by the test to the error stream does not match that
+declared with C<test_err>.
+
+=back
+
+As a convience, if only one argument is passed then this argument
+is assumed to be the name of the test (as in the above examples.)
+
+Once C<test_test> has been run test output will be redirected back to
+the original filehandles that B<Test::Builder> was connected to
+(probably STDOUT and STDERR,) meaning any further tests you run
+will function normally and cause success/errors for B<Test::Harness>.
+
+=cut
+
+sub test_test
+{
+ # decode the arguements as described in the pod
+ my $mess;
+ my %args;
+ if (@_ == 1)
+ { $mess = shift }
+ else
+ {
+ %args = @_;
+ $mess = $args{name} if exists($args{name});
+ $mess = $args{title} if exists($args{title});
+ $mess = $args{label} if exists($args{label});
+ }
+
+ # er, are we testing?
+ croak "Not testing. You must declare output with a test function first."
+ unless $testing;
+
+ # okay, reconnect the test suite back to the saved handles
+ $t->output($original_output_handle);
+ $t->failure_output($original_failure_handle);
+ $t->todo_output($original_todo_handle);
+
+ # restore the test no, etc, back to the original point
+ $t->current_test($testing_num);
+ $testing = 0;
+
+ # re-enable the original setting of the harness
+ $ENV{HARNESS_ACTIVE} = $original_harness_env;
+
+ # check the output we've stashed
+ unless ($t->ok( ($args{skip_out} || $out->check)
+ && ($args{skip_err} || $err->check),
+ $mess))
+ {
+ # print out the diagnostic information about why this
+ # test failed
+
+ local $_;
+
+ $t->diag(map {"$_\n"} $out->complaint)
+ unless $args{skip_out} || $out->check;
+
+ $t->diag(map {"$_\n"} $err->complaint)
+ unless $args{skip_err} || $err->check;
+ }
+}
+
+=item line_num
+
+A utility function that returns the line number that the function was
+called on. You can pass it an offset which will be added to the
+result. This is very useful for working out the correct text of
+diagnostic methods that contain line numbers.
+
+Essentially this is the same as the C<__LINE__> macro, but the
+C<line_num(+3)> idiom is arguably nicer.
+
+=cut
+
+sub line_num
+{
+ my ($package, $filename, $line) = caller;
+ return $line + (shift() || 0); # prevent warnings
+}
+
+=back
+
+In addition to the six exported functions there there exists one
+function that can only be accessed with a fully qualified function
+call.
+
+=over 4
+
+=item color
+
+When C<test_test> is called and the output that your tests generate
+does not match that which you declared, C<test_test> will print out
+debug information showing the two conflicting versions. As this
+output itself is debug information it can be confusing which part of
+the output is from C<test_test> and which was the original output from
+your original tests. Also, it may be hard to spot things like
+extraneous whitespace at the end of lines that may cause your test to
+fail even though the output looks similar.
+
+To assist you, if you have the B<Term::ANSIColor> module installed
+(which you should do by default from perl 5.005 onwards), C<test_test>
+can colour the background of the debug information to disambiguate the
+different types of output. The debug output will have it's background
+coloured green and red. The green part represents the text which is
+the same between the executed and actual output, the red shows which
+part differs.
+
+The C<color> function determines if colouring should occur or not.
+Passing it a true or false value will enable or disable colouring
+respectively, and the function called with no argument will return the
+current setting.
+
+To enable colouring from the command line, you can use the
+B<Text::Builder::Tester::Color> module like so:
+
+ perl -Mlib=Text::Builder::Tester::Color test.t
+
+Or by including the B<Test::Builder::Tester::Color> module directly in
+the PERL5LIB.
+
+=cut
+
+my $color;
+sub color
+{
+ $color = shift if @_;
+ $color;
+}
+
+=back
+
+=head1 BUGS
+
+Calls B<Test::Builder>'s C<no_ending> method turning off the ending
+tests. This is needed as otherwise it will trip out because we've run
+more tests than we strictly should have and it'll register any
+failures we had that we were testing for as real failures.
+
+The color function doesn't work unless B<Term::ANSIColor> is installed
+and is compatible with your terminal.
+
+Bugs (and requests for new features) can be reported to the author
+though the CPAN RT system:
+L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Builder-Tester>
+
+=head1 AUTHOR
+
+Copyright Mark Fowler E<lt>mark at twoshortplanks.comE<gt> 2002, 2004.
+
+Some code taken from B<Test::More> and B<Test::Catch>, written by by
+Michael G Schwern E<lt>schwern at pobox.comE<gt>. Hence, those parts
+Copyright Micheal G Schwern 2001. Used and distributed with
+permission.
+
+This program is free software; you can redistribute it
+and/or modify it under the same terms as Perl itself.
+
+=head1 NOTES
+
+This code has been tested explicitly on the following versions
+of perl: 5.7.3, 5.6.1, 5.6.0, 5.005_03, 5.004_05 and 5.004.
+
+Thanks to Richard Clamp E<lt>richardc at unixbeard.netE<gt> for letting
+me use his testing system to try this module out on.
+
+=head1 SEE ALSO
+
+L<Test::Builder>, L<Test::Builder::Tester::Color>, L<Test::More>.
+
+=cut
+
+1;
+
+####################################################################
+# Helper class that is used to remember expected and received data
+
+package Test::Tester::Tie;
+
+##
+# add line(s) to be expected
+
+sub expect
+{
+ my $self = shift;
+ $self->[2] .= join '', map { "$_\n" } @_;
+}
+
+##
+# return true iff the expected data matches the got data
+
+sub check
+{
+ my $self = shift;
+
+ # turn off warnings as these might be undef
+ local $^W = 0;
+
+ $self->[1] eq $self->[2];
+}
+
+##
+# a complaint message about the inputs not matching (to be
+# used for debugging messages)
+
+sub complaint
+{
+ my $self = shift;
+ my ($type, $got, $wanted) = @$self;
+
+ # are we running in colour mode?
+ if (Test::Builder::Tester::color)
+ {
+ # get color
+ eval "require Term::ANSIColor";
+ unless ($@)
+ {
+ # colours
+
+ my $green = Term::ANSIColor::color("black").
+ Term::ANSIColor::color("on_green");
+ my $red = Term::ANSIColor::color("black").
+ Term::ANSIColor::color("on_red");
+ my $reset = Term::ANSIColor::color("reset");
+
+ # work out where the two strings start to differ
+ my $char = 0;
+ $char++ while substr($got, $char, 1) eq substr($wanted, $char, 1);
+
+ # get the start string and the two end strings
+ my $start = $green . substr($wanted, 0, $char);
+ my $gotend = $red . substr($got , $char) . $reset;
+ my $wantedend = $red . substr($wanted, $char) . $reset;
+
+ # make the start turn green on and off
+ $start =~ s/\n/$reset\n$green/g;
+
+ # make the ends turn red on and off
+ $gotend =~ s/\n/$reset\n$red/g;
+ $wantedend =~ s/\n/$reset\n$red/g;
+
+ # rebuild the strings
+ $got = $start . $gotend;
+ $wanted = $start . $wantedend;
+ }
+ }
+
+ return "$type is:\n" .
+ "$got\nnot:\n$wanted\nas expected"
+}
+
+##
+# forget all expected and got data
+
+sub reset
+{
+ my $self = shift;
+ @$self = ($self->[0]);
+}
+
+###
+# tie interface
+###
+
+sub PRINT {
+ my $self = shift;
+ $self->[1] .= join '', @_;
+}
+
+sub TIEHANDLE {
+ my $class = shift;
+ my $self = [shift()];
+ return bless $self, $class;
+}
+
+sub READ {}
+sub READLINE {}
+sub GETC {}
+sub FILENO {}
+
+1;
Added: packages/libtest-builder-tester-perl/branches/upstream/current/t/01basic.t
===================================================================
--- packages/libtest-builder-tester-perl/branches/upstream/current/t/01basic.t 2005-03-10 06:08:37 UTC (rev 728)
+++ packages/libtest-builder-tester-perl/branches/upstream/current/t/01basic.t 2005-03-10 12:40:47 UTC (rev 729)
@@ -0,0 +1,33 @@
+#!/usr/bin/perl
+
+use Test::Builder::Tester tests => 6;
+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 28)");
+test_err("# got: 'foo'");
+test_err("# expected: 'bar'");
+is("foo","bar","should fail");
+test_test("testing failing");
+
+
+
+
Added: packages/libtest-builder-tester-perl/branches/upstream/current/t/02fhrestore.t
===================================================================
--- packages/libtest-builder-tester-perl/branches/upstream/current/t/02fhrestore.t 2005-03-10 06:08:37 UTC (rev 728)
+++ packages/libtest-builder-tester-perl/branches/upstream/current/t/02fhrestore.t 2005-03-10 12:40:47 UTC (rev 729)
@@ -0,0 +1,58 @@
+#!/usr/bin/perl
+
+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 {}
Added: packages/libtest-builder-tester-perl/branches/upstream/current/t/03die.t
===================================================================
--- packages/libtest-builder-tester-perl/branches/upstream/current/t/03die.t 2005-03-10 06:08:37 UTC (rev 728)
+++ packages/libtest-builder-tester-perl/branches/upstream/current/t/03die.t 2005-03-10 12:40:47 UTC (rev 729)
@@ -0,0 +1,12 @@
+#!/usr/bin/perl
+
+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");
+
Added: packages/libtest-builder-tester-perl/branches/upstream/current/t/04line_num.t
===================================================================
--- packages/libtest-builder-tester-perl/branches/upstream/current/t/04line_num.t 2005-03-10 06:08:37 UTC (rev 728)
+++ packages/libtest-builder-tester-perl/branches/upstream/current/t/04line_num.t 2005-03-10 12:40:47 UTC (rev 729)
@@ -0,0 +1,8 @@
+#!/usr/bin/perl
+
+use Test::More tests => 3;
+use Test::Builder::Tester;
+
+is(line_num(),6,"normal line num");
+is(line_num(-1),6,"line number minus one");
+is(line_num(+2),10,"line number plus two");
Added: packages/libtest-builder-tester-perl/branches/upstream/current/t/05faildiag.t
===================================================================
--- packages/libtest-builder-tester-perl/branches/upstream/current/t/05faildiag.t 2005-03-10 06:08:37 UTC (rev 728)
+++ packages/libtest-builder-tester-perl/branches/upstream/current/t/05faildiag.t 2005-03-10 12:40:47 UTC (rev 729)
@@ -0,0 +1,44 @@
+#!/usr/bin/perl
+
+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");
+
+
Added: packages/libtest-builder-tester-perl/branches/upstream/current/t/06errormess.t
===================================================================
--- packages/libtest-builder-tester-perl/branches/upstream/current/t/06errormess.t 2005-03-10 06:08:37 UTC (rev 728)
+++ packages/libtest-builder-tester-perl/branches/upstream/current/t/06errormess.t 2005-03-10 12:40:47 UTC (rev 729)
@@ -0,0 +1,265 @@
+#!/usr/bin/perl -w
+
+use Test::More tests => 12;
+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::Tester::Tie2", "STDOUT";
+my $err = tie *$error_handle, "Test::Tester::Tie2", "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
+ ($wanted, $got) = $out->both;
+ $t->is_eq($got, $wanted, "STDOUT $text");
+
+ # stderr
+ ($got, $wanted) = $err->both;
+ $got =~ s/ /+/g;
+ $wanted =~ s/ /+/g;
+ $t->ok($got eq $wanted, "STDERR $text")
+ or $t->diag("HEY THERE, I GOT '$got' not '$wanted'");
+}
+
+####################################################################
+# 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
+####################################################################
+
+# test that when something doesn't match the expected output we
+# get the correct error message
+
+# turn off colour
+Test::Builder::Tester::color(0);
+
+# declare the colours empty
+my ($red, $reset, $green) = ("","","");
+
+# set up the outer wrapper again
+start_testing();
+$out->expect("not ok 1 - bar");
+$err->expect("# Failed test ($0 at line ".line_num(+24).")");
+$err->expect("# STDERR is:",
+ "# ${green}# Failed test ($0 at line ".line_num(+19).")$reset",
+ "# ${green}# got: 'php'$reset",
+ "# ${green}# expected: '${red}Perl'$reset",
+ "# $reset",
+ "# not:",
+ "# ${green}# Failed test ($0 at line ".line_num(+19).")$reset",
+ "# ${green}# got: 'php'$reset",
+ "# ${green}# expected: '${red}perl'$reset",
+ "# $reset",
+ "# as expected");
+
+# set up what the inner wrapper expects (which it won't get);
+test_out("not ok 1 - foo");
+test_err("# Failed test ($0 at line ".line_num(+5).")",
+ "# got: 'php'",
+ "# expected: 'perl'");
+
+# the actual test function that we are testing (which fails)
+is("php","Perl","foo");
+
+# the test wrapper which will fail in turn as in the diagnostics
+# from the first fail we get "Perl" where we expected "perl"
+test_test("bar");
+
+# finally check that we got the correct diagnostics about our
+# diagnostics failing out
+my_test_test("meta test b&w");
+
+############################################
+
+# load the module and get colours if we can
+eval "require Term::ANSIColor";
+unless ($@) {
+ $red = Term::ANSIColor::color("black") .
+ Term::ANSIColor::color("on_red");
+ $reset = Term::ANSIColor::color("reset");
+ $green = Term::ANSIColor::color("black").
+ Term::ANSIColor::color("on_green");
+}
+
+# turn colour mode on
+Test::Builder::Tester::color(1);
+
+# set up the outer wrapper again
+start_testing();
+$out->expect("not ok 1 - bar");
+$err->expect("# Failed test ($0 at line ".line_num(+24).")");
+$err->expect("# STDERR is:",
+ "# ${green}# Failed test ($0 at line ".line_num(+19).")$reset",
+ "# ${green}# got: 'php'$reset",
+ "# ${green}# expected: '${red}Perl'$reset",
+ "# ${red}$reset",
+ "# not:",
+ "# ${green}# Failed test ($0 at line ".line_num(+19).")$reset",
+ "# ${green}# got: 'php'$reset",
+ "# ${green}# expected: '${red}perl'$reset",
+ "# ${red}$reset",
+ "# as expected");
+
+# set up what the inner wrapper expects (which it won't get);
+test_out("not ok 1 - foo");
+test_err("# Failed test ($0 at line ".line_num(+5).")",
+ "# got: 'php'",
+ "# expected: 'perl'");
+
+# the actual test function that we are testing (which fails)
+is("php","Perl","foo");
+
+# the test wrapper which will fail in turn as in the diagnostics
+# from the first fail we get "Perl" where we expected "perl"
+test_test("bar");
+
+# finally check that we got the correct diagnostics about our
+# diagnostics failing out
+my_test_test("meta test color");
+
+####################################################################
+
+package Test::Tester::Tie2;
+
+##
+# add line(s) to be expected
+
+sub expect
+{
+ my $self = shift;
+ $self->[2] .= join '', map { "$_\n" } @_;
+}
+
+sub both
+{
+ my $self = shift;
+ return ($self->[1], $self->[2]);
+}
+
+##
+# forget all expected and got data
+
+sub reset
+{
+ my $self = shift;
+ @$self = ($self->[0]);
+ }
+
+###
+# tie interface
+###
+
+sub PRINT {
+ my $self = shift;
+ $self->[1] .= join '', @_;
+}
+
+sub TIEHANDLE {
+ my $class = shift;
+ my $self = [shift()];
+ return bless $self, $class;
+}
+
+sub READ {}
+sub READLINE {}
+sub GETC {}
+sub FILENO {}
Added: packages/libtest-builder-tester-perl/branches/upstream/current/t/07args.t
===================================================================
--- packages/libtest-builder-tester-perl/branches/upstream/current/t/07args.t 2005-03-10 06:08:37 UTC (rev 728)
+++ packages/libtest-builder-tester-perl/branches/upstream/current/t/07args.t 2005-03-10 12:40:47 UTC (rev 729)
@@ -0,0 +1,266 @@
+#!/usr/bin/perl -w
+
+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::Tester::Tie2", "STDOUT";
+my $err = tie *$error_handle, "Test::Tester::Tie2", "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
+ ($wanted, $got) = $out->both;
+ $t->is_eq($got, $wanted, "STDOUT $text");
+
+ # stderr
+ ($got, $wanted) = $err->both;
+ $got =~ s/ /+/g;
+ $wanted =~ s/ /+/g;
+ $t->ok($got eq $wanted, "STDERR $text")
+ or $t->diag("HEY THERE, I GOT '$got' not '$wanted'");
+}
+
+####################################################################
+# 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");
+
+####################################################################
+
+package Test::Tester::Tie2;
+
+##
+# add line(s) to be expected
+
+sub expect
+{
+ my $self = shift;
+ $self->[2] .= join '', map { "$_\n" } @_;
+}
+
+sub both
+{
+ my $self = shift;
+ return ($self->[1], $self->[2]);
+}
+
+##
+# forget all expected and got data
+
+sub reset
+{
+ my $self = shift;
+ @$self = ($self->[0]);
+ }
+
+###
+# tie interface
+###
+
+sub PRINT {
+ my $self = shift;
+ $self->[1] .= join '', @_;
+}
+
+sub TIEHANDLE {
+ my $class = shift;
+ my $self = [shift()];
+ return bless $self, $class;
+}
+
+sub READ {}
+sub READLINE {}
+sub GETC {}
+sub FILENO {}
More information about the Pkg-perl-cvs-commits
mailing list