Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Should a CPAN module list Test:: modules as dependencies?

by grantm (Parson)
on Jul 20, 2004 at 09:08 UTC ( [id://375854]=note: print w/replies, xml ) Need Help??


in reply to Should a CPAN module list Test:: modules as dependencies?

As far as I can tell, cmp_deeply() does exactly what is_deeply() from Test::More does. If you're not using any of the more esoteric functions from Test::Deep then I'd say switch to Test::More and definitely list it as a prereq.

On a more philosophical note ... it's your module and you can list anything you like as a prerequisite. If it's a tool that makes your development easier and makes it easier to debug problem reports from the field then of course you should use it. If someone wants to use something you're giving away for free but they can't be bothered to install a test module then that's their loss not yours.

Looking at it from a slightly different angle though ... someone building a 'binary' distribution of your package (eg: for RPM or APT etc) shouldn't include the Test::* dependencies, or the test scripts either for that matter.

Update

Sorry I phrased that badly. I do/did realise that Test::Deep's cmp_deeply gives a lot more flexibility in comparing deep data structures. What I meant to say was that the code in the OP's example wasn't obviously using any of the extra flexibility.

Replies are listed 'Best First'.
Re^2: Should a CPAN module list Test:: modules as dependencies?
by stvn (Monsignor) on Jul 20, 2004 at 16:13 UTC
    As far as I can tell, cmp_deeply() does exactly what is_deeply() from Test::More does.

    Actually, cmp_deeply does a lot more than is_deeply. At its most basic, it does the same thing, but at its most complex, it is soooooo much more. Here is an example from the docs:

    cmp_deeply( $obj, listmethods( name => "John", ["favourites", "food"] => ["Mapo tofu", "Gongbao chicken"] ) );
    This is the Test::More equvalent of doing:
    is($obj->name, "John", '... our name is John); is_deeply([$obj->favourites("food")], ["Mapo tofu", "Gongbao chicken"] +);
    And it gets even better than that when you start looking at the superhash and subhash functions. I have used Test::Deep to validate a large tree-ish data-structure which is used to configure an application. This is all accomplished in a single test, here is a snippet of that code:
    my $report = do($tree_file) || die "failed to load the report tree\n=> + $@\n"; my $is_string = re('^(\s|\w|\d)*$'); my $is_module_name = re('^(([a-zA-Z0-9_]+)\:\:([a-zA-Z0-9_]+))+$'); cmp_deeply( $report, all( isa("ARRAY"), array_each( subhashof({ report_type => $is_string, report_module => $is_module_name, graphing_modules => isa("HASH"), question_groups => all( isa("ARRAY"), array_each( subhashof({ question_group => $is_string, report_module => $is_module_name, graphing_modules => isa("HASH"), questions => all( isa("ARRAY"), array_each(re('^\d+$') +) ) # all }) # subhashof ) # array_each ) # all }) # subhashof ) # array_each ) # all ); # cmp_deeply
    To do this with Test::More would not only have been more code, but would really have required a lot of bookkeeping. With Test::Deep, it took me no time at all to but this together and it is far more flexible than any version I would have coded.

    -stvn
Re^2: Should a CPAN module list Test:: modules as dependencies?
by adrianh (Chancellor) on Jul 20, 2004 at 16:23 UTC
    As far as I can tell, cmp_deeply() does exactly what is_deeply() from Test::More does.

    Even at a basic level cmp_deeply is different from is_deeply. For example:

    use Test::More 'no_plan'; use Test::Deep; my $x = { foo => 42 }; my $y = bless { foo => 42 }, 'SomeClass'; is_deeply( $x, $y, 'is_deeply ignores bless' ); cmp_deeply( $x, $y, 'cmp_deeply does not ignore bless' ); __END__ ok 1 - is_deeply ignores bless not ok 2 - cmp_deeply does not ignore bless # Failed test (foo.pl at line 12) # Compared blessed($data) # got : undef # expect : 'SomeClass' 1..2

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://375854]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-26 01:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found