Manual Pages for UNIX Darwin command on man Test::Builder::Tester
MyWebUniversity

Manual Pages for UNIX Darwin command on man Test::Builder::Tester

Test::Builder::Tester(3pPme)rl Programmers Reference GuiTdeest::Builder::Tester(3pm)

NAME

Test::Builder::Tester - test testsuites that have been built with

Test::Builder

SYNOPSIS

use Test::Builder::Tester tests => 1;

use Test::More;

testout("not ok 1 - foo");

testfail(+1); fail("foo"); testtest("fail works");

DESCRIPTION

A module that helps you test testing modules that are built with TTeesstt::::BBuuiillddeerr. 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 "testout" and "testerr" in advance to declare what the testsuite you are testing will output with TTeesstt::::BBuuiillddeerr to stdout and stderr. You then can run the test(s) from your test suite that call TTeesstt::::BBuuiillddeerr. At this point the output of TTeesstt::::BBuuiillddeerr is safely captured by TTeesstt::::BBuuiillddeerr::::TTeesstteerr rather than being interpreted as real test output. The final stage is to call "testtest" that will simply compare what you predeclared to what TTeesstt::::BBuuiillddeerr actually outputted, and report the results back with a "ok" or "not ok" (with debugging) to the normal output. Methods These are the six methods that are exported as default. testout testerr Procedures for predeclaring the output that your test suite is expected to produce until "testtest" is called. These procedures automatically assume that each line terminates with "\n". So testout("ok 1","ok 2"); is the same as testout("ok 1\nok 2"); which is even the same as testout("ok 1"); testout("ok 2"); Once "testout" or "testerr" (or "testfail" or "testdiag") have

been called once all further output from TTeesstt::::BBuuiillddeerr will be cap-

tured by TTeesstt::::BBuuiillddeerr::::TTeesstteerr. This means that your will not be able perform further tests to the normal output in the normal way until you call "testtest" (well, unless you manually meddle with the output filehandles) testfail Because the standard failure message that TTeesstt::::BBuuiillddeerr produces whenever a test fails will be a common occurrence in your test

error output, and because has changed between Test::Builder ver-

sions, rather than forcing you to call "testerr" with the string all the time like so

testerr("# Failed test ($0 at line ".linenum(+1).")");

"testfail" 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. testfail(+1); This means that the example in the synopsis could be rewritten more simply as:

testout("not ok 1 - foo");

testfail(+1); fail("foo"); testtest("fail works"); testdiag As most of the remaining expected output to the error stream will be created by Test::Builder's "diag" function, TTeesstt::::BBuuiillddeerr::::TTeesstteerr provides a convience function "testdiag" that you can use instead of "testerr". The "testdiag" 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

testerr("# Couldn't open file");

you can write testdiag("Couldn't open file"); Remember that TTeesstt::::BBuuiillddeerr's diag function will not add newlines to the end of output and testdiag will. So to check

Test::Builder->new->diag("foo\n","bar\n");

You would do testdiag("foo","bar") without the newlines. testtest Actually performs the output check testing the tests, comparing the data (with "eq") that we have captured from TTeesstt::::BBuuiillddeerr against that that was declared with "testout" and "testerr". This takes name/value pairs that effect how the test is run. title (synonym 'name', 'label') The name of the test that will be displayed after the "ok" or "not ok". skipout 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 "testout". skiperr 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 "testerr". 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 "testtest" has been run test output will be redirected back to the original filehandles that TTeesstt::::BBuuiillddeerr was connected to (probably STDOUT and STDERR,) meaning any further tests you run will function normally and cause success/errors for TTeesstt::::HHaarrnneessss. linenum 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 "LINE" macro, but the "linenum(+3)" idiom is arguably nicer.

In addition to the six exported functions there there exists one func-

tion that can only be accessed with a fully qualified function call. color When "testtest" is called and the output that your tests generate does not match that which you declared, "testtest" 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 "testtest" 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 TTeerrmm::::AANNSSIICCoolloorr module installed (which you should do by default from perl 5.005 onwards), "testtest" 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 repre-

sents the text which is the same between the executed and actual output, the red shows which part differs. 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. To enable colouring from the command line, you can use the TTeexxtt::::BBuuiillddeerr::::TTeesstteerr::::CCoolloorr module like so:

perl -Mlib=Text::Builder::Tester::Color test.t

Or by including the TTeesstt::::BBuuiillddeerr::::TTeesstteerr::::CCoolloorr module directly in the PERL5LIB.

BUGS

Calls TTeesstt::::BBuuiillddeerr's "noending" 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 TTeerrmm::::AANNSSIICCoolloorr 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:

Bug.html?Queue=Test-Builder-Tester>

AUTHOR Copyright Mark Fowler 2002, 2004. Some code taken from TTeesstt::::MMoorree and TTeesstt::::CCaattcchh, written by by Michael G Schwern . 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. NNOOTTEESS This code has been tested explicitly on the following versions of perl: 5.7.3, 5.6.1, 5.6.0, 5.00503, 5.00405 and 5.004. Thanks to Richard Clamp for letting me use his testing system to try this module out on.

SEE ALSO

Test::Builder, Test::Builder::Tester::Color, Test::More.

perl v5.8.8 2001-09-21 Test::Builder::Tester(3pm)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™