tester.html
来自「perl教程」· HTML 代码 · 共 348 行 · 第 1/2 页
HTML
348 行
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../../displayToc.js"></script>
<script language="JavaScript" src="../../../tocParas.js"></script>
<script language="JavaScript" src="../../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../../scineplex.css">
<title>Test::Builder::Tester - test testsuites that have been built with Test::Builder</title>
<link rel="stylesheet" href="../../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>
<body>
<script>writelinks('__top__',3);</script>
<h1><a>Test::Builder::Tester - test testsuites that have been built with Test::Builder</a></h1>
<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#synopsis">SYNOPSIS</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<ul>
<li><a href="#methods">Methods</a></li>
</ul>
<li><a href="#bugs">BUGS</a></li>
<li><a href="#author">AUTHOR</a></li>
<li><a href="#notes">NOTES</a></li>
<li><a href="#see_also">SEE ALSO</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>Test::Builder::Tester - test testsuites that have been built with
Test::Builder</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
<span class="keyword">use</span> <span class="variable">Test::Builder::Tester</span> <span class="string">tests</span> <span class="operator">=></span> <span class="number">1</span><span class="operator">;</span>
<span class="keyword">use</span> <span class="variable">Test::More</span><span class="operator">;</span>
</pre>
<pre>
<span class="variable">test_out</span><span class="operator">(</span><span class="string">"not ok 1 - foo"</span><span class="operator">);</span>
<span class="variable">test_fail</span><span class="operator">(+</span><span class="number">1</span><span class="operator">);</span>
<span class="variable">fail</span><span class="operator">(</span><span class="string">"foo"</span><span class="operator">);</span>
<span class="variable">test_test</span><span class="operator">(</span><span class="string">"fail works"</span><span class="operator">);</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>A module that helps you test testing modules that are built with
<strong>Test::Builder</strong>.</p>
<p>The testing system is designed to be used by performing a three step
process for each test you wish to test. This process starts with using
<a href="#item_test_out"><code>test_out</code></a> and <a href="#item_test_err"><code>test_err</code></a> in advance to declare what the testsuite you
are testing will output with <strong>Test::Builder</strong> to stdout and stderr.</p>
<p>You then can run the <code>test(s)</code> from your test suite that call
<strong>Test::Builder</strong>. At this point the output of <strong>Test::Builder</strong> is
safely captured by <strong>Test::Builder::Tester</strong> rather than being
interpreted as real test output.</p>
<p>The final stage is to call <a href="#item_test_test"><code>test_test</code></a> that will simply compare what you
predeclared to what <strong>Test::Builder</strong> actually outputted, and report the
results back with a "ok" or "not ok" (with debugging) to the normal
output.</p>
<p>
</p>
<h2><a name="methods">Methods</a></h2>
<p>These are the six methods that are exported as default.</p>
<dl>
<dt><strong><a name="item_test_out">test_out</a></strong>
<dt><strong><a name="item_test_err">test_err</a></strong>
<dd>
<p>Procedures for predeclaring the output that your test suite is
expected to produce until <a href="#item_test_test"><code>test_test</code></a> is called. These procedures
automatically assume that each line terminates with "\n". So</p>
</dd>
<dd>
<pre>
<span class="variable">test_out</span><span class="operator">(</span><span class="string">"ok 1"</span><span class="operator">,</span><span class="string">"ok 2"</span><span class="operator">);</span>
</pre>
</dd>
<dd>
<p>is the same as</p>
</dd>
<dd>
<pre>
<span class="variable">test_out</span><span class="operator">(</span><span class="string">"ok 1\nok 2"</span><span class="operator">);</span>
</pre>
</dd>
<dd>
<p>which is even the same as</p>
</dd>
<dd>
<pre>
<span class="variable">test_out</span><span class="operator">(</span><span class="string">"ok 1"</span><span class="operator">);</span>
<span class="variable">test_out</span><span class="operator">(</span><span class="string">"ok 2"</span><span class="operator">);</span>
</pre>
</dd>
<dd>
<p>Once <a href="#item_test_out"><code>test_out</code></a> or <a href="#item_test_err"><code>test_err</code></a> (or <a href="#item_test_fail"><code>test_fail</code></a> or <a href="#item_test_diag"><code>test_diag</code></a>) have
been called once all further output from <strong>Test::Builder</strong> will be
captured by <strong>Test::Builder::Tester</strong>. This means that your will not
be able perform further tests to the normal output in the normal way
until you call <a href="#item_test_test"><code>test_test</code></a> (well, unless you manually meddle with the
output filehandles)</p>
</dd>
</li>
<dt><strong><a name="item_test_fail">test_fail</a></strong>
<dd>
<p>Because the standard failure message that <strong>Test::Builder</strong> produces
whenever a test fails will be a common occurrence in your test error
output, and because has changed between Test::Builder versions, rather
than forcing you to call <a href="#item_test_err"><code>test_err</code></a> with the string all the time like
so</p>
</dd>
<dd>
<pre>
<span class="variable">test_err</span><span class="operator">(</span><span class="string">"# Failed test ($0 at line "</span><span class="operator">.</span><span class="variable">line_num</span><span class="operator">(+</span><span class="number">1</span><span class="operator">).</span><span class="string">")"</span><span class="operator">);</span>
</pre>
</dd>
<dd>
<p><a href="#item_test_fail"><code>test_fail</code></a> exists as a convenience method that can be called
instead. It takes one argument, the offset from the current line that
the line that causes the fail is on.</p>
</dd>
<dd>
<pre>
<span class="variable">test_fail</span><span class="operator">(+</span><span class="number">1</span><span class="operator">);</span>
</pre>
</dd>
<dd>
<p>This means that the example in the synopsis could be rewritten
more simply as:</p>
</dd>
<dd>
<pre>
<span class="variable">test_out</span><span class="operator">(</span><span class="string">"not ok 1 - foo"</span><span class="operator">);</span>
<span class="variable">test_fail</span><span class="operator">(+</span><span class="number">1</span><span class="operator">);</span>
<span class="variable">fail</span><span class="operator">(</span><span class="string">"foo"</span><span class="operator">);</span>
<span class="variable">test_test</span><span class="operator">(</span><span class="string">"fail works"</span><span class="operator">);</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_test_diag">test_diag</a></strong>
<dd>
<p>As most of the remaining expected output to the error stream will be
created by Test::Builder's <code>diag</code> function, <strong>Test::Builder::Tester</strong>
provides a convience function <a href="#item_test_diag"><code>test_diag</code></a> that you can use instead of
<a href="#item_test_err"><code>test_err</code></a>.</p>
</dd>
<dd>
<p>The <a href="#item_test_diag"><code>test_diag</code></a> function prepends comment hashes and spacing to the
start and newlines to the end of the expected output passed to it and
adds it to the list of expected error output. So, instead of writing</p>
</dd>
<dd>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?