<?xml version="1.0" encoding="windows-1252"?>
<node id="1129" title="perlman:lib:Test" created="1999-12-22 19:49:29" updated="2005-08-12 10:13:52">
<type id="119">
perlfunc</type>
<author id="113">
root</author>
<data>
<field name="doctext">
</field>
<field name="name">

&lt;P&gt;
&lt;PRE&gt;  Test - provides a simple framework for writing test scripts
&lt;/PRE&gt;
&lt;P&gt;
&lt;HR&gt;
</field>
<field name="synopsis">

&lt;P&gt;
&lt;PRE&gt;  use strict;
  use Test;
  BEGIN { plan tests =&amp;gt; 13, todo =&amp;gt; &amp;#091;3,4&amp;#093; }
&lt;/PRE&gt;
&lt;P&gt;
&lt;PRE&gt;  ok(0); # failure
  ok(1); # success
&lt;/PRE&gt;
&lt;P&gt;
&lt;PRE&gt;  ok(0); # ok, expected failure (see todo list, above)
  ok(1); # surprise success!
&lt;/PRE</field>
<field name="description">

&lt;P&gt;
Test::Harness expects to see particular output when it executes tests. This
module aims to make writing proper test scripts just a little bit easier
(and less error prone :-).

&lt;P&gt;
&lt;HR&gt;
&lt;H1&gt;&lt;A NAME="TEST_TYPES"&gt;TEST TYPES&lt;/A&gt;&lt;/H1&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;&lt;A NAME="item_NORMAL"&gt;NORMAL TESTS&lt;/A&gt;&lt;/STRONG&gt;
&lt;P&gt;
These tests are expected to succeed. If they don't, something's screwed up!

&lt;P&gt;&lt;LI&gt;&lt;STRONG&gt;&lt;A NAME="item_SKIPPED"&gt;SKIPPED TESTS&lt;/A&gt;&lt;/STRONG&gt;

Skip tests need a platform specific feature that might or might not be available. The first argument should evaluate to true if the required feature is 
&lt;FONT SIZE=-1&gt;NOT&lt;/FONT&gt; available. After the first argument, skip tests work exactly the same way as do normal tests.

&lt;P&gt;&lt;LI&gt;&lt;STRONG&gt;&lt;A NAME="item_TODO"&gt;TODO TESTS&lt;/A&gt;&lt;/STRONG&gt;


&lt;FONT SIZE=-1&gt;TODO&lt;/FONT&gt; tests are designed for maintaining an executable 
&lt;FONT SIZE=-1&gt;TODO&lt;/FONT&gt; list. These tests are expected 
&lt;FONT SIZE=-1&gt;NOT&lt;/FONT&gt; to succeed (otherwise the feature they test would be on the new feature list, not the 
&lt;FONT SIZE=-1&gt;TODO&lt;/FONT&gt; list).

&lt;P&gt;
Packages should 
&lt;FONT SIZE=-1&gt;NOT&lt;/FONT&gt; be released with successful 
&lt;FONT SIZE=-1&gt;TODO&lt;/FONT&gt; tests. As soon as a 
&lt;FONT SIZE=-1&gt;TODO&lt;/FONT&gt; test starts working, it should be promoted to a normal test and the newly minted feature should be documented in the release notes.

&lt;/UL&gt;
&lt;P&gt;
&lt;HR&gt;
&lt;H1&gt;&lt;A NAME="ONFAIL"&gt;ONFAIL&lt;/A&gt;&lt;/H1&gt;
&lt;P&gt;
&lt;PRE&gt;  BEGIN { plan test =&amp;gt; 4, onfail =&amp;gt; sub { warn &amp;quot;CALL 911!&amp;quot; } }
&lt;/PRE&gt;
&lt;P&gt;
The test failures can trigger extra diagnostics at the end of the test run.  &lt;CODE&gt;onfail&lt;/CODE&gt; is passed an array ref of hash refs that describe each test failure. Each
hash will contain at least the following fields: package, repetition, and
result. (The file, line, and test number are not included because their
correspondance to a particular test is fairly weak.) If the test had an
expected value or a diagnostic string, these will also be included.

&lt;P&gt;
This optional feature might be used simply to print out the version of your
package and/or how to report problems. It might also be used to generate
extremely sophisticated diagnostics for a particular test failure. It's not
a panacea, however. Core dumps or other unrecoverable errors will prevent
the &lt;CODE&gt;onfail&lt;/CODE&gt; hook from running. (It is run inside an 
&lt;FONT SIZE=-1&gt;END&lt;/FONT&gt; block.) Besides, &lt;CODE&gt;onfail&lt;/CODE&gt; is probably over-kill in the majority of cases. (Your test code should be
simpler than the code it is testing, yes?)

&lt;P&gt;
&lt;HR&gt;
&lt;H1&gt;&lt;A NAME="SEE_ALSO"&gt;SEE ALSO&lt;/A&gt;&lt;/H1&gt;
&lt;P&gt;
[perlman:Test::Harness|Test::Harness] and various test coverage analysis tools.

&lt;P&gt;
&lt;HR&gt;
&lt;H1&gt;&lt;A NAME="AUTHOR"&gt;AUTHOR&lt;/A&gt;&lt;/H1&gt;
&lt;P&gt;
Copyright 
&lt;FONT SIZE=-1&gt;(C)&lt;/FONT&gt; 1998 Joshua Nathaniel Pritikin. All rights
reserved.

&lt;P&gt;
This package is free software and is provided ``as is'' without express or
implied warranty. It may be used, redistributed and/or modified under the
terms of the Perl Artistic License (see &lt;A
HREF="http://www.perl.com/perl/misc/Artistic.html)"&gt;http://www.perl.com/perl/misc/Artistic.html)&lt;/A&gt;

&lt;HR&gt;
</field>
</data>
</node>
