home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _d2d35c468d8ec5f26f481c270bccffff < prev    next >
Text File  |  2000-03-23  |  6KB  |  158 lines

  1.  
  2. <HTML>
  3. <HEAD>
  4. <TITLE>Test - provides a simple framework for writing test scripts</TITLE>
  5. <LINK REL="stylesheet" HREF="../Active.css" TYPE="text/css">
  6. <LINK REV="made" HREF="mailto:">
  7. </HEAD>
  8.  
  9. <BODY>
  10. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  11. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  12. <STRONG><P CLASS=block> Test - provides a simple framework for writing test scripts</P></STRONG>
  13. </TD></TR>
  14. </TABLE>
  15.  
  16. <A NAME="__index__"></A>
  17. <!-- INDEX BEGIN -->
  18.  
  19. <UL>
  20.  
  21.     <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
  22.  
  23.     <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
  24.     <LI><A HREF="#description">DESCRIPTION</A></LI>
  25.     <LI><A HREF="#test types">TEST TYPES</A></LI>
  26.     <LI><A HREF="#return value">RETURN VALUE</A></LI>
  27.     <LI><A HREF="#onfail">ONFAIL</A></LI>
  28.     <LI><A HREF="#see also">SEE ALSO</A></LI>
  29.     <LI><A HREF="#author">AUTHOR</A></LI>
  30. </UL>
  31. <!-- INDEX END -->
  32.  
  33. <HR>
  34. <P>
  35. <H1><A NAME="name">NAME</A></H1>
  36. <PRE>
  37.   Test - provides a simple framework for writing test scripts</PRE>
  38. <P>
  39. <HR>
  40. <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
  41. <UL>
  42. <LI>Linux</LI>
  43. <LI>Solaris</LI>
  44. <LI>Windows</LI>
  45. </UL>
  46. <HR>
  47. <H1><A NAME="synopsis">SYNOPSIS</A></H1>
  48. <PRE>
  49.   use strict;
  50.   use Test;</PRE>
  51. <PRE>
  52.   # use a BEGIN block so we print our plan before MyModule is loaded
  53.   BEGIN { plan tests => 14, todo => [3,4] }</PRE>
  54. <PRE>
  55.   # load your module...
  56.   use MyModule;</PRE>
  57. <PRE>
  58.   ok(0); # failure
  59.   ok(1); # success</PRE>
  60. <PRE>
  61.   ok(0); # ok, expected failure (see todo list, above)
  62.   ok(1); # surprise success!</PRE>
  63. <PRE>
  64.   ok(0,1);             # failure: '0' ne '1'
  65.   ok('broke','fixed'); # failure: 'broke' ne 'fixed'
  66.   ok('fixed','fixed'); # success: 'fixed' eq 'fixed'
  67.   ok('fixed',qr/x/);   # success: 'fixed' =~ qr/x/</PRE>
  68. <PRE>
  69.   ok(sub { 1+1 }, 2);  # success: '2' eq '2'
  70.   ok(sub { 1+1 }, 3);  # failure: '2' ne '3'
  71.   ok(0, int(rand(2));  # (just kidding :-)</PRE>
  72. <PRE>
  73.   my @list = (0,0);
  74.   ok @list, 3, "\@list=".join(',',@list);      #extra diagnostics
  75.   ok 'segmentation fault', '/(?i)success/';    #regex match</PRE>
  76. <PRE>
  77.   skip($feature_is_missing, ...);    #do platform specific test</PRE>
  78. <P>
  79. <HR>
  80. <H1><A NAME="description">DESCRIPTION</A></H1>
  81. <P><A HREF="../lib/Test/Harness.html">the Test::Harness manpage</A> expects to see particular output when it executes
  82. tests.  This module aims to make writing proper test scripts just a
  83. little bit easier (and less error prone :-).</P>
  84. <P>
  85. <HR>
  86. <H1><A NAME="test types">TEST TYPES</A></H1>
  87. <UL>
  88. <LI><STRONG><A NAME="item_NORMAL_TESTS">NORMAL TESTS</A></STRONG><BR>
  89.  
  90. These tests are expected to succeed.  If they don't something's
  91. screwed up!
  92. <P></P>
  93. <LI><STRONG><A NAME="item_SKIPPED_TESTS">SKIPPED TESTS</A></STRONG><BR>
  94.  
  95. Skip is for tests that might or might not be possible to run depending
  96. on the availability of platform specific features.  The first argument
  97. should evaluate to true (think ``yes, please skip'') if the required
  98. feature is not available.  After the first argument, skip works
  99. exactly the same way as do normal tests.
  100. <P></P>
  101. <LI><STRONG><A NAME="item_TODO_TESTS">TODO TESTS</A></STRONG><BR>
  102.  
  103. TODO tests are designed for maintaining an <STRONG>executable TODO list</STRONG>.
  104. These tests are expected NOT to succeed.  If a TODO test does succeed,
  105. the feature in question should not be on the TODO list, now should it?
  106. <P>Packages should NOT be released with succeeding TODO tests.  As soon
  107. as a TODO test starts working, it should be promoted to a normal test
  108. and the newly working feature should be documented in the release
  109. notes or change log.</P>
  110. <P></P></UL>
  111. <P>
  112. <HR>
  113. <H1><A NAME="return value">RETURN VALUE</A></H1>
  114. <P>Both <CODE>ok</CODE> and <CODE>skip</CODE> return true if their test succeeds and false
  115. otherwise in a scalar context.</P>
  116. <P>
  117. <HR>
  118. <H1><A NAME="onfail">ONFAIL</A></H1>
  119. <PRE>
  120.   BEGIN { plan test => 4, onfail => sub { warn "CALL 911!" } }</PRE>
  121. <P>While test failures should be enough, extra diagnostics can be
  122. triggered at the end of a test run.  <CODE>onfail</CODE> is passed an array ref
  123. of hash refs that describe each test failure.  Each hash will contain
  124. at least the following fields: <A HREF="../lib/Pod/perlfunc.html#item_package"><CODE>package</CODE></A>, <CODE>repetition</CODE>, and
  125. <CODE>result</CODE>.  (The file, line, and test number are not included because
  126. their correspondence to a particular test is tenuous.)  If the test
  127. had an expected value or a diagnostic string, these will also be
  128. included.</P>
  129. <P>The <STRONG>optional</STRONG> <CODE>onfail</CODE> hook might be used simply to print out the
  130. version of your package and/or how to report problems.  It might also
  131. be used to generate extremely sophisticated diagnostics for a
  132. particularly bizarre test failure.  However it's not a panacea.  Core
  133. dumps or other unrecoverable errors prevent the <CODE>onfail</CODE> hook from
  134. running.  (It is run inside an <CODE>END</CODE> block.)  Besides, <CODE>onfail</CODE> is
  135. probably over-kill in most cases.  (Your test code should be simpler
  136. than the code it is testing, yes?)</P>
  137. <P>
  138. <HR>
  139. <H1><A NAME="see also">SEE ALSO</A></H1>
  140. <P><A HREF="../lib/Test/Harness.html">the Test::Harness manpage</A> and, perhaps, test coverage analysis tools.</P>
  141. <P>
  142. <HR>
  143. <H1><A NAME="author">AUTHOR</A></H1>
  144. <P>Copyright (c) 1998-1999 Joshua Nathaniel Pritikin.  All rights reserved.</P>
  145. <P>This package is free software and is provided ``as is'' without express
  146. or implied warranty.  It may be used, redistributed and/or modified
  147. under the terms of the Perl Artistic License (see
  148. <A HREF="http://www.perl.com/perl/misc/Artistic.html)">http://www.perl.com/perl/misc/Artistic.html)</A></P>
  149. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  150. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  151. <STRONG><P CLASS=block> Test - provides a simple framework for writing test scripts</P></STRONG>
  152. </TD></TR>
  153. </TABLE>
  154.  
  155. </BODY>
  156.  
  157. </HTML>
  158.