2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml">
5 <title>Test::Builder::Tester - test testsuites that have been built with
7 <meta http-equiv=
"content-type" content=
"text/html; charset=utf-8" />
8 <link rev=
"made" href=
"mailto:" />
11 <body style=
"background-color: white">
12 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
13 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
14 <big><strong><span class=
"block"> Test::Builder::Tester - test testsuites that have been built with
15 Test::Builder
</span></strong></big>
19 <p><a name=
"__index__"></a></p>
24 <li><a href=
"#name">NAME
</a></li>
25 <li><a href=
"#synopsis">SYNOPSIS
</a></li>
26 <li><a href=
"#description">DESCRIPTION
</a></li>
29 <li><a href=
"#methods">Methods
</a></li>
32 <li><a href=
"#bugs">BUGS
</a></li>
33 <li><a href=
"#author">AUTHOR
</a></li>
34 <li><a href=
"#notes">NOTES
</a></li>
35 <li><a href=
"#see_also">SEE ALSO
</a></li>
42 <h1><a name=
"name">NAME
</a></h1>
43 <p>Test::Builder::Tester - test testsuites that have been built with
48 <h1><a name=
"synopsis">SYNOPSIS
</a></h1>
50 use Test::Builder::Tester tests =
> 1;
53 test_out(
"not ok
1 - foo
");
55 fail(
"foo
");
56 test_test(
"fail works
");
</pre>
60 <h1><a name=
"description">DESCRIPTION
</a></h1>
61 <p>A module that helps you test testing modules that are built with
62 <strong>Test::Builder
</strong>.
</p>
63 <p>The testing system is designed to be used by performing a three step
64 process for each test you wish to test. This process starts with using
65 <a href=
"#item_test_out"><code>test_out
</code></a> and
<a href=
"#item_test_err"><code>test_err
</code></a> in advance to declare what the testsuite you
66 are testing will output with
<strong>Test::Builder
</strong> to stdout and stderr.
</p>
67 <p>You then can run the
<code>test(s)
</code> from your test suite that call
68 <strong>Test::Builder
</strong>. At this point the output of
<strong>Test::Builder
</strong> is
69 safely captured by
<strong>Test::Builder::Tester
</strong> rather than being
70 interpreted as real test output.
</p>
71 <p>The final stage is to call
<a href=
"#item_test_test"><code>test_test
</code></a> that will simply compare what you
72 predeclared to what
<strong>Test::Builder
</strong> actually outputted, and report the
73 results back with a ``ok'' or ``not ok'' (with debugging) to the normal
77 <h2><a name=
"methods">Methods
</a></h2>
78 <p>These are the six methods that are exported as default.
</p>
80 <dt><strong><a name=
"item_test_out">test_out
</a></strong>
82 <dt><strong><a name=
"item_test_err">test_err
</a></strong>
85 <p>Procedures for predeclaring the output that your test suite is
86 expected to produce until
<a href=
"#item_test_test"><code>test_test
</code></a> is called. These procedures
87 automatically assume that each line terminates with ``\n''. So
</p>
91 test_out(
"ok
1",
"ok
2");
</pre>
98 test_out(
"ok
1\nok
2");
</pre>
101 <p>which is even the same as
</p>
105 test_out(
"ok
1");
106 test_out(
"ok
2");
</pre>
109 <p>Once
<a href=
"#item_test_out"><code>test_out
</code></a> or
<a href=
"#item_test_err"><code>test_err
</code></a> (or
<a href=
"#item_test_fail"><code>test_fail
</code></a> or
<a href=
"#item_test_diag"><code>test_diag
</code></a>) have
110 been called once all further output from
<strong>Test::Builder
</strong> will be
111 captured by
<strong>Test::Builder::Tester
</strong>. This means that your will not
112 be able perform further tests to the normal output in the normal way
113 until you call
<a href=
"#item_test_test"><code>test_test
</code></a> (well, unless you manually meddle with the
114 output filehandles)
</p>
117 <dt><strong><a name=
"item_test_fail">test_fail
</a></strong>
120 <p>Because the standard failure message that
<strong>Test::Builder
</strong> produces
121 whenever a test fails will be a common occurrence in your test error
122 output, and because has changed between Test::Builder versions, rather
123 than forcing you to call
<a href=
"#item_test_err"><code>test_err
</code></a> with the string all the time like
128 test_err(
"# Failed test ($
0 at line
".line_num(+
1).
")
");
</pre>
131 <p><a href=
"#item_test_fail"><code>test_fail
</code></a> exists as a convenience method that can be called
132 instead. It takes one argument, the offset from the current line that
133 the line that causes the fail is on.
</p>
140 <p>This means that the example in the synopsis could be rewritten
145 test_out(
"not ok
1 - foo
");
147 fail(
"foo
");
148 test_test(
"fail works
");
</pre>
151 <dt><strong><a name=
"item_test_diag">test_diag
</a></strong>
154 <p>As most of the remaining expected output to the error stream will be
155 created by Test::Builder's
<code>diag
</code> function,
<strong>Test::Builder::Tester
</strong>
156 provides a convience function
<a href=
"#item_test_diag"><code>test_diag
</code></a> that you can use instead of
157 <a href=
"#item_test_err"><code>test_err
</code></a>.
</p>
160 <p>The
<a href=
"#item_test_diag"><code>test_diag
</code></a> function prepends comment hashes and spacing to the
161 start and newlines to the end of the expected output passed to it and
162 adds it to the list of expected error output. So, instead of writing
</p>
166 test_err(
"# Couldn't open file
");
</pre>
173 test_diag(
"Couldn't open file
");
</pre>
176 <p>Remember that
<strong>Test::Builder
</strong>'s diag function will not add newlines to
177 the end of output and test_diag will. So to check
</p>
181 Test::Builder-
>new-
>diag(
"foo\n
",
"bar\n
");
</pre>
188 test_diag(
"foo
",
"bar
")
</pre>
191 <p>without the newlines.
</p>
194 <dt><strong><a name=
"item_test_test">test_test
</a></strong>
197 <p>Actually performs the output check testing the tests, comparing the
198 data (with
<code>eq
</code>) that we have captured from
<strong>Test::Builder
</strong> against
199 that that was declared with
<a href=
"#item_test_out"><code>test_out
</code></a> and
<a href=
"#item_test_err"><code>test_err
</code></a>.
</p>
202 <p>This takes name/value pairs that effect how the test is run.
</p>
205 <dt><strong><a name=
"item_title">title (synonym 'name', 'label')
</a></strong>
208 <p>The name of the test that will be displayed after the
<code>ok
</code> or
<code>not
212 <dt><strong><a name=
"item_skip_out">skip_out
</a></strong>
215 <p>Setting this to a true value will cause the test to ignore if the
216 output sent by the test to the output stream does not match that
217 declared with
<a href=
"#item_test_out"><code>test_out
</code></a>.
</p>
220 <dt><strong><a name=
"item_skip_err">skip_err
</a></strong>
223 <p>Setting this to a true value will cause the test to ignore if the
224 output sent by the test to the error stream does not match that
225 declared with
<a href=
"#item_test_err"><code>test_err
</code></a>.
</p>
229 <p>As a convience, if only one argument is passed then this argument
230 is assumed to be the name of the test (as in the above examples.)
</p>
231 <p>Once
<a href=
"#item_test_test"><code>test_test
</code></a> has been run test output will be redirected back to
232 the original filehandles that
<strong>Test::Builder
</strong> was connected to
233 (probably STDOUT and STDERR,) meaning any further tests you run
234 will function normally and cause success/errors for
<strong>Test::Harness
</strong>.
</p>
235 <dt><strong><a name=
"item_line_num">line_num
</a></strong>
238 <p>A utility function that returns the line number that the function was
239 called on. You can pass it an offset which will be added to the
240 result. This is very useful for working out the correct text of
241 diagnostic methods that contain line numbers.
</p>
244 <p>Essentially this is the same as the
<code>__LINE__
</code> macro, but the
245 <a href=
"#item_line_num"><code>line_num(+
3)
</code></a> idiom is arguably nicer.
</p>
249 <p>In addition to the six exported functions there there exists one
250 function that can only be accessed with a fully qualified function
253 <dt><strong><a name=
"item_color">color
</a></strong>
256 <p>When
<a href=
"#item_test_test"><code>test_test
</code></a> is called and the output that your tests generate
257 does not match that which you declared,
<a href=
"#item_test_test"><code>test_test
</code></a> will print out
258 debug information showing the two conflicting versions. As this
259 output itself is debug information it can be confusing which part of
260 the output is from
<a href=
"#item_test_test"><code>test_test
</code></a> and which was the original output from
261 your original tests. Also, it may be hard to spot things like
262 extraneous whitespace at the end of lines that may cause your test to
263 fail even though the output looks similar.
</p>
266 <p>To assist you, if you have the
<strong>Term::ANSIColor
</strong> module installed
267 (which you should do by default from perl
5.005 onwards),
<a href=
"#item_test_test"><code>test_test
</code></a>
268 can colour the background of the debug information to disambiguate the
269 different types of output. The debug output will have it's background
270 coloured green and red. The green part represents the text which is
271 the same between the executed and actual output, the red shows which
275 <p>The
<a href=
"#item_color"><code>color
</code></a> function determines if colouring should occur or not.
276 Passing it a true or false value will enable or disable colouring
277 respectively, and the function called with no argument will return the
281 <p>To enable colouring from the command line, you can use the
282 <strong>Text::Builder::Tester::Color
</strong> module like so:
</p>
286 perl -Mlib=Text::Builder::Tester::Color test.t
</pre>
289 <p>Or by including the
<strong>Test::Builder::Tester::Color
</strong> module directly in
297 <h1><a name=
"bugs">BUGS
</a></h1>
298 <p>Calls
<strong>Test::Builder
</strong>'s
<code>no_ending
</code> method turning off the ending
299 tests. This is needed as otherwise it will trip out because we've run
300 more tests than we strictly should have and it'll register any
301 failures we had that we were testing for as real failures.
</p>
302 <p>The color function doesn't work unless
<strong>Term::ANSIColor
</strong> is installed
303 and is compatible with your terminal.
</p>
304 <p>Bugs (and requests for new features) can be reported to the author
305 though the CPAN RT system:
306 <a href=
"http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Builder-Tester">http://rt.cpan.org/NoAuth/ReportBug.html
</a></p>
310 <h1><a name=
"author">AUTHOR
</a></h1>
311 <p>Copyright Mark Fowler
<<a href=
"mailto:mark@twoshortplanks.com">mark@twoshortplanks.com
</a>> 2002,
2004.
</p>
312 <p>Some code taken from
<strong>Test::More
</strong> and
<strong>Test::Catch
</strong>, written by by
313 Michael G Schwern
<<a href=
"mailto:schwern@pobox.com">schwern@pobox.com
</a>>. Hence, those parts
314 Copyright Micheal G Schwern
2001. Used and distributed with
316 <p>This program is free software; you can redistribute it
317 and/or modify it under the same terms as Perl itself.
</p>
321 <h1><a name=
"notes">NOTES
</a></h1>
322 <p>This code has been tested explicitly on the following versions
323 of perl:
5.7.3,
5.6.1,
5.6.0,
5.005_03,
5.004_05 and
5.004.
</p>
324 <p>Thanks to Richard Clamp
<<a href=
"mailto:richardc@unixbeard.net">richardc@unixbeard.net
</a>> for letting
325 me use his testing system to try this module out on.
</p>
329 <h1><a name=
"see_also">SEE ALSO
</a></h1>
330 <p><a href=
"file://C|\msysgit\mingw\html/lib/Test/Builder.html">the Test::Builder manpage
</a>,
<a href=
"file://C|\msysgit\mingw\html/lib/Test/Builder/Tester/Color.html">the Test::Builder::Tester::Color manpage
</a>,
<a href=
"file://C|\msysgit\mingw\html/lib/Test/More.html">the Test::More manpage
</a>.
</p>
331 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
332 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
333 <big><strong><span class=
"block"> Test::Builder::Tester - test testsuites that have been built with
334 Test::Builder
</span></strong></big>