httpd-test-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <>
Subject notes about debugging prints in perl tests
Date Tue, 20 Nov 2001 04:05:37 GMT
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

=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?");


   # 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      mod_perl Guide

View raw message