=encoding euc-jp =head1 NAME =begin original Test::Builder::Tester - test testsuites that have been built with Test::Builder =end original Test::Builder::Tester - Test::Builder で構築されたテストスイートをテストする =head1 SYNOPSIS use Test::Builder::Tester tests => 1; use Test::More; test_out("not ok 1 - foo"); test_fail(+1); fail("foo"); test_test("fail works"); =head1 DESCRIPTION =begin original A module that helps you test testing modules that are built with B. =end original B で構築されたテストモジュールをテストするのを助ける モジュールです。 =begin original 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 and C in advance to declare what the testsuite you are testing will output with B to stdout and stderr. =end original 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 and C in advance to declare what the testsuite you are testing will output with B to stdout and stderr. (TBT) =begin original You then can run the test(s) from your test suite that call B. At this point the output of B is safely captured by B rather than being interpreted as real test output. =end original You then can run the test(s) from your test suite that call B. At this point the output of B is safely captured by B rather than being interpreted as real test output. (TBT) =begin original The final stage is to call C that will simply compare what you predeclared to what B actually outputted, and report the results back with a "ok" or "not ok" (with debugging) to the normal output. =end original The final stage is to call C that will simply compare what you predeclared to what B actually outputted, and report the results back with a "ok" or "not ok" (with debugging) to the normal output. (TBT) =cut =head2 Functions =begin original These are the six methods that are exported as default. =end original These are the six methods that are exported as default. (TBT) =over 4 =item test_out =item test_err =begin original Procedures for predeclaring the output that your test suite is expected to produce until C is called. These procedures automatically assume that each line terminates with "\n". So =end original Procedures for predeclaring the output that your test suite is expected to produce until C is called. These procedures automatically assume that each line terminates with "\n". So (TBT) test_out("ok 1","ok 2"); =begin original is the same as =end original is the same as (TBT) test_out("ok 1\nok 2"); =begin original which is even the same as =end original which is even the same as (TBT) test_out("ok 1"); test_out("ok 2"); =begin original Once C or C (or C or C) have been called, all further output from B will be captured by B. This means that you will not be able perform further tests to the normal output in the normal way until you call C (well, unless you manually meddle with the output filehandles) =end original Once C or C (or C or C) have been called, all further output from B will be captured by B. This means that you will not be able perform further tests to the normal output in the normal way until you call C (well, unless you manually meddle with the output filehandles) (TBT) =cut =item test_fail =begin original Because the standard failure message that B 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 C with the string all the time like so =end original Because the standard failure message that B 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 C with the string all the time like so (TBT) test_err("# Failed test ($0 at line ".line_num(+1).")"); =begin original C 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. =end original C 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); =begin original This means that the example in the synopsis could be rewritten more simply as: =end original 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"); =cut =item test_diag =begin original As most of the remaining expected output to the error stream will be created by Test::Builder's C function, B provides a convenience function C that you can use instead of C. =end original As most of the remaining expected output to the error stream will be created by Test::Builder's C function, B provides a convenience function C that you can use instead of C. (TBT) =begin original The C 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 =end original The C 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"); =begin original you can write =end original you can write (TBT) test_diag("Couldn't open file"); =begin original Remember that B's diag function will not add newlines to the end of output and test_diag will. So to check =end original Remember that B'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"); =begin original You would do =end original You would do (TBT) test_diag("foo","bar") =begin original without the newlines. =end original without the newlines. (TBT) =cut =item test_test =begin original Actually performs the output check testing the tests, comparing the data (with C) that we have captured from B against that that was declared with C and C. =end original Actually performs the output check testing the tests, comparing the data (with C) that we have captured from B against that that was declared with C and C. (TBT) =begin original This takes name/value pairs that effect how the test is run. =end original This takes name/value pairs that effect how the test is run. (TBT) =over =item title (synonym 'name', 'label') =begin original The name of the test that will be displayed after the C or C. =end original The name of the test that will be displayed after the C or C. (TBT) =item skip_out =begin original 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. =end original 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. (TBT) =item skip_err =begin original 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. =end original 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. (TBT) =back =begin original 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.) =end original 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) =begin original Once C has been run test output will be redirected back to the original filehandles that B was connected to (probably STDOUT and STDERR,) meaning any further tests you run will function normally and cause success/errors for B. =end original Once C has been run test output will be redirected back to the original filehandles that B was connected to (probably STDOUT and STDERR,) meaning any further tests you run will function normally and cause success/errors for B. (TBT) =cut =item line_num =begin original 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. =end original 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) =begin original Essentially this is the same as the C<__LINE__> macro, but the C idiom is arguably nicer. =end original Essentially this is the same as the C<__LINE__> macro, but the C idiom is arguably nicer. (TBT) =cut =back =begin original In addition to the six exported functions there exists one function that can only be accessed with a fully qualified function call. =end original In addition to the six exported functions there exists one function that can only be accessed with a fully qualified function call. (TBT) =over 4 =item color =begin original When C is called and the output that your tests generate does not match that which you declared, C 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 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. =end original When C is called and the output that your tests generate does not match that which you declared, C 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 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) =begin original To assist you C 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. =end original To assist you C 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) =begin original The C 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. =end original The C 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) =begin original To enable colouring from the command line, you can use the B module like so: =end original To enable colouring from the command line, you can use the B module like so: (TBT) perl -Mlib=Text::Builder::Tester::Color test.t =begin original Or by including the B module directly in the PERL5LIB. =end original Or by including the B module directly in the PERL5LIB. (TBT) =cut =back =head1 BUGS =begin original Calls C<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. =end original Calls C<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) =begin original The color function doesn't work unless B is compatible with your terminal. =end original The color function doesn't work unless B is compatible with your terminal. (TBT) =begin original Bugs (and requests for new features) can be reported to the author though the CPAN RT system: L =end original Bugs (and requests for new features) can be reported to the author though the CPAN RT system: L (TBT) =head1 AUTHOR Copyright Mark Fowler Emark@twoshortplanks.comE 2002, 2004. Some code taken from B and B, written by by Michael G Schwern Eschwern@pobox.comE. 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 =begin original Thanks to Richard Clamp Erichardc@unixbeard.netE for letting me use his testing system to try this module out on. =end original Thanks to Richard Clamp Erichardc@unixbeard.netE for letting me use his testing system to try this module out on. (TBT) =head1 SEE ALSO L, L, L. =begin meta Translate: SHIRAKATA Kentaro Status: in progress =end meta =cut