perl Testing 读书笔记(比较跨行字符串)

上一篇 / 下一篇  2012-04-10 22:26:39 / 个人分类:perl相关

 

Test::Differences 用eq_or_diff()函数来显示跨行的字符串之间的差异,下面是示例。

#!/usr/bin/perl

use Test::More tests => 1;
use Test::Differences;

my $string1 = <<"END1";
Lorem ipsum dolor sit
amet, consectetuer
adipiscing elit.
END1

my $string2 = <<"END2";
Lorem ipsum dolor sit
amet, facilisi
adipiscing elit.
END2

eq_or_diff( $string1, $string2, 'are they the same?' );

 

运行结果,*的一行代表不同

D:\loveperl>prove -v strings.pl
strings....1..1

#   Failed test 'are they the same?'
not ok 1 - are they the same?
#   at strings.pl line 18.
# +---+-----------------------+-----------------------+
# | Ln|Got                    |Expected               |
# +---+-----------------------+-----------------------+
# |  1|Lorem ipsum dolor sit  |Lorem ipsum dolor sit  |
# *  2|amet, consectetuer     |amet, facilisi         *
# |  3|adipiscing elit.       |adipiscing elit.       |
# +---+-----------------------+-----------------------+
# Looks like you failed 1 test of 1.
dubious
        Test returned status 1 (wstat 256, 0x100)
DIED. FAILED test 1
        Failed 1/1 tests, 0.00% okay
Failed Test Stat Wstat Total Fail  List of Failed
-------------------------------------------------------------------------
strings.pl     1   256     1    1  1
Failed 1/1 test scripts. 1/1 subtests failed.
Files=1, Tests=1,  0 wallclock secs ( 0.00 cusr +  0.00 csys =  0.00 CPU)
Failed 1/1 test programs. 1/1 subtests failed.


TAG:

 

评分:0

我来说两句

Open Toolbar