名前¶
Test::Builder::Tester - test testsuites that have been built with Test::Builder
Test::Builder::Tester - Test::Builder で構築されたテストスイートをテストする
概要¶
use Test::Builder::Tester tests => 1;
use Test::More;
test_out("not ok 1 - foo");
test_fail(+1);
fail("foo");
test_test("fail works");
説明¶
A module that helps you test testing modules that are built with Test::Builder.
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 test_out
and test_err
in advance to declare what the testsuite you are testing will output with Test::Builder to stdout and stderr.
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 test_out
and test_err
in advance to declare what the testsuite you are testing will output with Test::Builder to stdout and stderr. (TBT)
You then can run the test(s) from your test suite that call Test::Builder. At this point the output of Test::Builder is safely captured by Test::Builder::Tester rather than being interpreted as real test output.
You then can run the test(s) from your test suite that call Test::Builder. At this point the output of Test::Builder is safely captured by Test::Builder::Tester rather than being interpreted as real test output. (TBT)
The final stage is to call test_test
that will simply compare what you predeclared to what Test::Builder actually outputted, and report the results back with a "ok" or "not ok" (with debugging) to the normal output.
The final stage is to call test_test
that will simply compare what you predeclared to what Test::Builder actually outputted, and report the results back with a "ok" or "not ok" (with debugging) to the normal output. (TBT)
Functions¶
These are the six methods that are exported as default.
These are the six methods that are exported as default. (TBT)
- test_out
- test_err
-
Procedures for predeclaring the output that your test suite is expected to produce until
test_test
is called. These procedures automatically assume that each line terminates with "\n". SoProcedures for predeclaring the output that your test suite is expected to produce until
test_test
is called. These procedures automatically assume that each line terminates with "\n". So (TBT)test_out("ok 1","ok 2");
is the same as
is the same as (TBT)
test_out("ok 1\nok 2");
which is even the same as
which is even the same as (TBT)
test_out("ok 1"); test_out("ok 2");
Once
test_out
ortest_err
(ortest_fail
ortest_diag
) have been called, all further output from Test::Builder will be captured by Test::Builder::Tester. This means that you will not be able perform further tests to the normal output in the normal way until you calltest_test
(well, unless you manually meddle with the output filehandles)Once
test_out
ortest_err
(ortest_fail
ortest_diag
) have been called, all further output from Test::Builder will be captured by Test::Builder::Tester. This means that you will not be able perform further tests to the normal output in the normal way until you calltest_test
(well, unless you manually meddle with the output filehandles) (TBT) - test_fail
-
Because the standard failure message that Test::Builder produces whenever a test fails will be a common occurrence in your test error output, and because it has changed between Test::Builder versions, rather than forcing you to call
test_err
with the string all the time like soBecause the standard failure message that Test::Builder produces whenever a test fails will be a common occurrence in your test error output, and because it has changed between Test::Builder versions, rather than forcing you to call
test_err
with the string all the time like so (TBT)test_err("# Failed test ($0 at line ".line_num(+1).")");
test_fail
exists as a convenience function 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
exists as a convenience function that can be called instead. It takes one argument, the offset from the current line that the line that causes the fail is on. (TBT)test_fail(+1);
This means that the example in the synopsis could be rewritten more simply as:
This means that the example in the synopsis could be rewritten more simply as: (TBT)
test_out("not ok 1 - foo"); test_fail(+1); fail("foo"); test_test("fail works");
- test_diag
-
As most of the remaining expected output to the error stream will be created by Test::Builder's
diag
function, Test::Builder::Tester provides a convenience functiontest_diag
that you can use instead oftest_err
.As most of the remaining expected output to the error stream will be created by Test::Builder's
diag
function, Test::Builder::Tester provides a convenience functiontest_diag
that you can use instead oftest_err
. (TBT)The
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 writingThe
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 (TBT)test_err("# Couldn't open file");
you can write
you can write (TBT)
test_diag("Couldn't open file");
Remember that Test::Builder's diag function will not add newlines to the end of output and test_diag will. So to check
Remember that Test::Builder's diag function will not add newlines to the end of output and test_diag will. So to check (TBT)
Test::Builder->new->diag("foo\n","bar\n");
You would do
You would do (TBT)
test_diag("foo","bar")
without the newlines.
without the newlines. (TBT)
- test_test
-
Actually performs the output check testing the tests, comparing the data (with
eq
) that we have captured from Test::Builder against that that was declared withtest_out
andtest_err
.Actually performs the output check testing the tests, comparing the data (with
eq
) that we have captured from Test::Builder against that that was declared withtest_out
andtest_err
. (TBT)This takes name/value pairs that effect how the test is run.
This takes name/value pairs that effect how the test is run. (TBT)
- title (synonym 'name', 'label')
-
The name of the test that will be displayed after the
ok
ornot ok
.The name of the test that will be displayed after the
ok
ornot ok
. (TBT) - 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
test_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
test_out
. (TBT) - 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
test_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
test_err
. (TBT)
As a convenience, if only one argument is passed then this argument is assumed to be the name of the test (as in the above examples.)
As a convenience, if only one argument is passed then this argument is assumed to be the name of the test (as in the above examples.) (TBT)
Once
test_test
has been run test output will be redirected back to the original filehandles that Test::Builder was connected to (probably STDOUT and STDERR,) meaning any further tests you run will function normally and cause success/errors for Test::Harness.Once
test_test
has been run test output will be redirected back to the original filehandles that Test::Builder was connected to (probably STDOUT and STDERR,) meaning any further tests you run will function normally and cause success/errors for Test::Harness. (TBT) - 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 functions that contain line numbers.
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 functions that contain line numbers. (TBT)
Essentially this is the same as the
__LINE__
macro, but theline_num(+3)
idiom is arguably nicer.Essentially this is the same as the
__LINE__
macro, but theline_num(+3)
idiom is arguably nicer. (TBT)
In addition to the six exported functions there exists one function that can only be accessed with a fully qualified function call.
In addition to the six exported functions there exists one function that can only be accessed with a fully qualified function call. (TBT)
- color
-
When
test_test
is called and the output that your tests generate does not match that which you declared,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 fromtest_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.When
test_test
is called and the output that your tests generate does not match that which you declared,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 fromtest_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. (TBT)To assist you
test_test
can colour the background of the debug information to disambiguate the different types of output. The debug output will have its 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.To assist you
test_test
can colour the background of the debug information to disambiguate the different types of output. The debug output will have its 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. (TBT)The
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.The
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. (TBT)To enable colouring from the command line, you can use the Text::Builder::Tester::Color module like so:
To enable colouring from the command line, you can use the Text::Builder::Tester::Color module like so: (TBT)
perl -Mlib=Text::Builder::Tester::Color test.t
Or by including the Test::Builder::Tester::Color module directly in the PERL5LIB.
Or by including the Test::Builder::Tester::Color module directly in the PERL5LIB. (TBT)
バグ¶
Calls <Test::Builder-
no_ending>> 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.
Calls <Test::Builder-
no_ending>> 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. (TBT)
The color function doesn't work unless Term::ANSIColor is compatible with your terminal.
The color function doesn't work unless Term::ANSIColor is compatible with your terminal. (TBT)
Bugs (and requests for new features) can be reported to the author though the CPAN RT system: http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Builder-Tester
Bugs (and requests for new features) can be reported to the author though the CPAN RT system: http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Builder-Tester (TBT)
作者¶
Copyright Mark Fowler <[email protected]> 2002, 2004.
Some code taken from Test::More and Test::Catch, written by by Michael G Schwern <[email protected]>. 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.
NOTES¶
Thanks to Richard Clamp <[email protected]> for letting me use his testing system to try this module out on.
Thanks to Richard Clamp <[email protected]> for letting me use his testing system to try this module out on. (TBT)