straps.html

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

HTML
308
字号
<pre>
    <span class="keyword">my</span> <span class="variable">%results</span> <span class="operator">=</span> <span class="variable">$strap</span><span class="operator">-&gt;</span><span class="variable">analyze_file</span><span class="operator">(</span><span class="variable">$test_file</span><span class="operator">);</span>
</pre>
<p>Like <code>analyze</code>, but it runs the given <code>$test_file</code> and parses its
results.  It will also use that name for the total report.</p>
<p>
</p>
<h2><a name="_strap__command_line___file__">$strap-&gt;_command_line( $file )</a></h2>
<p>Returns the full command line that will be run to test <em>$file</em>.</p>
<p>
</p>
<h2><a name="_strap__command__">$strap-&gt;<code>_command()</code></a></h2>
<p>Returns the command that runs the test.  Combine this with <code>_switches()</code>
to build a command line.</p>
<p>Typically this is <a href="../../../lib/Pod/perlvar.html#item___x"><code>$^X</code></a>, but you can set <code>$ENV{HARNESS_PERL}</code>
to use a different Perl than what you're running the harness under.
This might be to run a threaded Perl, for example.</p>
<p>You can also overload this method if you've built your own strap subclass,
such as a PHP interpreter for a PHP-based strap.</p>
<p>
</p>
<h2><a name="_strap__switches___file__">$strap-&gt;_switches( $file )</a></h2>
<p>Formats and returns the switches necessary to run the test.</p>
<p>
</p>
<h2><a name="_strap__cleaned_switches___switches_from_user__">$strap-&gt;_cleaned_switches( @switches_from_user )</a></h2>
<p>Returns only defined, non-blank, trimmed switches from the parms passed.</p>
<p>
</p>
<h2><a name="_strap__inc2perl5lib">$strap-&gt;_INC2PERL5LIB</a></h2>
<pre>
  <span class="keyword">local</span> <span class="variable">$ENV</span><span class="operator">{</span><span class="string">PERL5LIB</span><span class="operator">}</span> <span class="operator">=</span> <span class="variable">$self</span><span class="operator">-&gt;</span><span class="variable">_INC2PERL5LIB</span><span class="operator">;</span>
</pre>
<p>Takes the current value of <a href="../../../lib/Pod/perlvar.html#item__inc"><code>@INC</code></a> and turns it into something suitable
for putting onto <a href="../../../lib/Pod/perlrun.html#item_perl5lib"><code>PERL5LIB</code></a>.</p>
<p>
</p>
<h2><a name="_strap__filtered_inc__">$strap-&gt;<code>_filtered_INC()</code></a></h2>
<pre>
  <span class="keyword">my</span> <span class="variable">@filtered_inc</span> <span class="operator">=</span> <span class="variable">$self</span><span class="operator">-&gt;</span><span class="variable">_filtered_INC</span><span class="operator">;</span>
</pre>
<p>Shortens <a href="../../../lib/Pod/perlvar.html#item__inc"><code>@INC</code></a> by removing redundant and unnecessary entries.
Necessary for OSes with limited command line lengths, like VMS.</p>
<p>
</p>
<h2><a name="_strap__restore_perl5lib__">$strap-&gt;<code>_restore_PERL5LIB()</code></a></h2>
<pre>
  <span class="variable">$self</span><span class="operator">-&gt;</span><span class="variable">_restore_PERL5LIB</span><span class="operator">;</span>
</pre>
<p>This restores the original value of the <a href="../../../lib/Pod/perlrun.html#item_perl5lib"><code>PERL5LIB</code></a> environment variable.
Necessary on VMS, otherwise a no-op.</p>
<p>
</p>
<hr />
<h1><a name="parsing">Parsing</a></h1>
<p>Methods for identifying what sort of line you're looking at.</p>
<p>
</p>
<h2><a name="_is_diagnostic"><code>_is_diagnostic</code></a></h2>
<pre>
    <span class="keyword">my</span> <span class="variable">$is_diagnostic</span> <span class="operator">=</span> <span class="variable">$strap</span><span class="operator">-&gt;</span><span class="variable">_is_diagnostic</span><span class="operator">(</span><span class="variable">$line</span><span class="operator">,</span> <span class="operator">\</span><span class="variable">$comment</span><span class="operator">);</span>
</pre>
<p>Checks if the given line is a comment.  If so, it will place it into
<code>$comment</code> (sans #).</p>
<p>
</p>
<h2><a name="_is_header"><code>_is_header</code></a></h2>
<pre>
  <span class="keyword">my</span> <span class="variable">$is_header</span> <span class="operator">=</span> <span class="variable">$strap</span><span class="operator">-&gt;</span><span class="variable">_is_header</span><span class="operator">(</span><span class="variable">$line</span><span class="operator">);</span>
</pre>
<p>Checks if the given line is a header (1..M) line.  If so, it places how
many tests there will be in <code>$strap-&gt;{max}</code>, a list of which tests
are todo in <code>$strap-&gt;{todo}</code> and if the whole test was skipped
<code>$strap-&gt;{skip_all}</code> contains the reason.</p>
<p>
</p>
<h2><a name="_is_bail_out"><code>_is_bail_out</code></a></h2>
<pre>
  <span class="keyword">my</span> <span class="variable">$is_bail_out</span> <span class="operator">=</span> <span class="variable">$strap</span><span class="operator">-&gt;</span><span class="variable">_is_bail_out</span><span class="operator">(</span><span class="variable">$line</span><span class="operator">,</span> <span class="operator">\</span><span class="variable">$reason</span><span class="operator">);</span>
</pre>
<p>Checks if the line is a &quot;Bail out!&quot;.  Places the reason for bailing
(if any) in $reason.</p>
<p>
</p>
<h2><a name="_reset_file_state"><code>_reset_file_state</code></a></h2>
<pre>
  <span class="variable">$strap</span><span class="operator">-&gt;</span><span class="variable">_reset_file_state</span><span class="operator">;</span>
</pre>
<p>Resets things like <code>$strap-&gt;{max}</code> , <code>$strap-&gt;{skip_all}</code>,
etc. so it's ready to parse the next file.</p>
<p>
</p>
<hr />
<h1><a name="results">Results</a></h1>
<p>The <code>%results</code> returned from <code>analyze()</code> contain the following
information:</p>
<pre>
  passing           true if the whole test is considered a pass 
                    (or skipped), false if its a failure</pre>
<pre>
  exit              the exit code of the test run, if from a file
  wait              the wait code of the test run, if from a file</pre>
<pre>
  max               total tests which should have been run
  seen              total tests actually seen
  skip_all          if the whole test was skipped, this will 
                      contain the reason.</pre>
<pre>
  ok                number of tests which passed 
                      (including todo and skips)</pre>
<pre>
  todo              number of todo tests seen
  bonus             number of todo tests which 
                      unexpectedly passed</pre>
<pre>
  skip              number of tests skipped</pre>
<p>So a successful test should have max == seen == ok.</p>
<p>There is one final item, the details.</p>
<pre>
  details           an array ref reporting the result of 
                    each test looks like this:</pre>
<pre>
    <span class="variable">$results</span><span class="operator">{</span><span class="string">details</span><span class="operator">}[</span><span class="variable">$test_num</span> <span class="operator">-</span> <span class="number">1</span><span class="operator">]</span> <span class="operator">=</span> 
            <span class="operator">{</span> <span class="string">ok</span>          <span class="operator">=&gt;</span> <span class="variable">is</span> <span class="variable">the</span> <span class="variable">test</span> <span class="variable">considered</span> <span class="variable">ok</span><span class="operator">?</span>
              <span class="string">actual_ok</span>   <span class="operator">=&gt;</span> <span class="variable">did</span> <span class="variable">it</span> <span class="variable">literally</span> <span class="variable">say</span> <span class="string">'ok'</span><span class="operator">?</span>
              <span class="string">name</span>        <span class="operator">=&gt;</span> <span class="variable">name</span> <span class="variable">of</span> <span class="variable">the</span> <span class="variable">test</span> <span class="operator">(</span><span class="keyword">if</span> <span class="variable">any</span><span class="operator">)</span>
              <span class="string">diagnostics</span> <span class="operator">=&gt;</span> <span class="variable">test</span> <span class="variable">diagnostics</span> <span class="operator">(</span><span class="keyword">if</span> <span class="variable">any</span><span class="operator">)</span>
              <span class="string">type</span>        <span class="operator">=&gt;</span> <span class="string">'skip'</span> <span class="keyword">or</span> <span class="string">'todo'</span> <span class="operator">(</span><span class="keyword">if</span> <span class="variable">any</span><span class="operator">)</span>
              <span class="string">reason</span>      <span class="operator">=&gt;</span> <span class="variable">reason</span> <span class="keyword">for</span> <span class="variable">the</span> <span class="variable">above</span> <span class="operator">(</span><span class="keyword">if</span> <span class="variable">any</span><span class="operator">)</span>
            <span class="operator">}</span><span class="operator">;</span>
</pre>
<p>Element 0 of the details is test #1.  I tried it with element 1 being
#1 and 0 being empty, this is less awkward.</p>
<p>
</p>
<hr />
<h1><a name="examples">EXAMPLES</a></h1>
<p>See <em>examples/mini_harness.plx</em> for an example of use.</p>
<p>
</p>
<hr />
<h1><a name="author">AUTHOR</a></h1>
<p>Michael G Schwern <code>&lt;schwern@pobox.com&gt;</code>, currently maintained by
Andy Lester <code>&lt;andy@petdance.com&gt;</code>.</p>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p><a href="../../../lib/Test/Harness.html">the Test::Harness manpage</a></p>

</body>

</html>

⌨️ 快捷键说明

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