[Pdx-pm] Testing question

benh ben.hengst at gmail.com
Wed Jan 18 10:52:47 PST 2012


oop, just noticed that I've got my get and expected reversed, sorry about that.

it should be :
eq_or_diff
  [ map{sprintf q{test%02d}, $_} 8..12 ],
  [ qw{test08 test09 test10 test11 test13} ], # NOTE 13 rather then 12
to cause failure
  q{well do they match?}
;


On Wed, Jan 18, 2012 at 10:50, benh <ben.hengst at gmail.com> wrote:
> Another option is to not boil everything down to a single string to do
> the test. Like Leto said, if you use Test::Differences (included when
> you use Test::Most) then you'll have access to eq_or_diff that gives
> you Data::Dumper-ish output for data structures when they fail. In the
> example below take a look at the output (post __END__) and look at the
> last row, note that it's flagged with '*' and you can see what's the
> same and what's not.
>
>
> #!/usr/bin/env perl
> use strict;
> use warnings;
> use Test::Most qw{no_plan};
>
> eq_or_diff
>  [ qw{test08 test09 test10 test11 test13} ], # NOTE 13 rather then 12
> to cause failure
>  [ map{sprintf q{test%02d}, $_} 8..12 ],
>  q{well do they match?}
> ;
>
> __END__
> not ok 1 - well do they match?
> #   Failed test 'well do they match?'
> #   at tom.t line 8.
> # +----+----------+----------+
> # | Elt|Got       |Expected  |
> # +----+----------+----------+
> # |   0|'test08'  |'test08'  |
> # |   1|'test09'  |'test09'  |
> # |   2|'test10'  |'test10'  |
> # |   3|'test11'  |'test11'  |
> # *   4|'test13'  |'test12'  *
> # +----+----------+----------+
> 1..1
> # Looks like you failed 1 test of 1.
>
>
>
>
>
> 2012/1/18 Andy Lester <andy at petdance.com>:
>>
>> On Jan 18, 2012, at 9:53 AM, Jonathan Duke Leto wrote:
>>
>> is($x eq $y, 'blarg')
>>
>> this is better:
>>
>> cmp_ok($x, 'eq', $y, 'blarg')
>>
>> because you will get better error reporting from cmp_ok. It knows that
>> you are using 'eq', so it can say "hey, $x != $y", whereas the first
>> test will just say "this thing isn't true", which isn't nearly as
>> useful.
>>
>>
>> ok( $x eq $y, 'blarg' ) isn't informative.
>>
>> is( $x, $y, 'blarg' ) tells you what's different.
>>
>> cmp_ok( $x, 'eq', $y, 'blarg' ) is no more informative than the is() call.
>>  cmp_ok should be used only if you want to compare using something other
>> than 'eq'.
>>
>> xoa
>>
>>
>> --
>> Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance
>>
>>
>> _______________________________________________
>> Pdx-pm-list mailing list
>> Pdx-pm-list at pm.org
>> http://mail.pm.org/mailman/listinfo/pdx-pm-list
>
>
>
> --
> benh~
>
> http://about.notbenh.info



-- 
benh~

http://about.notbenh.info


More information about the Pdx-pm-list mailing list