> Changing the subject slightly, is there any guidance on what people
> should write in the name/comment/label?
> 
> I ask because several times I've been puzzled by a test failure
> where the message printed is ambiguous. Compare these two:
> 
>       not ok 42 - is red
> 
>       not ok 42 - should be red
> 
> The first isn't clear whether "is red" is what's expected or what's
> actually happened.

yeah, it's easy to get confused when using ok() like that.  that's why I use
is() and it's better diagnostics almost all the time, reserving ok() for
only cases like this

  my $rc = foo('bar');
  ok ($rc, 'foo() succeeded');

so, my personal rule is this:

  - use ok() only when testing single variables for truth of falsity
  - use is() (or another comparison function) when you care about the data
behind the results

the corrolary to this is that I wouldn't do

  is($rc, 1, 'foo() succeeded')

unless it was important to know that foo() returned 1 (over, say, 33) when I
really want to check for truth.

no big insights here, mind you, but I've seen people try to muscle lots of
stuff into ok() that would work better using some of the other T::M
functions.  if you're stuck using Test.pm I guess this isn't an option, but
if you have T::M you might as well use the tools available to you.

one other comment is that I (personally) enforce making each comment unique,
even within loops, since I just find results easier to track that way, even
when everything is successful.  YMMV.

HTH

--Geoff

Reply via email to