Install Perl 5.8.8
[msysgit.git] / mingw / html / lib / Test / Simple.html
blob02da838d5451c2212213a68aad7e4d0593737237
1 <?xml version="1.0" ?>
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">
4 <head>
5 <title>Test::Simple - Basic utilities for writing tests.</title>
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 <link rev="made" href="mailto:" />
8 </head>
10 <body style="background-color: white">
11 <table border="0" width="100%" cellspacing="0" cellpadding="3">
12 <tr><td class="block" style="background-color: #cccccc" valign="middle">
13 <big><strong><span class="block">&nbsp;Test::Simple - Basic utilities for writing tests.</span></strong></big>
14 </td></tr>
15 </table>
17 <p><a name="__index__"></a></p>
18 <!-- INDEX BEGIN -->
20 <ul>
22 <li><a href="#name">NAME</a></li>
23 <li><a href="#synopsis">SYNOPSIS</a></li>
24 <li><a href="#description">DESCRIPTION</a></li>
25 <li><a href="#example">EXAMPLE</a></li>
26 <li><a href="#caveats">CAVEATS</a></li>
27 <li><a href="#notes">NOTES</a></li>
28 <li><a href="#history">HISTORY</a></li>
29 <li><a href="#see_also">SEE ALSO</a></li>
30 <li><a href="#authors">AUTHORS</a></li>
31 <li><a href="#copyright">COPYRIGHT</a></li>
32 </ul>
33 <!-- INDEX END -->
35 <hr />
36 <p>
37 </p>
38 <h1><a name="name">NAME</a></h1>
39 <p>Test::Simple - Basic utilities for writing tests.</p>
40 <p>
41 </p>
42 <hr />
43 <h1><a name="synopsis">SYNOPSIS</a></h1>
44 <pre>
45 use Test::Simple tests =&gt; 1;</pre>
46 <pre>
47 ok( $foo eq $bar, 'foo is bar' );</pre>
48 <p>
49 </p>
50 <hr />
51 <h1><a name="description">DESCRIPTION</a></h1>
52 <p>** If you are unfamiliar with testing <strong>read Test::Tutorial</strong> first! **</p>
53 <p>This is an extremely simple, extremely basic module for writing tests
54 suitable for CPAN modules and other pursuits. If you wish to do more
55 complicated testing, use the Test::More module (a drop-in replacement
56 for this one).</p>
57 <p>The basic unit of Perl testing is the ok. For each thing you want to
58 test your program will print out an ``ok'' or ``not ok'' to indicate pass
59 or fail. You do this with the <a href="#item_ok"><code>ok()</code></a> function (see below).</p>
60 <p>The only other constraint is you must pre-declare how many tests you
61 plan to run. This is in case something goes horribly wrong during the
62 test and your test program aborts, or skips a test or whatever. You
63 do this like so:</p>
64 <pre>
65 use Test::Simple tests =&gt; 23;</pre>
66 <p>You must have a plan.</p>
67 <dl>
68 <dt><strong><a name="item_ok"><strong>ok</strong></a></strong>
70 <dd>
71 <pre>
72 ok( $foo eq $bar, $name );
73 ok( $foo eq $bar );</pre>
74 </dd>
75 <dd>
76 <p><a href="#item_ok"><code>ok()</code></a> is given an expression (in this case <code>$foo eq $bar</code>). If it's
77 true, the test passed. If it's false, it didn't. That's about it.</p>
78 </dd>
79 <dd>
80 <p><a href="#item_ok"><code>ok()</code></a> prints out either ``ok'' or ``not ok'' along with a test number (it
81 keeps track of that for you).</p>
82 </dd>
83 <dd>
84 <pre>
85 # This produces &quot;ok 1 - Hell not yet frozen over&quot; (or not ok)
86 ok( get_temperature($hell) &gt; 0, 'Hell not yet frozen over' );</pre>
87 </dd>
88 <dd>
89 <p>If you provide a $name, that will be printed along with the ``ok/not
90 ok'' to make it easier to find your test when if fails (just search for
91 the name). It also makes it easier for the next guy to understand
92 what your test is for. It's highly recommended you use test names.</p>
93 </dd>
94 <dd>
95 <p>All tests are run in scalar context. So this:</p>
96 </dd>
97 <dd>
98 <pre>
99 ok( @stuff, 'I have some stuff' );</pre>
100 </dd>
101 <dd>
102 <p>will do what you mean (fail if stuff is empty)</p>
103 </dd>
104 </dl>
105 <p>Test::Simple will start by printing number of tests run in the form
106 ``1..M'' (so ``1..5'' means you're going to run 5 tests). This strange
107 format lets Test::Harness know how many tests you plan on running in
108 case something goes horribly wrong.</p>
109 <p>If all your tests passed, Test::Simple will exit with zero (which is
110 normal). If anything failed it will exit with how many failed. If
111 you run less (or more) tests than you planned, the missing (or extras)
112 will be considered failures. If no tests were ever run Test::Simple
113 will throw a warning and exit with 255. If the test died, even after
114 having successfully completed all its tests, it will still be
115 considered a failure and will exit with 255.</p>
116 <p>So the exit codes are...</p>
117 <pre>
118 0 all tests successful
119 255 test died or all passed but wrong # of tests run
120 any other number how many failed (including missing or extras)</pre>
121 <p>If you fail more than 254 tests, it will be reported as 254.</p>
122 <p>This module is by no means trying to be a complete testing system.
123 It's just to get you started. Once you're off the ground its
124 recommended you look at <a href="file://C|\msysgit\mingw\html/lib/Test/More.html">the Test::More manpage</a>.</p>
126 </p>
127 <hr />
128 <h1><a name="example">EXAMPLE</a></h1>
129 <p>Here's an example of a simple .t file for the fictional Film module.</p>
130 <pre>
131 use Test::Simple tests =&gt; 5;</pre>
132 <pre>
133 use Film; # What you're testing.</pre>
134 <pre>
135 my $btaste = Film-&gt;new({ Title =&gt; 'Bad Taste',
136 Director =&gt; 'Peter Jackson',
137 Rating =&gt; 'R',
138 NumExplodingSheep =&gt; 1
140 ok( defined($btaste) &amp;&amp; ref $btaste eq 'Film, 'new() works' );</pre>
141 <pre>
142 ok( $btaste-&gt;Title eq 'Bad Taste', 'Title() get' );
143 ok( $btaste-&gt;Director eq 'Peter Jackson', 'Director() get' );
144 ok( $btaste-&gt;Rating eq 'R', 'Rating() get' );
145 ok( $btaste-&gt;NumExplodingSheep == 1, 'NumExplodingSheep() get' );</pre>
146 <p>It will produce output like this:</p>
147 <pre>
148 1..5
149 ok 1 - new() works
150 ok 2 - Title() get
151 ok 3 - Director() get
152 not ok 4 - Rating() get
153 # Failed test 'Rating() get'
154 # in t/film.t at line 14.
155 ok 5 - NumExplodingSheep() get
156 # Looks like you failed 1 tests of 5</pre>
157 <p>Indicating the Film::Rating() method is broken.</p>
159 </p>
160 <hr />
161 <h1><a name="caveats">CAVEATS</a></h1>
162 <p>Test::Simple will only report a maximum of 254 failures in its exit
163 code. If this is a problem, you probably have a huge test script.
164 Split it into multiple files. (Otherwise blame the Unix folks for
165 using an unsigned short integer as the exit status).</p>
166 <p>Because VMS's exit codes are much, much different than the rest of the
167 universe, and perl does horrible mangling to them that gets in my way,
168 it works like this on VMS.</p>
169 <pre>
170 0 SS$_NORMAL all tests successful
171 4 SS$_ABORT something went wrong</pre>
172 <p>Unfortunately, I can't differentiate any further.</p>
174 </p>
175 <hr />
176 <h1><a name="notes">NOTES</a></h1>
177 <p>Test::Simple is <strong>explicitly</strong> tested all the way back to perl 5.004.</p>
178 <p>Test::Simple is thread-safe in perl 5.8.0 and up.</p>
180 </p>
181 <hr />
182 <h1><a name="history">HISTORY</a></h1>
183 <p>This module was conceived while talking with Tony Bowden in his
184 kitchen one night about the problems I was having writing some really
185 complicated feature into the new Testing module. He observed that the
186 main problem is not dealing with these edge cases but that people hate
187 to write tests <strong>at all</strong>. What was needed was a dead simple module
188 that took all the hard work out of testing and was really, really easy
189 to learn. Paul Johnson simultaneously had this idea (unfortunately,
190 he wasn't in Tony's kitchen). This is it.</p>
192 </p>
193 <hr />
194 <h1><a name="see_also">SEE ALSO</a></h1>
195 <dl>
196 <dt><strong><a name="item_test_3a_3amore"><a href="file://C|\msysgit\mingw\html/lib/Test/More.html">the Test::More manpage</a></a></strong>
198 <dd>
199 <p>More testing functions! Once you outgrow Test::Simple, look at
200 Test::More. Test::Simple is 100% forward compatible with Test::More
201 (i.e. you can just use Test::More instead of Test::Simple in your
202 programs and things will still work).</p>
203 </dd>
204 </li>
205 <dt><strong><a name="item_test"><a href="file://C|\msysgit\mingw\html/lib/Test.html">the Test manpage</a></a></strong>
207 <dd>
208 <p>The original Perl testing module.</p>
209 </dd>
210 </li>
211 <dt><strong><a name="item_test_3a_3aunit"><a href="file://C|\msysgit\mingw\html/Test/Unit.html">the Test::Unit manpage</a></a></strong>
213 <dd>
214 <p>Elaborate unit testing.</p>
215 </dd>
216 </li>
217 <dt><strong><a name="item_test_3a_3ainline_2c_selftest"><a href="file://C|\msysgit\mingw\html/Test/Inline.html">the Test::Inline manpage</a>, <em>SelfTest</em></a></strong>
219 <dd>
220 <p>Embed tests in your code!</p>
221 </dd>
222 </li>
223 <dt><strong><a name="item_test_3a_3aharness"><a href="file://C|\msysgit\mingw\html/lib/Test/Harness.html">the Test::Harness manpage</a></a></strong>
225 <dd>
226 <p>Interprets the output of your test program.</p>
227 </dd>
228 </li>
229 </dl>
231 </p>
232 <hr />
233 <h1><a name="authors">AUTHORS</a></h1>
234 <p>Idea by Tony Bowden and Paul Johnson, code by Michael G Schwern
235 &lt;<a href="mailto:schwern@pobox.com">schwern@pobox.com</a>&gt;, wardrobe by Calvin Klein.</p>
237 </p>
238 <hr />
239 <h1><a name="copyright">COPYRIGHT</a></h1>
240 <p>Copyright 2001, 2002, 2004 by Michael G Schwern &lt;<a href="mailto:schwern@pobox.com">schwern@pobox.com</a>&gt;.</p>
241 <p>This program is free software; you can redistribute it and/or
242 modify it under the same terms as Perl itself.</p>
243 <p>See <em><a href="http://www.perl.com/perl/misc/Artistic.html">http://www.perl.com/perl/misc/Artistic.html</a></em></p>
244 <table border="0" width="100%" cellspacing="0" cellpadding="3">
245 <tr><td class="block" style="background-color: #cccccc" valign="middle">
246 <big><strong><span class="block">&nbsp;Test::Simple - Basic utilities for writing tests.</span></strong></big>
247 </td></tr>
248 </table>
250 </body>
252 </html>