At the risk of being pedantic, I thought I'd flesh out some information here.

As guha pointed out, using &diag instead of print is the way to go. &diag prints its messages in such a way so as to play nicely with Test::Harness. It's always possible that simply printing data could result in something that confuses Test::Harness and thus causes unpredictable results which could be hard to diagnose.

Also, it looks like you're using the venerable Test module instead of Test::More. In the former, your code makes perfect sense. In the latter you'll find that &ok does a simple boolean check, but &is makes the comparison, allows a test name to be assigned and gives very useful diagnostic info.

$ perl -MTest::More=tests,1 -e 'is(23,42,"Discordia should have the an +swer")' 1..1 not ok 1 - Discordia should have the answer # Failed test (-e at line 1) # got: '23' # expected: '42' # Looks like you failed 1 tests of 1.

And if you like the new Data::Dumper::Simple, you may wish to note that unlike Data::Dumper, the parentheses are required. That's lamentable, but it made it much easier to implement.

Cheers,
Ovid

New address of my CGI Course.


In reply to Re: Using Data::Dumper in Test-Driven Development by Ovid
in thread Using Data::Dumper in Test-Driven Development by dws

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.