2008年9月12日星期五

Re: [PerlChina] China-pm Digest, Vol 41, Issue 21

Thanks for your help.:)

2008/9/13 <china-pm-request@pm.org>
Send China-pm mailing list submissions to
       china-pm@pm.org

To subscribe or unsubscribe via the World Wide Web, visit
       http://mail.pm.org/mailman/listinfo/china-pm
or, via email, send a message with subject or body 'help' to
       china-pm-request@pm.org

You can reach the person managing the list at
       china-pm-owner@pm.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of China-pm digest..."


Today's Topics:

  1. Re:  China-pm Digest, Vol 41, Issue 17 (agentzh)
  2. Re:  China-pm Digest, Vol 41, Issue 17 (agentzh)


----------------------------------------------------------------------

Message: 1
Date: Fri, 12 Sep 2008 11:34:47 +0800
From: agentzh <agentzh@gmail.com>
Subject: Re: [PerlChina] China-pm Digest, Vol 41, Issue 17
To: china-pm@pm.org
Message-ID:
       <c711ff240809112034h5e1037e0x9cc9336170b74629@mail.gmail.com>
Content-Type: text/plain; charset="gb2312"

2008/9/12 rochelle hsu <rjhome@gmail.com>

> Abuse Test::Base to test everything
>
> 请问有这个模块的介绍吗,个人比较感兴趣。
>
> Test::Base 是一个 CPAN 模块:

http://search.cpan.org/perldoc?Test::Base

CPAN 上有不少文档。

我几年前刚接触时是通过看 Ingy dot net 的一个 talk 幻灯片学会的,呵呵。最简单的一个示例是:

# foo.t
use Test::Base;

plan tests => 1 * blocks();

sub add ($$) {
   $_[0] + $_[1];
}

run {
   my $block = shift;
   my $name = $block->name;
   #warn $name;
   my $input = $block->input;
   if (!defined $input) { die "No --- input specified for $name"; }
   my $got = eval $input;
   my $expected = $block->output;
   chomp($expected);
   like $got, $expected, "$name - answer okay";
};

__DATA__

=== TEST 1: add
--- input
1+2
--- output
3



=== TEST 2: sub
--- input: 1-2-3
--- output: -4



=== TEST 3: sub
--- input: 1-2-3
--- output: -4

我写了一个小脚本可以自动对这里的 foo.t 进行"格式化",比如序号重编,空行调整等等:

http://svn.openfoundry.org/openapi/trunk/bin/reindex

没有这个 reindex 脚本,使用 Test::Base
会感觉失败测试的准确定位有些困难,呵呵。毕竟失身测试的行号在这里已经没什么意义了,我们依赖于这里的 TEST 1, TEST 2 等编号来定位。

Test::Base 是一个很好的数据驱动的测试框架。我用它组织了 OpenResty 的测试集,可以以多种不同的方式(HTTP 或者进程内或者
mocking 方式)运行同一个测试集。我还用它结合 JavaScript::SpiderMonkey 对一些没有太多 DOM 操作的 .js
文件进行单元测试(比如
http://svn.openfoundry.org/openapi/trunk/demo/Onccf/t/01-pod2html.t ),用它对
GNU make 性质的外部程序进行测试(比如
http://svn.openfoundry.org/mdom/branches/gmake/t/gmake/sanity/simple.t ),用它对
Haskell 编写的编译器进行测试(比如
http://svn.openfoundry.org/openapi/trunk/haskell/t/view/emit-frags.t),用它测试了我的除了
OpenResty 以外的多个 CPAN 模块,包括一个 Perl 6 正则引擎 Pugs::Compiler::Rule
:))

Happy abusing Test::Base!

-agentzh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/china-pm/attachments/20080912/16204e62/attachment-0001.html>

------------------------------

Message: 2
Date: Fri, 12 Sep 2008 11:37:54 +0800
From: agentzh <agentzh@gmail.com>
Subject: Re: [PerlChina] China-pm Digest, Vol 41, Issue 17
To: china-pm@pm.org
Message-ID:
       <c711ff240809112037p168dc8bv8d311bdfc1737688@mail.gmail.com>
Content-Type: text/plain; charset="gb2312"

2008/9/12 agentzh <agentzh@gmail.com>

>
> 没有这个 reindex 脚本,使用 Test::Base
> 会感觉失败测试的准确定位有些困难,呵呵。毕竟失身测试的行号在这里已经没什么意义了,我们依赖于这里的 TEST 1, TEST 2 等编号来定位。
>

呃。。。我是说"失败测试",不是"失身测试"。五笔打快了就会犯这种错误。。。唔唔唔。。。

Best,
-agentzh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/china-pm/attachments/20080912/2f523c7c/attachment-0001.html>

------------------------------

_______________________________________________
China-pm mailing list
China-pm@pm.org
http://mail.pm.org/mailman/listinfo/china-pm

End of China-pm Digest, Vol 41, Issue 21
****************************************

没有评论: