http://www.perlmonks.org?node_id=208426
astaines has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I'm writing a module to verify data values. The objects are esentially factories which write subroutines to validate data items.

As part of their construction these objects can be fed arrays or subroutine references. The relevant set routines check to see if you've fed them the right type of thing - this is done using ref :-

sub _ref_check { my ($test,$should_be) = @_; my $ref = ref($test); unless ($ref eq $should_be) { if (length($ref) > 0) { carp ("\n>> $test isn't a reference to a $should_be, but rathe +r a reference to a ".$ref."\n") } else { carp ("\n>> $test isn't an array reference at all, but a SCALA +R\n") }# if (defined($refref)) return 0; } # unless ($ref eq $should_be) return 1; } #End of subrotuine _ref_check

This works fine, and I'm happy with it, but in my test scripts I have chosen to test that I can't feed improper things to the set routines. As you can see the error reports from carp in _ref_check() turn up in the test output.

t\01-sanity.....................ok t\02-simple.....................ok 16/0 >> 4 isn't an array reference at all, but a SCALAR # # Won't accept scalar values >> HASH(0x1dec550) isn't a reference to an array, but rather a referen +ce to a HASH # # Won't accept hash values t\02-simple.....................ok t\03-transform..................ok 3/0 >> ARRAY(0x1c0ba88) isn't a reference to a subroutine , but rather a r +eference to an ARRAY t\03-transform..................ok 5/0 >> 4 isn't an array reference at all, but a SCALAR t\03-transform..................ok 7/0 >> HASH(0x1ab5430) isn't a reference to an array, but rather a referen +ce to a HAS t\03-transform..................ok [snip] All tests successful. Files=9, Tests=101, 1 wallclock secs ( 0.00 cusr + 0.00 csys = 0.00 + CPU)

So what I would like is style advice - is it appropriate/accepatable for tests to output something besides

t\01-sanity.....................ok

In any event can I turn off carp, or otherwise lose diagnostic output while running tests?

--
Anthony Staines

P.S. If you're really curious the module will be on my scratchpad for a while, but it's not really ready for the real world...