r19132 - in /branches/upstream/libtest-tester-perl/current: CHANGES META.yml README lib/Test/Tester.pm lib/Test/Tester/Capture.pm t/auto.t t/depth.t t/run_test.t
yvesago-guest at users.alioth.debian.org
yvesago-guest at users.alioth.debian.org
Fri Apr 25 08:04:42 UTC 2008
Author: yvesago-guest
Date: Fri Apr 25 08:04:41 2008
New Revision: 19132
URL: http://svn.debian.org/wsvn/?sc=1&rev=19132
Log:
[svn-upgrade] Integrating new upstream version, libtest-tester-perl (0.107)
Modified:
branches/upstream/libtest-tester-perl/current/CHANGES
branches/upstream/libtest-tester-perl/current/META.yml
branches/upstream/libtest-tester-perl/current/README
branches/upstream/libtest-tester-perl/current/lib/Test/Tester.pm
branches/upstream/libtest-tester-perl/current/lib/Test/Tester/Capture.pm
branches/upstream/libtest-tester-perl/current/t/auto.t
branches/upstream/libtest-tester-perl/current/t/depth.t
branches/upstream/libtest-tester-perl/current/t/run_test.t
Modified: branches/upstream/libtest-tester-perl/current/CHANGES
URL: http://svn.debian.org/wsvn/branches/upstream/libtest-tester-perl/current/CHANGES?rev=19132&op=diff
==============================================================================
--- branches/upstream/libtest-tester-perl/current/CHANGES (original)
+++ branches/upstream/libtest-tester-perl/current/CHANGES Fri Apr 25 08:04:41 2008
@@ -1,3 +1,34 @@
+0.107
+
+Test::Tester::Capgture::new used to just return __PACKAGE__
+because Test::Builder::new enforced it's singleton nature by
+return __PACKAGE__. That has since changed, Test::Builder::new now
+returns a blessed has and around version 0.78, Test::Builder::todo
+started wanting to modify $self. To cope with this, we now return
+a blessed hash. This is a short-term hack, the correct thing to do
+is to detect which style of Test::Builder we're dealing with and
+act appropriately.
+
+0.106
+
+Some doc clarifications and improvements.
+
+0.105
+
+Fixed documentation for run_tests - looks like I copied code for
+check_test and didn't alter it correctly. Ricardo Signes pointed out
+the errors.
+
+Removed the code and docs related to the $name parameter of run_tests,
+it had no effect and a name makes no sense (again a hang over from
+factoring this out of check_tests I guess).
+
+0.104
+
+Removed a bogus entry for Exporter in @ISA in Test::Tester::Capture
+and add a "use Test::Builder". This can cause problems that I can't
+reproduce. Thanks to Andres Koenig.
+
0.103
Default to checking depth (check against 1 if none specified). This means
Modified: branches/upstream/libtest-tester-perl/current/META.yml
URL: http://svn.debian.org/wsvn/branches/upstream/libtest-tester-perl/current/META.yml?rev=19132&op=diff
==============================================================================
--- branches/upstream/libtest-tester-perl/current/META.yml (original)
+++ branches/upstream/libtest-tester-perl/current/META.yml Fri Apr 25 08:04:41 2008
@@ -1,11 +1,11 @@
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: Test-Tester
-version: 0.103
+version: 0.107
version_from: ./lib/Test/Tester.pm
installdirs: perl
requires:
Test::Builder: 0
distribution_type: module
-generated_by: ExtUtils::MakeMaker version 6.17
+generated_by: ExtUtils::MakeMaker version 6.30_01
Modified: branches/upstream/libtest-tester-perl/current/README
URL: http://svn.debian.org/wsvn/branches/upstream/libtest-tester-perl/current/README?rev=19132&op=diff
==============================================================================
--- branches/upstream/libtest-tester-perl/current/README (original)
+++ branches/upstream/libtest-tester-perl/current/README Fri Apr 25 08:04:41 2008
@@ -24,18 +24,15 @@
use Test::More tests => 3;
use Test::MyStyle;
- my @results = run_tests(
+ my ($premature, @results) = run_tests(
sub {
is_database_alive("dbname");
- },
- {
- ok => 1, # expect the test to pass
}
);
# now use Test::More::like to check the diagnostic output
- like($result[1]->{diag}, "/^Database ping took \\d+ seconds$"/, "diag");
+ like($results[0]->{diag}, "/^Database ping took \\d+ seconds$"/, "diag");
DESCRIPTION
If you have written a test module based on Test::Builder then Test::Tester
@@ -51,9 +48,10 @@
you go.
Other modules based on Test::Builder can be used to help with the testing.
- In fact you can even use functions from your test module to test other
- functions from the same module - although that may not be a very wise thing
- to do!
+ In fact you can even use functions from your module to test other functions
+ from the same module (while this is possible it is probably not a good idea,
+ if your module has bugs, then using it to test itself may give the wrong
+ answers).
The easiest way to test is to do something like
@@ -70,20 +68,17 @@
checking that they are what was expected.
You may need to examine the test results in a more flexible way, for
- example, if the diagnostic output may be quite complex or it may involve
- something that you cannot predict in advance like a timestamp. In this case
- you can get direct access to the test results:
-
- my @results = run_tests(
+ example, the diagnostic output may be quite long or complex or it may
+ involve something that you cannot predict in advance like a timestamp. In
+ this case you can get direct access to the test results:
+
+ my ($premature, @results) = run_tests(
sub {
is_database_alive("dbname");
- },
- {
- ok => 1, # expect the test to pass
}
);
- like($result[1]->{diag}, "/^Database ping took \\d+ seconds$"/, "diag");
+ like($result[0]->{diag}, "/^Database ping took \\d+ seconds$"/, "diag");
We cannot predict how long the database ping will take so we use
Test::More's like() test to check that the diagnostic string is of the right
@@ -139,30 +134,32 @@
Any diagnostics that were output for the test. This only includes
diagnostics output after the test result is declared.
- Note that Test::Builder ensures that any diagnostics end in a \n and so it
- was essential that you have the final \n in your expected diagnostics.
- From version 0.10 onwards, Test::Tester will add the \n if you forgot it.
- Of course it will not add a \n if you are expecting no diagnostics. See
- below for help tracking down hard to find space and tab related problems.
+ Note that Test::Builder ensures that any diagnostics end in a \n and it in
+ earlier versions of Test::Tester it was essential that you have the final
+ \n in your expected diagnostics. From version 0.10 onwards, Test::Tester
+ will add the \n if you forgot it. It will not add a \n if you are
+ expecting no diagnostics. See below for help tracking down hard to find
+ space and tab related problems.
depth
This allows you to check that your test module is setting the correct
value for $Test::Builder::Level and thus giving the correct file and line
number when a test fails. It is calculated by looking at caller() and
$Test::Builder::Level. It should count how many subroutines there are
- before jumping into the function you are testing so for example in
+ before jumping into the function you are testing. So for example in
run_tests( sub { my_test_function("a", "b") } );
the depth should be 1 and in
sub deeper { my_test_function("a", "b") }
-
+
run_tests(sub { deeper() });
depth should be 2, that is 1 for the sub {} and one for deeper(). This
- might seem a little complex but unless you are calling your test functions
- inside subroutines or evals then depth will always be 1.
+ might seem a little complex but if your tests look like the simple
+ examples in this doc then you don't need to worry as the depth will always
+ be 1 and that's what Test::Tester expects by default.
Note: if you do not specify a value for depth in check_test() then it
automatically compares it against 1, if you really want to skip the depth
@@ -171,11 +168,12 @@
Note: depth will not be correctly calculated for tests that run from a
signal handler or an END block or anywhere else that hides the call stack.
- Some of the Test::Testers functions return arrays of these hashes, just like
+ Some of Test::Tester's functions return arrays of these hashes, just like
Test::Builder->details. That is, the hash for the first test will be array
element 1 (not 0). Element 0 will not be a hash it will be a string which
contains any diagnostic output that came before the first test. This should
- usually be empty.
+ usually be empty, if it's not, it means something output diagnostics before
+ any test results showed up.
SPACES AND TABS
Appearances can be deceptive, especially when it comes to emptiness. If you
@@ -221,17 +219,15 @@
variable also works (if both are set then the British spelling wins out).
EXPORTED FUNCTIONS
- ($prem, @results) = run_tests(\&test_sub, $name)
+ ($premature, @results) = run_tests(\&test_sub)
\&test_sub is a reference to a subroutine.
-
- $name is a string.
run_tests runs the subroutine in $test_sub and captures the results of any
tests inside it. You can run more than 1 test inside this subroutine if you
like.
- $prem is a string containing any diagnostic output from before the first
- test.
+ $premature is a string containing any diagnostic output from before the
+ first test.
@results is an array of test result hashes.
@@ -255,7 +251,7 @@
through each result checking it against the expected result as in
cmp_result() above.
- ($prem, @results) = check_tests(\&test_sub, \@expects, $name)
+ ($premature, @results) = check_tests(\&test_sub, \@expects, $name)
\&test_sub is a reference to a subroutine.
\@expect is a ref to an array of hash refs which are expected test results.
@@ -266,14 +262,15 @@
It returns the same values as run_tests, so you can further examine the test
results if you need to.
- ($prem, @results) = check_test(\&test_sub, \%expect, $name)
+ ($premature, @results) = check_test(\&test_sub, \%expect, $name)
\&test_sub is a reference to a subroutine.
\%expect is a ref to an hash of expected values for the test result.
check_test is a wrapper around check_tests. It combines run_tests and
cmp_tests into a single call, checking if the test died. It assumes that
- only a single test is run inside \&test_sub and test to make this is true.
+ only a single test is run inside \&test_sub and include a test to make sure
+ this is true.
It returns the same values as run_tests, so you can further examine the test
results if you need to.
@@ -288,7 +285,7 @@
methods on this object to record information about test results. When
Test::Tester is loaded, it replaces Test::Builder's new() method with one
which returns a Test::Tester::Delegate object. Most of the time this object
- appears to be the real Test::Builder object. Any methods that are called are
+ behaves as the real Test::Builder object. Any methods that are called are
delegated to the real Test::Builder object so everything works perfectly.
However once we go into test mode, the method calls are no longer passed to
the real Test::Builder object, instead they go to the Test::Tester::Capture
Modified: branches/upstream/libtest-tester-perl/current/lib/Test/Tester.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libtest-tester-perl/current/lib/Test/Tester.pm?rev=19132&op=diff
==============================================================================
--- branches/upstream/libtest-tester-perl/current/lib/Test/Tester.pm (original)
+++ branches/upstream/libtest-tester-perl/current/lib/Test/Tester.pm Fri Apr 25 08:04:41 2008
@@ -18,7 +18,7 @@
use vars qw( @ISA @EXPORT $VERSION );
-$VERSION = "0.103";
+$VERSION = "0.107";
@EXPORT = qw( run_tests check_tests check_test cmp_results show_space );
@ISA = qw( Exporter );
@@ -318,18 +318,15 @@
use Test::More tests => 3;
use Test::MyStyle;
- my @results = run_tests(
+ my ($premature, @results) = run_tests(
sub {
is_database_alive("dbname");
- },
- {
- ok => 1, # expect the test to pass
}
);
# now use Test::More::like to check the diagnostic output
- like($result[1]->{diag}, "/^Database ping took \\d+ seconds$"/, "diag");
+ like($results[0]->{diag}, "/^Database ping took \\d+ seconds$"/, "diag");
=head1 DESCRIPTION
@@ -343,13 +340,14 @@
use Test::Tester;
-in your test script before any other Test::Builder based modules and away
+in your test script B<before> any other Test::Builder based modules and away
you go.
-Other modules based on Test::Builder can be used to help with the testing.
-In fact you can even use functions from your test module to test other
-functions from the same module - although that may not be a very wise thing
-to do!
+Other modules based on Test::Builder can be used to help with the
+testing. In fact you can even use functions from your module to test
+other functions from the same module (while this is possible it is
+probably not a good idea, if your module has bugs, then
+using it to test itself may give the wrong answers).
The easiest way to test is to do something like
@@ -366,20 +364,17 @@
checking that they are what was expected.
You may need to examine the test results in a more flexible way, for
-example, if the diagnostic output may be quite complex or it may involve
+example, the diagnostic output may be quite long or complex or it may involve
something that you cannot predict in advance like a timestamp. In this case
you can get direct access to the test results:
- my @results = run_tests(
+ my ($premature, @results) = run_tests(
sub {
is_database_alive("dbname");
- },
- {
- ok => 1, # expect the test to pass
}
);
- like($result[1]->{diag}, "/^Database ping took \\d+ seconds$"/, "diag");
+ like($result[0]->{diag}, "/^Database ping took \\d+ seconds$"/, "diag");
We cannot predict how long the database ping will take so we use
@@ -414,7 +409,7 @@
These fields are documented in L<Test::Builder> in the details() function
-=over 2
+=over 2
=item ok
@@ -449,11 +444,12 @@
Any diagnostics that were output for the test. This only includes
diagnostics output B<after> the test result is declared.
-Note that Test::Builder ensures that any diagnostics end in a \n and so it
-was essential that you have the final \n in your expected diagnostics. From
-version 0.10 onwards, Test::Tester will add the \n if you forgot it. Of
-course it will not add a \n if you are expecting no diagnostics. See below
-for help tracking down hard to find space and tab related problems.
+Note that Test::Builder ensures that any diagnostics end in a \n and
+it in earlier versions of Test::Tester it was essential that you have
+the final \n in your expected diagnostics. From version 0.10 onwards,
+Test::Tester will add the \n if you forgot it. It will not add a \n if
+you are expecting no diagnostics. See below for help tracking down
+hard to find space and tab related problems.
=item depth
@@ -461,19 +457,20 @@
for $Test::Builder::Level and thus giving the correct file and line number
when a test fails. It is calculated by looking at caller() and
$Test::Builder::Level. It should count how many subroutines there are before
-jumping into the function you are testing so for example in
+jumping into the function you are testing. So for example in
run_tests( sub { my_test_function("a", "b") } );
the depth should be 1 and in
sub deeper { my_test_function("a", "b") }
-
+
run_tests(sub { deeper() });
-depth should be 2, that is 1 for the sub {} and one for deeper(). This might
-seem a little complex but unless you are calling your test functions inside
-subroutines or evals then depth will always be 1.
+depth should be 2, that is 1 for the sub {} and one for deeper(). This
+might seem a little complex but if your tests look like the simple
+examples in this doc then you don't need to worry as the depth will
+always be 1 and that's what Test::Tester expects by default.
B<Note>: if you do not specify a value for depth in check_test() then it
automatically compares it against 1, if you really want to skip the depth
@@ -484,11 +481,12 @@
=back
-Some of the Test::Testers functions return arrays of these hashes, just like
-Test::Builder->details. That is, the hash for the first test will be array
-element 1 (not 0). Element 0 will not be a hash it will be a string which
-contains any diagnostic output that came before the first test. This should
-usually be empty.
+Some of Test::Tester's functions return arrays of these hashes, just
+like Test::Builder->details. That is, the hash for the first test will
+be array element 1 (not 0). Element 0 will not be a hash it will be a
+string which contains any diagnostic output that came before the first
+test. This should usually be empty, if it's not, it means something
+output diagnostics before any test results showed up.
=head1 SPACES AND TABS
@@ -537,17 +535,16 @@
=head1 EXPORTED FUNCTIONS
-=head3 ($prem, @results) = run_tests(\&test_sub, $name)
+=head3 ($premature, @results) = run_tests(\&test_sub)
\&test_sub is a reference to a subroutine.
-
-$name is a string.
run_tests runs the subroutine in $test_sub and captures the results of any
tests inside it. You can run more than 1 test inside this subroutine if you
like.
-$prem is a string containing any diagnostic output from before the first test.
+$premature is a string containing any diagnostic output from before
+the first test.
@results is an array of test result hashes.
@@ -573,7 +570,7 @@
through each result checking it against the expected result as in
cmp_result() above.
-=head3 ($prem, @results) = check_tests(\&test_sub, \@expects, $name)
+=head3 ($premature, @results) = check_tests(\&test_sub, \@expects, $name)
\&test_sub is a reference to a subroutine.
@@ -585,20 +582,21 @@
It returns the same values as run_tests, so you can further examine the test
results if you need to.
-=head3 ($prem, @results) = check_test(\&test_sub, \%expect, $name)
-
-\&test_sub is a reference to a subroutine.
+=head3 ($premature, @results) = check_test(\&test_sub, \%expect, $name)
+
+\&test_sub is a reference to a subroutine.
\%expect is a ref to an hash of expected values for the test result.
check_test is a wrapper around check_tests. It combines run_tests and
-cmp_tests into a single call, checking if the test died. It assumes that
-only a single test is run inside \&test_sub and test to make this is true.
+cmp_tests into a single call, checking if the test died. It assumes
+that only a single test is run inside \&test_sub and include a test to
+make sure this is true.
It returns the same values as run_tests, so you can further examine the test
results if you need to.
-=head3 show_space()
+=head3 show_space()
Turn on the escaping of characters as described in the SPACES AND TABS
section.
@@ -610,7 +608,7 @@
methods on this object to record information about test results. When
Test::Tester is loaded, it replaces Test::Builder's new() method with one
which returns a Test::Tester::Delegate object. Most of the time this object
-appears to be the real Test::Builder object. Any methods that are called are
+behaves as the real Test::Builder object. Any methods that are called are
delegated to the real Test::Builder object so everything works perfectly.
However once we go into test mode, the method calls are no longer passed to
the real Test::Builder object, instead they go to the Test::Tester::Capture
Modified: branches/upstream/libtest-tester-perl/current/lib/Test/Tester/Capture.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libtest-tester-perl/current/lib/Test/Tester/Capture.pm?rev=19132&op=diff
==============================================================================
--- branches/upstream/libtest-tester-perl/current/lib/Test/Tester/Capture.pm (original)
+++ branches/upstream/libtest-tester-perl/current/lib/Test/Tester/Capture.pm Fri Apr 25 08:04:41 2008
@@ -2,8 +2,10 @@
package Test::Tester::Capture;
-use vars qw( @ISA @EXPORT);
- at ISA = qw( Test::Builder Exporter );
+use Test::Builder;
+
+use vars qw( @ISA );
+ at ISA = qw( Test::Builder );
# Make Test::Tester::Capture thread-safe for ithreads.
BEGIN {
@@ -25,7 +27,17 @@
sub new
{
- return __PACKAGE__;
+ # Test::Tester::Capgture::new used to just return __PACKAGE__
+ # because Test::Builder::new enforced it's singleton nature by
+ # return __PACKAGE__. That has since changed, Test::Builder::new now
+ # returns a blessed has and around version 0.78, Test::Builder::todo
+ # started wanting to modify $self. To cope with this, we now return
+ # a blessed hash. This is a short-term hack, the correct thing to do
+ # is to detect which style of Test::Builder we're dealing with and
+ # act appropriately.
+
+ my $class = shift;
+ return bless {}, $class;
}
sub ok {
Modified: branches/upstream/libtest-tester-perl/current/t/auto.t
URL: http://svn.debian.org/wsvn/branches/upstream/libtest-tester-perl/current/t/auto.t?rev=19132&op=diff
==============================================================================
--- branches/upstream/libtest-tester-perl/current/t/auto.t (original)
+++ branches/upstream/libtest-tester-perl/current/t/auto.t Fri Apr 25 08:04:41 2008
@@ -11,8 +11,7 @@
{
my ($prem, @results) = run_tests(
- sub { MyTest::ok(1, "run pass")},
- "run pass"
+ sub { MyTest::ok(1, "run pass")}
);
is_eq($results[0]->{name}, "run pass");
@@ -21,8 +20,7 @@
{
my ($prem, @results) = run_tests(
- sub { MyTest::ok(0, "run fail")},
- "run fail"
+ sub { MyTest::ok(0, "run fail")}
);
is_eq($results[0]->{name}, "run fail");
Modified: branches/upstream/libtest-tester-perl/current/t/depth.t
URL: http://svn.debian.org/wsvn/branches/upstream/libtest-tester-perl/current/t/depth.t?rev=19132&op=diff
==============================================================================
--- branches/upstream/libtest-tester-perl/current/t/depth.t (original)
+++ branches/upstream/libtest-tester-perl/current/t/depth.t Fri Apr 25 08:04:41 2008
@@ -21,8 +21,7 @@
sub {
MyTest::ok(1);
deeper();
- },
- "run pass"
+ }
);
local $Test::Builder::Level = 0;
Modified: branches/upstream/libtest-tester-perl/current/t/run_test.t
URL: http://svn.debian.org/wsvn/branches/upstream/libtest-tester-perl/current/t/run_test.t?rev=19132&op=diff
==============================================================================
--- branches/upstream/libtest-tester-perl/current/t/run_test.t (original)
+++ branches/upstream/libtest-tester-perl/current/t/run_test.t Fri Apr 25 08:04:41 2008
@@ -12,8 +12,7 @@
{
$cap = Test::Tester->capture;
my ($prem, @results) = run_tests(
- sub {$cap->ok(1, "run pass")},
- "run pass"
+ sub {$cap->ok(1, "run pass")}
);
local $Test::Builder::Level = 0;
@@ -34,8 +33,7 @@
{
my ($prem, @results) = run_tests(
- sub {$cap->ok(0, "run fail")},
- "run fail"
+ sub {$cap->ok(0, "run fail")}
);
local $Test::Builder::Level = 0;
@@ -56,8 +54,7 @@
{
my ($prem, @results) = run_tests(
- sub {$cap->skip("just because")},
- "skip"
+ sub {$cap->skip("just because")}
);
local $Test::Builder::Level = 0;
@@ -78,8 +75,7 @@
{
my ($prem, @results) = run_tests(
- sub {$cap->todo_skip("just because")},
- "todo_skip"
+ sub {$cap->todo_skip("just because")}
);
local $Test::Builder::Level = 0;
@@ -100,8 +96,7 @@
{
my ($prem, @results) = run_tests(
- sub {$cap->diag("run diag")},
- "run diag"
+ sub {$cap->diag("run diag")}
);
local $Test::Builder::Level = 0;
@@ -118,8 +113,7 @@
$cap->diag("multi pass diag2");
$cap->ok(0, "multi fail");
$cap->diag("multi fail diag");
- },
- "run multi"
+ }
);
local $Test::Builder::Level = 0;
More information about the Pkg-perl-cvs-commits
mailing list