On Mon, Dec 10, 2001 at 06:53:20PM -0800, Kurt D. Starsinic wrote:
> Why go to such trouble to have 20 different automagical comparators,
> when you can do whatever you want with anonymous subs and/or eval in ok()?
> Where's the real value? Frankly, I'm getting pretty confused by the
> myriad testing options.
Yes, ok() is the simplest and most versatile testing function and you
can perform just about any test with it, which is why Test::Simple
consists of one function: ok.
However, its also the least informative. About all it can tell you is
"it failed".
not ok 6 - something about a horse
# Failed test (foo.t at line 16)
If you want to know more you could go in with the
debugger, but there are cases where this is impossible (mod_perl) or
it will interfere with the results of the test.
Or you can start adding lots of debugging print statements.
ok( $foo == $bar ) || print "# $foo == $bar\n";
After your 1000th test you'll find this is rather tedious work and
unnecessarily clutters up the code. If you try to side-step this
by adding them only when a test fails it will make intermittent
failures difficult to track down.
Then there's the problem of when someone else reports a failure to
you. You'll know tests 12, 32 and 103 failed but nothing more. Then
begins the email exchanges "Could you add a print at line 43 and tell
me what the value of $foo is?"
is(), like() and friends solve this problem by providing narrower
functionality but more diagnostics.
is( $foo, $bar );
not ok 6
# Failed test (foo.t at line 16)
# got: '16'
# expected: '17'
so you get sufficient information to understand what went wrong
without having to re-run the test or write a lot of extra code.
This reaches its height with the somewhat awkwardly named is_deeply()
where you can compare complex structures and get some idea of if and
where they differ.
And that's basically the whole purpose of Test::More. More functions,
more diagnostics. If you're having trouble getting your head around
it, stick to Test::Simple until you find yourself needing more.
--
Michael G. Schwern <[EMAIL PROTECTED]> http://www.pobox.com/~schwern/
Perl Quality Assurance <[EMAIL PROTECTED]> Kwalitee Is Job One
Carpe canem! Seize the dog! This cannot be right.
-- The Critic