Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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

In reply to Re^2: Should a CPAN module list Test:: modules as dependencies? by stvn
in thread Should a CPAN module list Test:: modules as dependencies? by grinder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-20 03:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found