Edit D:\app\Administrator\product\11.2.0\dbhome_1\perl\html\lib\Test\Harness.html
<?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Test::Harness - Run Perl standard test scripts with statistics</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rev="made" href="mailto:" /> </head> <body style="background-color: white"> <table border="0" width="100%" cellspacing="0" cellpadding="3"> <tr><td class="block" style="background-color: #cccccc" valign="middle"> <big><strong><span class="block"> Test::Harness - Run Perl standard test scripts with statistics</span></strong></big> </td></tr> </table> <!-- INDEX BEGIN --> <div name="index"> <p><a name="__index__"></a></p> <ul> <li><a href="#name">NAME</a></li> <li><a href="#version">VERSION</a></li> <li><a href="#synopsis">SYNOPSIS</a></li> <li><a href="#description">DESCRIPTION</a></li> <ul> <li><a href="#taint_mode">Taint mode</a></li> <li><a href="#configuration_variables_">Configuration variables.</a></li> <li><a href="#failure">Failure</a></li> </ul> <li><a href="#functions">FUNCTIONS</a></li> <ul> <li><a href="#runtests___test_files__">runtests( @test_files )</a></li> <li><a href="#execute_tests__tests______test_files__out______fh__">execute_tests( tests => \@test_files, out => \*FH )</a></li> </ul> <li><a href="#export">EXPORT</a></li> <li><a href="#diagnostics">DIAGNOSTICS</a></li> <li><a href="#environment_variables_that_test__harness_sets">ENVIRONMENT VARIABLES THAT TEST::HARNESS SETS</a></li> <li><a href="#environment_variables_that_affect_test__harness">ENVIRONMENT VARIABLES THAT AFFECT TEST::HARNESS</a></li> <li><a href="#example">EXAMPLE</a></li> <li><a href="#see_also">SEE ALSO</a></li> <li><a href="#todo">TODO</a></li> <li><a href="#bugs">BUGS</a></li> <li><a href="#support">SUPPORT</a></li> <li><a href="#source_code">SOURCE CODE</a></li> <li><a href="#authors">AUTHORS</a></li> <li><a href="#copyright">COPYRIGHT</a></li> </ul> <hr name="index" /> </div> <!-- INDEX END --> <p> </p> <h1><a name="name">NAME</a></h1> <p>Test::Harness - Run Perl standard test scripts with statistics</p> <p> </p> <hr /> <h1><a name="version">VERSION</a></h1> <p>Version 2.64</p> <p> </p> <hr /> <h1><a name="synopsis">SYNOPSIS</a></h1> <pre> use Test::Harness;</pre> <pre> runtests(@test_files);</pre> <p> </p> <hr /> <h1><a name="description">DESCRIPTION</a></h1> <p><strong>STOP!</strong> If all you want to do is write a test script, consider using Test::Simple. Test::Harness is the module that reads the output from Test::Simple, Test::More and other modules based on Test::Builder. You don't need to know about Test::Harness to use those modules.</p> <p>Test::Harness runs tests and expects output from the test in a certain format. That format is called TAP, the Test Anything Protocol. It is defined in <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/lib/Test/Harness/TAP.html">the Test::Harness::TAP manpage</a>.</p> <p><code>Test::Harness::runtests(@tests)</code> runs all the testscripts named as arguments and checks standard output for the expected strings in TAP format.</p> <p>The <em class="file">prove</em> utility is a thin wrapper around Test::Harness.</p> <p> </p> <h2><a name="taint_mode">Taint mode</a></h2> <p>Test::Harness will honor the <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlrun.html#t"><code>-T</code></a> or <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlrun.html#t"><code>-t</code></a> in the #! line on your test files. So if you begin a test with:</p> <pre> #!perl -T</pre> <p>the test will be run with taint mode on.</p> <p> </p> <h2><a name="configuration_variables_">Configuration variables.</a></h2> <p>These variables can be used to configure the behavior of Test::Harness. They are exported on request.</p> <dl> <dt><strong><a name="_test__harness__verbose" class="item"><code>$Test::Harness::Verbose</code></a></strong> <dd> <p>The package variable <a href="#_test__harness__verbose"><code>$Test::Harness::Verbose</code></a> is exportable and can be used to let <code>runtests()</code> display the standard output of the script without altering the behavior otherwise. The <em class="file">prove</em> utility's <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlrun.html#v"><code>-v</code></a> flag will set this.</p> </dd> </li> <dt><strong><a name="_test__harness__switches" class="item"><code>$Test::Harness::switches</code></a></strong> <dd> <p>The package variable <a href="#_test__harness__switches"><code>$Test::Harness::switches</code></a> is exportable and can be used to set perl command line options used for running the test script(s). The default value is <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlrun.html#w"><code>-w</code></a>. It overrides <a href="#harness_perl_switches"><code>HARNESS_PERL_SWITCHES</code></a>.</p> </dd> </li> <dt><strong><a name="_test__harness__timer" class="item"><code>$Test::Harness::Timer</code></a></strong> <dd> <p>If set to true, and <code>Time::HiRes</code> is available, print elapsed seconds after each test file.</p> </dd> </li> </dl> <p> </p> <h2><a name="failure">Failure</a></h2> <p>When tests fail, analyze the summary report:</p> <pre> t/base..............ok t/nonumbers.........ok t/ok................ok t/test-harness......ok t/waterloo..........dubious Test returned status 3 (wstat 768, 0x300) DIED. FAILED tests 1, 3, 5, 7, 9, 11, 13, 15, 17, 19 Failed 10/20 tests, 50.00% okay Failed Test Stat Wstat Total Fail List of Failed --------------------------------------------------------------- t/waterloo.t 3 768 20 10 1 3 5 7 9 11 13 15 17 19 Failed 1/5 test scripts, 80.00% okay. 10/44 subtests failed, 77.27% okay.</pre> <p>Everything passed but <em class="file">t/waterloo.t</em>. It failed 10 of 20 tests and exited with non-zero status indicating something dubious happened.</p> <p>The columns in the summary report mean:</p> <dl> <dt><strong><a name="failed_test" class="item"><strong>Failed Test</strong></a></strong> <dd> <p>The test file which failed.</p> </dd> </li> <dt><strong><a name="stat" class="item"><strong>Stat</strong></a></strong> <dd> <p>If the test exited with non-zero, this is its exit status.</p> </dd> </li> <dt><strong><a name="wstat" class="item"><strong>Wstat</strong></a></strong> <dd> <p>The wait status of the test.</p> </dd> </li> <dt><strong><a name="total" class="item"><strong>Total</strong></a></strong> <dd> <p>Total number of tests expected to run.</p> </dd> </li> <dt><strong><a name="fail" class="item"><strong>Fail</strong></a></strong> <dd> <p>Number which failed, either from "not ok" or because they never ran.</p> </dd> </li> <dt><strong><a name="list_of_failed" class="item"><strong>List of Failed</strong></a></strong> <dd> <p>A list of the tests which failed. Successive failures may be abbreviated (ie. 15-20 to indicate that tests 15, 16, 17, 18, 19 and 20 failed).</p> </dd> </li> </dl> <p> </p> <hr /> <h1><a name="functions">FUNCTIONS</a></h1> <p>The following functions are available.</p> <p> </p> <h2><a name="runtests___test_files__">runtests( @test_files )</a></h2> <p>This runs all the given <em>@test_files</em> and divines whether they passed or failed based on their output to STDOUT (details above). It prints out each individual test which failed along with a summary report and a how long it all took.</p> <p>It returns true if everything was ok. Otherwise it will <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlfunc.html#die"><code>die()</code></a> with one of the messages in the DIAGNOSTICS section.</p> <p> </p> <h2><a name="execute_tests__tests______test_files__out______fh__">execute_tests( tests => \@test_files, out => \*FH )</a></h2> <p>Runs all the given <code>@test_files</code> (just like <code>runtests()</code>) but doesn't generate the final report. During testing, progress information will be written to the currently selected output filehandle (usually <code>STDOUT</code>), or to the filehandle given by the <code>out</code> parameter. The <em>out</em> is optional.</p> <p>Returns a list of two values, <code>$total</code> and <code>$failed</code>, describing the results. <code>$total</code> is a hash ref summary of all the tests run. Its keys and values are this:</p> <pre> bonus Number of individual todo tests unexpectedly passed max Number of individual tests ran ok Number of individual tests passed sub_skipped Number of individual tests skipped todo Number of individual todo tests</pre> <pre> files Number of test files ran good Number of test files passed bad Number of test files failed tests Number of test files originally given skipped Number of test files skipped</pre> <p>If <code>$total->{bad} == 0</code> and <code>$total->{max} > 0</code>, you've got a successful test.</p> <p><code>$failed</code> is a hash ref of all the test scripts that failed. Each key is the name of a test script, each value is another hash representing how that script failed. Its keys are these:</p> <pre> name Name of the test which failed estat Script's exit value wstat Script's wait status max Number of individual tests failed Number which failed canon List of tests which failed (as string).</pre> <p><code>$failed</code> should be empty if everything passed.</p> <pre> my($leader, $ml) = _mk_leader($test_file, $width);</pre> <p>Generates the 't/foo........' leader for the given <code>$test_file</code> as well as a similar version which will overwrite the current line (by use of \r and such). <code>$ml</code> may be empty if Test::Harness doesn't think you're on TTY.</p> <p>The <code>$width</code> is the width of the "yada/blah.." string.</p> <pre> my($width) = _leader_width(@test_files);</pre> <p>Calculates how wide the leader should be based on the length of the longest test name.</p> <p> </p> <hr /> <h1><a name="export">EXPORT</a></h1> <p><code>&runtests</code> is exported by Test::Harness by default.</p> <p><code>&execute_tests</code>, <code>$verbose</code>, <code>$switches</code> and <code>$debug</code> are exported upon request.</p> <p> </p> <hr /> <h1><a name="diagnostics">DIAGNOSTICS</a></h1> <dl> <dt><strong><a name="all_tests_successful_nfiles_d_tests_d_s" class="item"><code>All tests successful.\nFiles=%d, Tests=%d, %s</code></a></strong> <dd> <p>If all tests are successful some statistics about the performance are printed.</p> </dd> </li> <dt><strong><a name="failed_tests_s_n_tfailed_d_d_tests_2f_okay" class="item"><code>FAILED tests %s\n\tFailed %d/%d tests, %.2f%% okay.</code></a></strong> <dd> <p>For any single script that has failing subtests statistics like the above are printed.</p> </dd> </li> <dt><strong><a name="d" class="item"><code>Test returned status %d (wstat %d)</code></a></strong> <dd> <p>Scripts that return a non-zero exit status, both <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlvar.html#_"><code>$? >> 8</code></a> and <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlvar.html#_"><code>$?</code></a> are printed in a message similar to the above.</p> </dd> </li> <dt><strong><a name="failed_1_test_2f_okay_s" class="item"><code>Failed 1 test, %.2f%% okay. %s</code></a></strong> <dt><strong><a name="failed_d_d_tests_2f_okay_s" class="item"><code>Failed %d/%d tests, %.2f%% okay. %s</code></a></strong> <dd> <p>If not all tests were successful, the script dies with one of the above messages.</p> </dd> </li> <dt><strong><a name="failed_further_testing_stopped_s" class="item"><code>FAILED--Further testing stopped: %s</code></a></strong> <dd> <p>If a single subtest decides that further testing will not make sense, the script dies with this message.</p> </dd> </li> </dl> <p> </p> <hr /> <h1><a name="environment_variables_that_test__harness_sets">ENVIRONMENT VARIABLES THAT TEST::HARNESS SETS</a></h1> <p>Test::Harness sets these before executing the individual tests.</p> <dl> <dt><strong><a name="harness_active" class="item"><code>HARNESS_ACTIVE</code></a></strong> <dd> <p>This is set to a true value. It allows the tests to determine if they are being executed through the harness or by any other means.</p> </dd> </li> <dt><strong><a name="harness_version" class="item"><code>HARNESS_VERSION</code></a></strong> <dd> <p>This is the version of Test::Harness.</p> </dd> </li> </dl> <p> </p> <hr /> <h1><a name="environment_variables_that_affect_test__harness">ENVIRONMENT VARIABLES THAT AFFECT TEST::HARNESS</a></h1> <dl> <dt><strong><a name="harness_columns" class="item"><code>HARNESS_COLUMNS</code></a></strong> <dd> <p>This value will be used for the width of the terminal. If it is not set then it will default to <code>COLUMNS</code>. If this is not set, it will default to 80. Note that users of Bourne-sh based shells will need to <code>export COLUMNS</code> for this module to use that variable.</p> </dd> </li> <dt><strong><a name="harness_compile_test" class="item"><code>HARNESS_COMPILE_TEST</code></a></strong> <dd> <p>When true it will make harness attempt to compile the test using <code>perlcc</code> before running it.</p> </dd> <dd> <p><strong>NOTE</strong> This currently only works when sitting in the perl source directory!</p> </dd> </li> <dt><strong><a name="harness_debug" class="item"><code>HARNESS_DEBUG</code></a></strong> <dd> <p>If true, Test::Harness will print debugging information about itself as it runs the tests. This is different from <a href="#harness_verbose"><code>HARNESS_VERBOSE</code></a>, which prints the output from the test being run. Setting <code>$Test::Harness::Debug</code> will override this, or you can use the <a href="#d"><code>-d</code></a> switch in the <em class="file">prove</em> utility.</p> </dd> </li> <dt><strong><a name="harness_fileleak_in_dir" class="item"><code>HARNESS_FILELEAK_IN_DIR</code></a></strong> <dd> <p>When set to the name of a directory, harness will check after each test whether new files appeared in that directory, and report them as</p> </dd> <dd> <pre> LEAKED FILES: scr.tmp 0 my.db</pre> </dd> <dd> <p>If relative, directory name is with respect to the current directory at the moment <code>runtests()</code> was called. Putting absolute path into <a href="#harness_fileleak_in_dir"><code>HARNESS_FILELEAK_IN_DIR</code></a> may give more predictable results.</p> </dd> </li> <dt><strong><a name="harness_notty" class="item"><code>HARNESS_NOTTY</code></a></strong> <dd> <p>When set to a true value, forces it to behave as though STDOUT were not a console. You may need to set this if you don't want harness to output more frequent progress messages using carriage returns. Some consoles may not handle carriage returns properly (which results in a somewhat messy output).</p> </dd> </li> <dt><strong><a name="harness_perl" class="item"><code>HARNESS_PERL</code></a></strong> <dd> <p>Usually your tests will be run by <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlvar.html#__x"><code>$^X</code></a>, the currently-executing Perl. However, you may want to have it run by a different executable, such as a threading perl, or a different version.</p> </dd> <dd> <p>If you're using the <em class="file">prove</em> utility, you can use the <code>--perl</code> switch.</p> </dd> </li> <dt><strong><a name="harness_perl_switches" class="item"><code>HARNESS_PERL_SWITCHES</code></a></strong> <dd> <p>Its value will be prepended to the switches used to invoke perl on each test. For example, setting <a href="#harness_perl_switches"><code>HARNESS_PERL_SWITCHES</code></a> to <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlrun.html#w"><code>-W</code></a> will run all tests with all warnings enabled.</p> </dd> </li> <dt><strong><a name="harness_timer" class="item"><code>HARNESS_TIMER</code></a></strong> <dd> <p>Setting this to true will make the harness display the number of milliseconds each test took. You can also use <em class="file">prove</em>'s <code>--timer</code> switch.</p> </dd> </li> <dt><strong><a name="harness_verbose" class="item"><code>HARNESS_VERBOSE</code></a></strong> <dd> <p>If true, Test::Harness will output the verbose results of running its tests. Setting <code>$Test::Harness::verbose</code> will override this, or you can use the <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlrun.html#v"><code>-v</code></a> switch in the <em class="file">prove</em> utility.</p> </dd> <dd> <p>If true, Test::Harness will output the verbose results of running its tests. Setting <code>$Test::Harness::verbose</code> will override this, or you can use the <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlrun.html#v"><code>-v</code></a> switch in the <em class="file">prove</em> utility.</p> </dd> </li> <dt><strong><a name="harness_strap_class" class="item"><code>HARNESS_STRAP_CLASS</code></a></strong> <dd> <p>Defines the Test::Harness::Straps subclass to use. The value may either be a filename or a class name.</p> </dd> <dd> <p>If HARNESS_STRAP_CLASS is a class name, the class must be in <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlvar.html#_inc"><code>@INC</code></a> like any other class.</p> </dd> <dd> <p>If HARNESS_STRAP_CLASS is a filename, the .pm file must return the name of the class, instead of the canonical "1".</p> </dd> </li> </dl> <p> </p> <hr /> <h1><a name="example">EXAMPLE</a></h1> <p>Here's how Test::Harness tests itself</p> <pre> $ cd ~/src/devel/Test-Harness $ perl -Mblib -e 'use Test::Harness qw(&runtests $verbose); $verbose=0; runtests @ARGV;' t/*.t Using /home/schwern/src/devel/Test-Harness/blib t/base..............ok t/nonumbers.........ok t/ok................ok t/test-harness......ok All tests successful. Files=4, Tests=24, 2 wallclock secs ( 0.61 cusr + 0.41 csys = 1.02 CPU)</pre> <p> </p> <hr /> <h1><a name="see_also">SEE ALSO</a></h1> <p>The included <em class="file">prove</em> utility for running test scripts from the command line, <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/lib/Test.html">the Test manpage</a> and <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/lib/Test/Simple.html">the Test::Simple manpage</a> for writing test scripts, <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/lib/Benchmark.html">the Benchmark manpage</a> for the underlying timing routines, and <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/Devel/Cover.html">the Devel::Cover manpage</a> for test coverage analysis.</p> <p> </p> <hr /> <h1><a name="todo">TODO</a></h1> <p>Provide a way of running tests quietly (ie. no printing) for automated validation of tests. This will probably take the form of a version of <code>runtests()</code> which rather than printing its output returns raw data on the state of the tests. (Partially done in Test::Harness::Straps)</p> <p>Document the format.</p> <p>Fix HARNESS_COMPILE_TEST without breaking its core usage.</p> <p>Figure a way to report test names in the failure summary.</p> <p>Rework the test summary so long test names are not truncated as badly. (Partially done with new skip test styles)</p> <p>Add option for coverage analysis.</p> <p>Trap STDERR.</p> <p>Implement Straps <code>total_results()</code></p> <p>Remember exit code</p> <p>Completely redo the print summary code.</p> <p>Straps-><code>analyze_file()</code> not taint clean, don't know if it can be</p> <p>Fix that damned VMS nit.</p> <p>Add a test for verbose.</p> <p>Change internal list of test results to a hash.</p> <p>Fix stats display when there's an overrun.</p> <p>Fix so perls with spaces in the filename work.</p> <p>Keeping whittling away at <code>_run_all_tests()</code></p> <p>Clean up how the summary is printed. Get rid of those damned formats.</p> <p> </p> <hr /> <h1><a name="bugs">BUGS</a></h1> <p>Please report any bugs or feature requests to <code>bug-test-harness at rt.cpan.org</code>, or through the web interface at <a href="http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Harness">http://rt.cpan.org/NoAuth/ReportBug.html</a>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.</p> <p> </p> <hr /> <h1><a name="support">SUPPORT</a></h1> <p>You can find documentation for this module with the <em class="file">perldoc</em> command.</p> <pre> <a href="//C|\ADE\aime_smenon_perl_090715\perl\html/pod/perldoc.html">perldoc</a> Test::Harness</pre> <p>You can get docs for <em class="file">prove</em> with</p> <pre> prove --man</pre> <p>You can also look for information at:</p> <ul> <li><strong><a name="annocpan_annotated_cpan_documentation" class="item">AnnoCPAN: Annotated CPAN documentation</a></strong> <p><a href="http://annocpan.org/dist/Test-Harness">http://annocpan.org/dist/Test-Harness</a></p> </li> <li><strong><a name="cpan_ratings" class="item">CPAN Ratings</a></strong> <p><a href="http://cpanratings.perl.org/d/Test-Harness">http://cpanratings.perl.org/d/Test-Harness</a></p> </li> <li><strong><a name="rt_cpan_s_request_tracker" class="item">RT: CPAN's request tracker</a></strong> <p><a href="http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Harness">http://rt.cpan.org/NoAuth/Bugs.html</a></p> </li> <li><strong><a name="search_cpan" class="item">Search CPAN</a></strong> <p><a href="http://search.cpan.org/dist/Test-Harness">http://search.cpan.org/dist/Test-Harness</a></p> </li> </ul> <p> </p> <hr /> <h1><a name="source_code">SOURCE CODE</a></h1> <p>The source code repository for Test::Harness is at <a href="http://svn.perl.org/modules/Test-Harness">http://svn.perl.org/modules/Test-Harness</a>.</p> <p> </p> <hr /> <h1><a name="authors">AUTHORS</a></h1> <p>Either Tim Bunce or Andreas Koenig, we don't know. What we know for sure is, that it was inspired by Larry Wall's <em class="file">TEST</em> script that came with perl distributions for ages. Numerous anonymous contributors exist. Andreas Koenig held the torch for many years, and then Michael G Schwern.</p> <p>Current maintainer is Andy Lester <code><andy at petdance.com></code>.</p> <p> </p> <hr /> <h1><a name="copyright">COPYRIGHT</a></h1> <p>Copyright 2002-2006 by Michael G Schwern <code><schwern at pobox.com></code>, Andy Lester <code><andy at petdance.com></code>.</p> <p>This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.</p> <p>See <a href="http://www.perl.com/perl/misc/Artistic.html">http://www.perl.com/perl/misc/Artistic.html</a>.</p> <table border="0" width="100%" cellspacing="0" cellpadding="3"> <tr><td class="block" style="background-color: #cccccc" valign="middle"> <big><strong><span class="block"> Test::Harness - Run Perl standard test scripts with statistics</span></strong></big> </td></tr> </table> </body> </html>
Ms-Dos/Windows
Unix
Write backup
jsp File Browser version 1.2 by
www.vonloesch.de