Re: Testing for NULL return values in test scripts
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]
Re: Testing for NULL return values in test scripts
I can't use Test::Simple, I have to use Test.pm for this module for backwards compatibility reasons. I'm trying to replace this function call with an ok() call: $ctx = Net::SSLeay::SSL_CTX_new() or die ("Unable to create SSL context"); Hard to tell what $ctx is if SSL_CTX_new() fails; I know it returns NULL in c. > On 4/12/05, Steve Peters <[EMAIL PROTECTED]> wrote: > > 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] > > >
Re: Testing for NULL return values in test scripts
On Tue, Apr 12, 2005 at 01:39:59PM -0500, Walter Goulet wrote: > I can't use Test::Simple, I have to use Test.pm for this module for > backwards compatibility reasons. Try Test::Legacy, it gives you an upgrade path away from Test.pm. http://search.cpan.org/dist/Test-Legacy/ It almost perfectly emulates the Test.pm interface and it works in conjunction with other test modules. If you're worried about dependencies, you can simply ship a copy of Test::Legacy and Test::Builder with your module. Stick 'em in t/lib/ and put "use lib qw(t/lib)" at the top of your tests. Then you can say: use Test::Legacy; # replaces use Test; and leave the rest of your code the same. You can also add in other modules... # so as not to clash with Test::Legacy's functions use Test::More import => [qw(!ok !plan !skip)]; > I'm trying to replace this function call with an ok() call: > > $ctx = Net::SSLeay::SSL_CTX_new() or die ("Unable to create SSL context"); > > Hard to tell what $ctx is if SSL_CTX_new() fails; I know it returns NULL in c. To test for undef using Test.pm... ok( $ctx, undef );
Re: Testing for NULL return values in test scripts
-BEGIN PGP SIGNED MESSAGE- Moin, On Tuesday 12 April 2005 22:15, Michael G Schwern wrote: > On Tue, Apr 12, 2005 at 01:39:59PM -0500, Walter Goulet wrote: > > I can't use Test::Simple, I have to use Test.pm for this module for > > backwards compatibility reasons. > > Try Test::Legacy, it gives you an upgrade path away from Test.pm. > http://search.cpan.org/dist/Test-Legacy/ > > It almost perfectly emulates the Test.pm interface and it works in > conjunction with other test modules. If you're worried about > dependencies, you can simply ship a copy of Test::Legacy and > Test::Builder with your module. Stick 'em in t/lib/ and put "use lib > qw(t/lib)" at the top of your tests. > > Then you can say: Uhm, is there any reason why you can't do this with Test::Simple, too? *puzzled* Best wishes, Tels - -- Signed on Tue Apr 12 22:56:23 2005 with key 0x93B84C15. Visit my photo gallery at http://bloodgate.com/photos/ PGP key on http://bloodgate.com/tels.asc or per email. "Retsina?" - "Ja, Papa?" - "Schach Matt." - "Is gut, Papa." -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.4 (GNU/Linux) iQEVAwUBQlw2JncLPEOTuEwVAQFHXwf/Uuk+jnOjvijI+Nm+/9v4KaaPa61XoqYx 73Aot4Vm203Q5mYm86ax/HgdsqHQyQWxRBeAIKGN9cASpHj9ZdVBbOrMgNrw4jzC y/eEw1eODAhb6SfvWLn6mbxjZIFzxmkphP5mgxRMNqqTsXHUCkmk0VaaIcvAxxoH C61gAcM7uSYSVt+WMlDRPq6D9CmmKVerFpgjo4Puqq32taPK8RRdwtlfDnQTEyDR KApr8bgCrHNUeWAtuXxO3keig2E96KM/UEKziAPcdLwCH1IJ82JJ24LZl7RRHtTv jzT1/Fspf5rWptEPyAYQ+QNWDcVInPmJAgs4TAO6Mp+q1zwGCqew5Q== =01+/ -END PGP SIGNATURE-
Re: Testing for NULL return values in test scripts
I think the suggestion to use Test::Legacy was based on the statement 'backwards compatibility reasons' require me to use Test.pm. I should have been clearer in my explanation; the module author is not permitting me to use any additional modules that aren't included in perl 5.6.0 to test his module. Therefore, I am restricted to only using Test.pm for testing the module. If I had the flexibility of specifying additional dependancies, I would gladly move to Test::Simple or Test::More. If only I could convince the author to let me bundle additional test modules with his distribution... - walt On 4/12/05, Tels <[EMAIL PROTECTED]> wrote: > -BEGIN PGP SIGNED MESSAGE- > > Moin, > > On Tuesday 12 April 2005 22:15, Michael G Schwern wrote: > > On Tue, Apr 12, 2005 at 01:39:59PM -0500, Walter Goulet wrote: > > > I can't use Test::Simple, I have to use Test.pm for this module for > > > backwards compatibility reasons. > > > > Try Test::Legacy, it gives you an upgrade path away from Test.pm. > > http://search.cpan.org/dist/Test-Legacy/ > > > > It almost perfectly emulates the Test.pm interface and it works in > > conjunction with other test modules. If you're worried about > > dependencies, you can simply ship a copy of Test::Legacy and > > Test::Builder with your module. Stick 'em in t/lib/ and put "use lib > > qw(t/lib)" at the top of your tests. > > > > Then you can say: > > Uhm, is there any reason why you can't do this with Test::Simple, too? > *puzzled* > > Best wishes, > > Tels > > - -- > Signed on Tue Apr 12 22:56:23 2005 with key 0x93B84C15. > Visit my photo gallery at http://bloodgate.com/photos/ > PGP key on http://bloodgate.com/tels.asc or per email. > > "Retsina?" - "Ja, Papa?" - "Schach Matt." - "Is gut, Papa." > > -BEGIN PGP SIGNATURE- > Version: GnuPG v1.2.4 (GNU/Linux) > > iQEVAwUBQlw2JncLPEOTuEwVAQFHXwf/Uuk+jnOjvijI+Nm+/9v4KaaPa61XoqYx > 73Aot4Vm203Q5mYm86ax/HgdsqHQyQWxRBeAIKGN9cASpHj9ZdVBbOrMgNrw4jzC > y/eEw1eODAhb6SfvWLn6mbxjZIFzxmkphP5mgxRMNqqTsXHUCkmk0VaaIcvAxxoH > C61gAcM7uSYSVt+WMlDRPq6D9CmmKVerFpgjo4Puqq32taPK8RRdwtlfDnQTEyDR > KApr8bgCrHNUeWAtuXxO3keig2E96KM/UEKziAPcdLwCH1IJ82JJ24LZl7RRHtTv > jzT1/Fspf5rWptEPyAYQ+QNWDcVInPmJAgs4TAO6Mp+q1zwGCqew5Q== > =01+/ > -END PGP SIGNATURE- >
Re: Testing for NULL return values in test scripts
On Tue, Apr 12, 2005 at 10:57:02PM +0200, Tels wrote: > > Try Test::Legacy, it gives you an upgrade path away from Test.pm. > > http://search.cpan.org/dist/Test-Legacy/ > > > > It almost perfectly emulates the Test.pm interface and it works in > > conjunction with other test modules. If you're worried about > > dependencies, you can simply ship a copy of Test::Legacy and > > Test::Builder with your module. Stick 'em in t/lib/ and put "use lib > > qw(t/lib)" at the top of your tests. > > > > Then you can say: > > Uhm, is there any reason why you can't do this with Test::Simple, too? > *puzzled* If you mean replace "use Test" with "use Test::Simple" the problem is except in the very, very simple cases Test.pm's ok() function works differently from Test::Simple/More's ok() function. Test.pm's ok() is like ok(), is() and like() all rolled into one. Test.pm Test::More ok( $foo ); == ok( $foo ); ok( $foo, $bar ); == is( $foo, $bar ); ok( $foo, '/regex/'); == like( $foo, '/regex/' ); ok( $foo, $code_ref); == is( $foo, $code_ref->() );
Re: Testing for NULL return values in test scripts
On Tue, Apr 12, 2005 at 04:15:01PM -0500, Walter Goulet wrote: > I think the suggestion to use Test::Legacy was based on the statement > 'backwards compatibility reasons' require me to use Test.pm. I should > have been clearer in my explanation; the module author is not > permitting me to use any additional modules that aren't included in > perl 5.6.0 to test his module. Therefore, I am restricted to only > using Test.pm for testing the module. Is there a reason for this odd policy? The only thing I can think of is to avoid users having to download and install additional dependencies but the t/lib trick takes care of that. Test::Builder/More/Simple are tested back to 5.004_05 so there's no compatibility issue. If you want to go all the way you can try out Module::Install and PAR to completely break the dependency problem. > If only I could convince the author to let me bundle additional test > modules with his distribution... If logic isn't working you might just want to go with the "everybody's doing it" argument. FWIW here's some important projects which do the t/lib trick. ExtUtils::MakeMaker http://search.cpan.org/src/MSCHWERN/ExtUtils-MakeMaker-6.27/t/lib/ Test::Harness http://search.cpan.org/src/PETDANCE/Test-Harness-2.47_03/t/lib/ mod_perl http://perl.apache.org/dist/mod_perl-2.0-current/t/lib/ Parrot https://svn.perl.org/parrot/trunk/lib/ xmlstream http://www.jabberstudio.org/cgi-bin/viewcvs.cgi/cvs/xmlstream/t/lib/ darcs http://abridgegame.org/cgi-bin/darcs.cgi/darcs/tests/lib/perl/?c=browse
Re: Testing for NULL return values in test scripts
So the good news is that I was able to convince the author to let me include my dependancies in the test library. So I'll switch to Test::More. Thanks for the help. On 4/12/05, Michael G Schwern <[EMAIL PROTECTED]> wrote: > On Tue, Apr 12, 2005 at 04:15:01PM -0500, Walter Goulet wrote: > > I think the suggestion to use Test::Legacy was based on the statement > > 'backwards compatibility reasons' require me to use Test.pm. I should > > have been clearer in my explanation; the module author is not > > permitting me to use any additional modules that aren't included in > > perl 5.6.0 to test his module. Therefore, I am restricted to only > > using Test.pm for testing the module. > > Is there a reason for this odd policy? The only thing I can think of is > to avoid users having to download and install additional dependencies but > the t/lib trick takes care of that. > > Test::Builder/More/Simple are tested back to 5.004_05 so there's no > compatibility issue. > > If you want to go all the way you can try out Module::Install and PAR to > completely break the dependency problem. > > > > If only I could convince the author to let me bundle additional test > > modules with his distribution... > > If logic isn't working you might just want to go with the "everybody's doing > it" argument. > FWIW here's some important projects which do the t/lib trick. > > ExtUtils::MakeMaker > http://search.cpan.org/src/MSCHWERN/ExtUtils-MakeMaker-6.27/t/lib/ > > Test::Harness > http://search.cpan.org/src/PETDANCE/Test-Harness-2.47_03/t/lib/ > > mod_perl > http://perl.apache.org/dist/mod_perl-2.0-current/t/lib/ > > Parrot > https://svn.perl.org/parrot/trunk/lib/ > > xmlstream > http://www.jabberstudio.org/cgi-bin/viewcvs.cgi/cvs/xmlstream/t/lib/ > > darcs > http://abridgegame.org/cgi-bin/darcs.cgi/darcs/tests/lib/perl/?c=browse > >
Re: Testing for NULL return values in test scripts
On Wed, Apr 13, 2005 at 03:52:43PM -0500, Walter Goulet wrote: > So the good news is that I was able to convince the author to let me > include my dependancies in the test library. So I'll switch to > Test::More. Huzzah for sanity!
Re: Testing for NULL return values in test scripts
-BEGIN PGP SIGNED MESSAGE- Moin, On Wednesday 13 April 2005 22:52, Walter Goulet wrote: > So the good news is that I was able to convince the author to let me > include my dependancies in the test library. So I'll switch to > Test::More. > > Thanks for the help. Thats very good news! Best wishes, Tels - -- Signed on Wed Apr 13 23:57:19 2005 with key 0x93B84C15. Visit my photo gallery at http://bloodgate.com/photos/ PGP key on http://bloodgate.com/tels.asc or per email. "The campaign should combat the messages of pornography by putting signs on buses saying sex with children is not OK." -- Mary Anne Layden in ttp://tinyurl.com/6a9cy -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.4 (GNU/Linux) iQEVAwUBQl2V3ncLPEOTuEwVAQEaqQf9EvluE+1OPSV9qdg+ccl8llGrP309fDDx irQS6AETmYH7Y20kp5gRylYwMY0GvOu0sg6qlHWEZt7GxhJpX+Woh60QPDGuIYC8 8RnfRw/YyaNDjvILTVlXo1ayZUO0K1Bmry6rBwmgpmncXDfTbaQJhyDRT6CQmNbw pavmF6ONpkW5J/U/4IDiu0kjy+29VCIpz+hVA+I9Q0xbhisb/JIc6DvRTmEoifux lT6Do7YgGStE5bNiBtBMqqIxBCQQryNa9YKqFhtpNyY1Rfn6I3MB9EFqAwvZPC7t bJMPmT8k2blt2Lu072LPfgQzKUk2l8L/phz+QH7yhJl/awOht/NBPw== =mDWX -END PGP SIGNATURE-