On Tue, Apr 12, 2005 at 12:49:30PM -0500, Walter Goulet wrote: > Hi, > > I was wondering if there is a way to use the ok() function in Test.pm > to check for a null return value. It looks like the 3 arg form of ok() > I'm using only tests the first 2 args to see if they're equal. > > I'm considering this approach: > > $val = some_func(); # returns NULL on failure > > if($val != 0 && $val ne "0") > { > $isnull = 0; > } > else > { > $isnull = 1; > } > > ok($isnull,0,"NULL returned"); >
First, there is no NULL in Perl. There is undef, so I'll assume that's what you mean. The test above does not test for undef at all. It just checks to see that the return is not equal to zero. If you used Test::Simple, it would be as simple as use strict; use warnings; use Test::Simple tests => 1; my $val = some_func(); ok(! defined $val, "undef returned"); This should work just fine for what you are testing. Steve Peters [EMAIL PROTECTED]