harness.html

来自「perl教程」· HTML 代码 · 共 465 行 · 第 1/2 页

HTML
465 行
字号
<dt><strong><a name="item_failed_tests__25s_5cn_5ctfailed__25d_2f_25d_tests_"><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="item_d"><code>Test returned status %d (wstat %d)</code></a></strong>

<dd>
<p>Scripts that return a non-zero exit status, both <a href="../../lib/Pod/perlvar.html#item__"><code>$? &gt;&gt; 8</code></a>
and <a href="../../lib/Pod/perlvar.html#item__"><code>$?</code></a> are printed in a message similar to the above.</p>
</dd>
</li>
<dt><strong><a name="item_failed_1_test_2c__25_2e2f_25_25_okay_2e__25s"><code>Failed 1 test, %.2f%% okay. %s</code></a></strong>

<dt><strong><a name="item_failed__25d_2f_25d_tests_2c__25_2e2f_25_25_okay_2e"><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="item_failed_2d_2dfurther_testing_stopped_3a__25s"><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="item_harness_active"><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="item_harness_version"><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="item_harness_columns"><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="item_harness_compile_test"><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="item_harness_debug"><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="#item_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="../../lib/Pod/perlrun.html#item__2dd"><code>-d</code></a> switch in the <em>prove</em> utility.</p>
</dd>
</li>
<dt><strong><a name="item_harness_fileleak_in_dir"><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 <a href="#item_runtests"><code>runtests()</code></a> was called.  Putting absolute path into 
<a href="#item_harness_fileleak_in_dir"><code>HARNESS_FILELEAK_IN_DIR</code></a> may give more predictable results.</p>
</dd>
</li>
<dt><strong><a name="item_harness_ignore_exitcode"><code>HARNESS_IGNORE_EXITCODE</code></a></strong>

<dd>
<p>Makes harness ignore the exit status of child processes when defined.</p>
</dd>
</li>
<dt><strong><a name="item_harness_notty"><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="item_harness_perl"><code>HARNESS_PERL</code></a></strong>

<dd>
<p>Usually your tests will be run by <a href="../../lib/Pod/perlvar.html#item___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>prove</em> utility, you can use the <code>--perl</code> switch.</p>
</dd>
</li>
<dt><strong><a name="item_harness_perl_switches"><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="#item_harness_perl_switches"><code>HARNESS_PERL_SWITCHES</code></a> to <a href="../../lib/Pod/perlrun.html#item__2dw"><code>-W</code></a> will
run all tests with all warnings enabled.</p>
</dd>
</li>
<dt><strong><a name="item_harness_verbose"><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="../../lib/Pod/perlrun.html#item__2dv"><code>-v</code></a> switch in the <em>prove</em> utility.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="example">EXAMPLE</a></h1>
<p>Here's how Test::Harness tests itself</p>
<pre>
  <span class="operator">$ </span><span class="variable">cd</span> <span class="operator">~</span><span class="regex">/src/devel</span><span class="operator">/</span><span class="variable">Test</span><span class="operator">-</span><span class="variable">Harness</span>
  <span class="operator">$ </span><span class="variable">perl</span> <span class="operator">-</span><span class="variable">Mblib</span> <span class="keyword">-e</span> <span class="string">'use Test::Harness qw(&amp;runtests $verbose);
    $verbose=0; runtests @ARGV;'</span> <span class="variable">t</span><span class="operator">/*.</span><span class="variable">t</span>
  <span class="variable">Using</span> <span class="operator">/</span><span class="variable">home</span><span class="operator">/</span><span class="variable">schwern</span><span class="operator">/</span><span class="variable">src</span><span class="operator">/</span><span class="variable">devel</span><span class="operator">/</span><span class="variable">Test</span><span class="operator">-</span><span class="variable">Harness</span><span class="operator">/</span><span class="variable">blib</span>
  <span class="variable">t</span><span class="operator">/</span><span class="variable">base</span><span class="operator">..............</span><span class="variable">ok</span>
  <span class="variable">t</span><span class="operator">/</span><span class="variable">nonumbers</span><span class="operator">.........</span><span class="variable">ok</span>
  <span class="variable">t</span><span class="operator">/</span><span class="variable">ok</span><span class="operator">................</span><span class="variable">ok</span>
  <span class="variable">t</span><span class="operator">/</span><span class="variable">test</span><span class="operator">-</span><span class="variable">harness</span><span class="operator">......</span><span class="variable">ok</span>
  <span class="variable">All</span> <span class="variable">tests</span> <span class="variable">successful</span><span class="operator">.</span>
  <span class="variable">Files</span><span class="operator">=</span><span class="number">4</span><span class="operator">,</span> <span class="variable">Tests</span><span class="operator">=</span><span class="number">24</span><span class="operator">,</span> <span class="number">2</span> <span class="variable">wallclock</span> <span class="variable">secs</span> <span class="operator">(</span> <span class="number">0</span><span class="operator">.</span><span class="number">61</span> <span class="variable">cusr</span> <span class="operator">+</span> <span class="number">0</span><span class="operator">.</span><span class="number">41</span> <span class="variable">csys</span> <span class="operator">=</span> <span class="number">1.02</span> <span class="variable">CPU</span><span class="operator">)</span>
</pre>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p>The included <em>prove</em> utility for running test scripts from the command line,
<a href="../../lib/Test.html">the Test manpage</a> and <a href="../../lib/Test/Simple.html">the Test::Simple manpage</a> for writing test scripts, <a href="../../lib/Benchmark.html">the Benchmark manpage</a> for
the underlying timing routines, and <a href="../../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 <a href="#item_runtests"><code>runtests()</code></a> 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>Implement Straps callbacks.  (experimentally implemented)</p>
<p>Straps-&gt;<code>analyze_file()</code> not taint clean, don't know if it can be</p>
<p>Fix that damned VMS nit.</p>
<p>HARNESS_TODOFAIL to display TODO failures</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 <a href="#item__run_all_tests"><code>_run_all_tests()</code></a></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>HARNESS_COMPILE_TEST currently assumes it's run from the Perl source
directory.</p>
<p>Please use the CPAN bug ticketing system at <a href="http://rt.cpan.org/">http://rt.cpan.org/</a>.
You can also mail bugs, fixes and enhancements to 
<code>&lt;bug-test-harness</code> at <code>rt.cpan.org&gt;</code>.</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 TEST 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>&lt;andy at petdance.com&gt;</code>.</p>
<p>
</p>
<hr />
<h1><a name="copyright">COPYRIGHT</a></h1>
<p>Copyright 2002-2005
by Michael G Schwern <code>&lt;schwern at pobox.com&gt;</code>,
Andy Lester <code>&lt;andy at petdance.com&gt;</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>

</body>

</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?