views:

139

answers:

2

I'm writing some tests in Perl which have a fair amount of set up. This setup all lives in a module that the test scripts use. I want to be able to print some diagnostics from the module, and intended to use the diag function from Test::More. Problem is, when you use Test::More, it writes the plan so I get

You tried to plan twice at lib/MyTest.pm line 15.

Is there any way I can use diag (or is there an equivalent), or am I stuck with print STDERR?

+4  A: 

For me, the following code:

  #!/usr/bin/perl
  use strict;
  use Test::More;
  diag('hello');

Just prints

  # hello

Test::More won't print the plan unless you tell it to. This is done by passing args to its import:

  use Test::More tests => 30;

Or by calling plan explicitly.

  use Test::More;
  plan(tests => 30);
mpeters
Yup, that works. I was doing use Test::More qw(diag);Which (along with jumping to conclusions) is what got me confused. Thanks.
Tom Dunham
+4  A: 
use Test::More qw(no_plan)
Sam Kington