<div dir="ltr">Thanks for your help.:)<br><br><div class="gmail_quote">2008/9/13  <span dir="ltr">&lt;<a href="mailto:china-pm-request@pm.org">china-pm-request@pm.org</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Send China-pm mailing list submissions to<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<a href="mailto:china-pm@pm.org">china-pm@pm.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://mail.pm.org/mailman/listinfo/china-pm" target="_blank">http://mail.pm.org/mailman/listinfo/china-pm</a><br>
or, via email, send a message with subject or body &#39;help&#39; to<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<a href="mailto:china-pm-request@pm.org">china-pm-request@pm.org</a><br>
<br>
You can reach the person managing the list at<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<a href="mailto:china-pm-owner@pm.org">china-pm-owner@pm.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than &quot;Re: Contents of China-pm digest...&quot;<br>
<br>
<br>
Today&#39;s Topics:<br>
<br>
 &nbsp; 1. Re: &nbsp;China-pm Digest, Vol 41, Issue 17 (agentzh)<br>
 &nbsp; 2. Re: &nbsp;China-pm Digest, Vol 41, Issue 17 (agentzh)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Fri, 12 Sep 2008 11:34:47 +0800<br>
From: agentzh &lt;<a href="mailto:agentzh@gmail.com">agentzh@gmail.com</a>&gt;<br>
Subject: Re: [PerlChina] China-pm Digest, Vol 41, Issue 17<br>
To: <a href="mailto:china-pm@pm.org">china-pm@pm.org</a><br>
Message-ID:<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;<a href="mailto:c711ff240809112034h5e1037e0x9cc9336170b74629@mail.gmail.com">c711ff240809112034h5e1037e0x9cc9336170b74629@mail.gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=&quot;gb2312&quot;<br>
<br>
2008/9/12 rochelle hsu &lt;<a href="mailto:rjhome@gmail.com">rjhome@gmail.com</a>&gt;<br>
<br>
&gt; Abuse Test::Base to test everything<br>
&gt;<br>
&gt; 请问有这个模块的介绍吗,个人比较感兴趣。<br>
&gt;<br>
&gt; Test::Base 是一个 CPAN 模块:<br>
<br>
<a href="http://search.cpan.org/perldoc?Test::Base" target="_blank">http://search.cpan.org/perldoc?Test::Base</a><br>
<br>
CPAN 上有不少文档。<br>
<br>
我几年前刚接触时是通过看 Ingy dot net 的一个 talk 幻灯片学会的,呵呵。最简单的一个示例是:<br>
<br>
# foo.t<br>
use Test::Base;<br>
<br>
plan tests =&gt; 1 * blocks();<br>
<br>
sub add ($$) {<br>
 &nbsp; &nbsp;$_[0] + $_[1];<br>
}<br>
<br>
run {<br>
 &nbsp; &nbsp;my $block = shift;<br>
 &nbsp; &nbsp;my $name = $block-&gt;name;<br>
 &nbsp; &nbsp;#warn $name;<br>
 &nbsp; &nbsp;my $input = $block-&gt;input;<br>
 &nbsp; &nbsp;if (!defined $input) { die &quot;No --- input specified for $name&quot;; }<br>
 &nbsp; &nbsp;my $got = eval $input;<br>
 &nbsp; &nbsp;my $expected = $block-&gt;output;<br>
 &nbsp; &nbsp;chomp($expected);<br>
 &nbsp; &nbsp;like $got, $expected, &quot;$name - answer okay&quot;;<br>
};<br>
<br>
__DATA__<br>
<br>
=== TEST 1: add<br>
--- input<br>
1+2<br>
--- output<br>
3<br>
<br>
<br>
<br>
=== TEST 2: sub<br>
--- input: 1-2-3<br>
--- output: -4<br>
<br>
<br>
<br>
=== TEST 3: sub<br>
--- input: 1-2-3<br>
--- output: -4<br>
<br>
我写了一个小脚本可以自动对这里的 foo.t 进行&quot;格式化&quot;,比如序号重编,空行调整等等:<br>
<br>
<a href="http://svn.openfoundry.org/openapi/trunk/bin/reindex" target="_blank">http://svn.openfoundry.org/openapi/trunk/bin/reindex</a><br>
<br>
没有这个 reindex 脚本,使用 Test::Base<br>
会感觉失败测试的准确定位有些困难,呵呵。毕竟失身测试的行号在这里已经没什么意义了,我们依赖于这里的 TEST 1, TEST 2 等编号来定位。<br>
<br>
Test::Base 是一个很好的数据驱动的测试框架。我用它组织了 OpenResty 的测试集,可以以多种不同的方式(HTTP 或者进程内或者<br>
mocking 方式)运行同一个测试集。我还用它结合 JavaScript::SpiderMonkey 对一些没有太多 DOM 操作的 .js<br>
文件进行单元测试(比如<br>
<a href="http://svn.openfoundry.org/openapi/trunk/demo/Onccf/t/01-pod2html.t" target="_blank">http://svn.openfoundry.org/openapi/trunk/demo/Onccf/t/01-pod2html.t</a> ),用它对<br>
GNU make 性质的外部程序进行测试(比如<br>
<a href="http://svn.openfoundry.org/mdom/branches/gmake/t/gmake/sanity/simple.t" target="_blank">http://svn.openfoundry.org/mdom/branches/gmake/t/gmake/sanity/simple.t</a> ),用它对<br>
Haskell 编写的编译器进行测试(比如<br>
<a href="http://svn.openfoundry.org/openapi/trunk/haskell/t/view/emit-frags.t" target="_blank">http://svn.openfoundry.org/openapi/trunk/haskell/t/view/emit-frags.t</a>),用它测试了我的除了<br>
OpenResty 以外的多个 CPAN 模块,包括一个 Perl 6 正则引擎 Pugs::Compiler::Rule<br>
:))<br>
<br>
Happy abusing Test::Base!<br>
<br>
-agentzh<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: &lt;<a href="http://mail.pm.org/pipermail/china-pm/attachments/20080912/16204e62/attachment-0001.html" target="_blank">http://mail.pm.org/pipermail/china-pm/attachments/20080912/16204e62/attachment-0001.html</a>&gt;<br>

<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Fri, 12 Sep 2008 11:37:54 +0800<br>
From: agentzh &lt;<a href="mailto:agentzh@gmail.com">agentzh@gmail.com</a>&gt;<br>
Subject: Re: [PerlChina] China-pm Digest, Vol 41, Issue 17<br>
To: <a href="mailto:china-pm@pm.org">china-pm@pm.org</a><br>
Message-ID:<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;<a href="mailto:c711ff240809112037p168dc8bv8d311bdfc1737688@mail.gmail.com">c711ff240809112037p168dc8bv8d311bdfc1737688@mail.gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=&quot;gb2312&quot;<br>
<br>
2008/9/12 agentzh &lt;<a href="mailto:agentzh@gmail.com">agentzh@gmail.com</a>&gt;<br>
<br>
&gt;<br>
&gt; 没有这个 reindex 脚本,使用 Test::Base<br>
&gt; 会感觉失败测试的准确定位有些困难,呵呵。毕竟失身测试的行号在这里已经没什么意义了,我们依赖于这里的 TEST 1, TEST 2 等编号来定位。<br>
&gt;<br>
<br>
呃。。。我是说&quot;失败测试&quot;,不是&quot;失身测试&quot;。五笔打快了就会犯这种错误。。。唔唔唔。。。<br>
<br>
Best,<br>
-agentzh<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: &lt;<a href="http://mail.pm.org/pipermail/china-pm/attachments/20080912/2f523c7c/attachment-0001.html" target="_blank">http://mail.pm.org/pipermail/china-pm/attachments/20080912/2f523c7c/attachment-0001.html</a>&gt;<br>

<br>
------------------------------<br>
<br>
_______________________________________________<br>
China-pm mailing list<br>
<a href="mailto:China-pm@pm.org">China-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/china-pm" target="_blank">http://mail.pm.org/mailman/listinfo/china-pm</a><br>
<br>
End of China-pm Digest, Vol 41, Issue 21<br>
****************************************<br>
</blockquote></div><br></div>