Re: Trying to spear a phalanx shield for pod

2003-10-26 Thread Michael G Schwern
On Sun, Oct 26, 2003 at 04:45:48PM +1100, Andrew Savige wrote:
> Michael G Schwern wrote:
> > Since skip_all will exit immediately you can fold that big "everything
> > inside the else block" away.
> > 
> > eval 'use Test::Pod';
> > my $have_testpod = !$@ and $Test::Pod::VERSION >= 0.95;
> > plan skip_all => "Test::Pod v0.95 required for testing POD" 
> > unless $have_testpod;
> > 
> > my @files;
> > my $blib = File::Spec->catfile(qw(blib lib));
> > ...
> 
> There is a misprint in this line:
>my $have_testpod = !$@ and $Test::Pod::VERSION >= 0.95;
> It should read:
>my $have_testpod = !$@ &&  $Test::Pod::VERSION >= 0.95;

I deliberately used and instead of &&.  I'd noticed the original was
using explicit parens to disambiuate the precendence to make sure there
was no chance of it accidentally evaluating as:

(!$@ && $Test::Pod::VERSION) >= 0.95

for those of us that don't have the symbol table memorized.  Instead of
parens, I went with 'and'.

But looking at the precdence table, either version will work.


> Based on the excellent work from Lester & Schwern, I could not restrain
> myself from shortening this a little more (since it will be included
> in many distributions). 

The logic escapes me.  Clarity is more important than length if you're
going to be sticking this code all over the place.

But if we're going to encourage people to copy this code, Test::Pod should 
probably just have a subroutine to do this for you.  That's what libraries
are for!


> My current short version is:
> 
> use Test::More;
> use File::Spec;
> use File::Find;
> use strict;
> eval 'use Test::Pod';
> plan skip_all => "Test::Pod v0.95 required for testing POD"
> if $@ || $Test::Pod::VERSION < 0.95;
> my @files;
> find( sub {push @files, $File::Find::name if /\.p(?:l|m|od)$/},
> File::Spec->catfile( qw(blib lib) ) );
> plan tests => scalar @files;
> foreach my $file (@files) { pod_file_ok($file) }
> 
> Two questions:
> 
> 1) Is using $File::Find::name portable on VMS and Mac OS?
>(I'm confused about File::Find's use of 'Unix' names).

Since you're just looking at the end of the filename, yes.  It doesn't matter
if the path is Unixy or native.  In fact, since the directory name doesn't 
matter you can match against $_.


> 2) Which is preferred:
>eval 'use Test::Pod';
>or:
>eval { require Test::Pod };
>...
>Test::Pod->import;
>or does it not matter?

Doesn't really matter.  If I was going to be strict about it I'd say
do this:

BEGIN {
eval { require Test::Pod };
plan skip_all => "Test::Pod v0.95 required for testing POD"
  if $@ || $Test::Pod::VERSION < 0.95;
Test::Pod->import;
}

or this:

BEGIN {
eval q{ use Test::Pod 0.95 };
plan skip_all => "Test::Pod v0.95 required for testing POD" if $@;
}

so that the functions are imported at compile time.  This means you can
use them without parens.  I like the latter since its most straight
forward and concise.


-- 
Michael G Schwern[EMAIL PROTECTED]  http://www.pobox.com/~schwern/
WOOHOO!  I'm going to Disneyland!
http://www.goats.com/archive/980805.html


Test dying after running

2003-10-26 Thread Tony Bowden

In one of my local applications, the regression test has just started to
fail with:

dubious
  Test returned status 0 (wstat 14, 0xe)
Constant subroutine __need_size_t redefined at
/usr/lib/perl/5.8.0/stddef.ph line 147.
  after all the subtests completed successfully


Bizarrely this only happens if this test runs after some other test. Run
on its own, or first in a series of tests, it works just fine.

I can't think of anything that has changed that might have caused this.

Has anyone ever seen anything like this before?

Tony





Re: Trying to spear a phalanx shield for pod

2003-10-26 Thread Andrew Savige
Michael G Schwern wrote:
> On Sun, Oct 26, 2003 at 04:45:48PM +1100, Andrew Savige wrote:
>> There is a misprint in this line:
>>my $have_testpod = !$@ and $Test::Pod::VERSION >= 0.95;
>> It should read:
>>my $have_testpod = !$@ &&  $Test::Pod::VERSION >= 0.95;
>
> I deliberately used and instead of &&.  I'd noticed the original was
> using explicit parens to disambiuate the precendence to make sure there
> was no chance of it accidentally evaluating as:
> 
> (!$@ && $Test::Pod::VERSION) >= 0.95
> 
> for those of us that don't have the symbol table memorized.  Instead of
> parens, I went with 'and'.
> 
> But looking at the precdence table, either version will work.

Your version does not work (unless I've had a brain malfunction):

# cat sch.pl
use strict;
eval 'use Test::Pod';
my $have_testpod = !$@ and $Test::Pod::VERSION >= 0.95;
print "have_testpod='$have_testpod'\n";
print "tpv=", $Test::Pod::VERSION, "\n";

# perl -w sch.pl
Useless use of numeric ge (>=) in void context at sch.pl line 3.
have_testpod='1'
tpv=0.94

# perl -MO=Deparse -e \
> 'my $have_testpod = !$@ and $Test::Pod::VERSION >= 0.95'
$Test::Pod::VERSION >= 0.95 if my $have_testpod = !$@;
-e syntax OK

>> Based on the excellent work from Lester & Schwern, I could not restrain
>> myself from shortening this a little more (since it will be included
>> in many distributions).
> 
> The logic escapes me.  Clarity is more important than length if you're
> going to be sticking this code all over the place.

I'm not going to pretend it's rational, but for some reason I feel more
comfortable with cut n' pasting if it's only a small amount of code.

This reminds me of the many recent discussions re the merit of:
   $s = do { local $/; <$fh> };
versus using File::Slurp. Psychologically, it may be easier to justify
cut n' pasting if you can say "oh, it's just a one-liner".

> But if we're going to encourage people to copy this code, Test::Pod
> should probably just have a subroutine to do this for you.  That's
> what libraries are for!

I hope Andy is listening. ;-)
Yes, I agree it'd be nice for Test::Pod to provide a little more help
for this very common chore for CPAN module authors. I do feel most
uncomfortable cut n' pasting this code all over the place.

/-\


http://personals.yahoo.com.au - Yahoo! Personals
New people, new possibilities. FREE for a limited time.