You are viewing a plain text version of this content. The canonical link for it is here.
Posted to test-dev@httpd.apache.org by Stas Bekman <st...@stason.org> on 2001/11/20 05:05:37 UTC

notes about debugging prints in perl tests

Just an update for those who don't follow the commits.

Whenever you want to print a debug message in perl-framework tests, you 
should use t_debug() method (just added).

If you want the trinary expected, received, what's tested functionality 
use t_cmp() instead:

See other tests using these two functions, or read the docs below.

If you in need of other convenience wrappers, please let us know.

=item t_debug()

   t_debug("testing feature foo");
   t_debug("test", [1..3], 5, {a=>[1..5]});

t_debug() prints out any datastructure while prepending C<#> at the
beginning of each line, to make the debug printouts comply with
C<Test::Harness>'s requirements. This function should be always used
for debug prints, since if in the future the debug printing will
change (e.g. redirected into a file) your tests won't need to be
changed.

=item t_cmp()

   t_cmp($expected, $received, $comment);

t_cmp() prints the values of I<$comment>, I<$expected> and
I<$received>. e.g.:

   t_cmp(1, 1, "1 == 1?");

prints:

   # testing : 1 == 1?
   # expected: 1
   # received: 1

then it returns the result of comparison of the I<$expected> and the
I<$received> variables. Usually, the return value of this function is
fed directly to the ok() function, like this:

   ok t_cmp(1, 1, "1 == 1?");

the third argument (I<$comment>) is optional, but a nice to use.

It is valid to use I<undef> as an expected value. Therefore:

   1 == t_cmp(undef, undef, "undef == undef?");

is true.

You can compare any two data-structures with t_cmp(). Just make sure
that if you pass non-scalars, you have to pass their references. The
datastructures can be deeply nested. For example you can compare:

   t_cmp({1 => [2..3,{5..8}], 4 => [5..6]},
         {1 => [2..3,{5..8}], 4 => [5..6]},
         "hash of array of hashes");
_____________________________________________________________________
Stas Bekman             JAm_pH      --   Just Another mod_perl Hacker
http://stason.org/      mod_perl Guide   http://perl.apache.org/guide
mailto:stas@stason.org  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/