Essential Modules Smoke Testing?

2001-10-17 Thread chromatic

Test::Smoke handles bleadperl nicely.  Is there a tool to download a set of
modules (say, EssentialModules from the Wiki), to run their tests, to collate,
and to report the results?

Have I just volunteered to write such a beast?  It'd be a good idea, at least
to get a look at CPAN.pm before someone has to write tests for it.

-- c



Re: Preliminary test coverage analysis

2001-10-17 Thread chromatic

In article <[EMAIL PROTECTED]>, "schwern"
<[EMAIL PROTECTED]> wrote:

Going back eight months, this was the state of things.  Schwern had just added
coverage analysis to Test::Harness:

> - A bit less than half of all the core libraries have no coverage at all.
> 
> Some very important things are not covered: AutoSplit, CPAN, Cwd,
> Data::Dumper, MakeMaker, Pod::Html, Pod::Man and Term::ReadLine.

We're aware of most of these, and most of them still don't have tests.  (I'm
trying, I'm trying!)
 
> - Of those covered, a smidge less than half have < 75% statement coverage. - "
>"  "   , 20% have < 50% statement coverage.
 
Is it possible to get an update on this?  Writing a new test from scratch is
generally harder than adding to an existing test.  (It's probably the blank page
thing that plagues authors.)

If we can identify some spots that need ~ 30 minutes/25 lines of attention, I
can bang on the "get involved, you lazy bums" drum and try to find some new
people.

-- c



Proposed Patch (add tests for Net::Time)

2001-10-17 Thread chromatic

This is *not* being sent to p5p _yet_, because I did something either brilliantly
clever or fiendishly stupid to get good coverage.  (It's hard to tell the
difference.)

Relying on reliable networking is pretty unportable, and it's really hard to
get useful test information that way.  I coded up some mock objects for
IO::Socket and IO::Select that made this test much easier.

I've been thinking of using them for other Net::* modules -- if they can be
generalized a little more, our lives will be much easier.  I'd like some
feedback on the approach.

If it's a stupid idea, that's cool.  If it's in the wrong place, that's fine.
If there's a better way to do it, I'm all ears.

Someone has to get this done, though, and if doing things the Max Power way
(wrong, but faster and with more yelling) shakes out better ideas, I'll rush in
where fools fear to tread.

HELP!,
-- c

--- ~MANIFEST   Thu Oct 18 00:54:07 2001
+++ MANIFESTThu Oct 18 00:55:15 2001
@@ -1100,7 +1100,8 @@
 lib/Net/t/nntp.t   libnet
 lib/Net/t/require.tlibnet
 lib/Net/t/smtp.t   libnet
-lib/Net/Time.pmlibnet
+lib/Net/Time.pmGet the time from a remote machine
+lib/Net/Time.t See if Net::Time works
 lib/newgetopt.pl   A perl library supporting long option parsing
 lib/NEXT.pmPseudo-class NEXT for method redispatch
 lib/NEXT/Changes   NEXT
--- /dev/null   Thu Aug 30 03:54:37 2001
+++ lib/Net/Time.t  Fri Oct 12 12:59:29 2001
@@ -0,0 +1,46 @@
+#!./perl -w
+
+BEGIN {
+   chdir 't' if -d 't';
+   @INC = '../lib';
+}
+
+use Net::t::Mock;
+
+use Test::More 'no_plan';
+
+use_ok( 'Net::Time' );
+
+# force the socket to fail
+make_fail('IO::Socket::INET', 'new');
+is( Net::Time::_socket('foo', 1, 'bar', 'baz'), undef, 
+   '_socket() should fail if Socket creation fails' );
+
+# if socket is created with protocol UDP (default), it will send a newline
+my $sock = Net::Time::_socket('foo', 2, 'bar'); 
+isa_ok( $sock, 'IO::Socket::INET' );
+is( $sock->{sent}, "\n", 'should send \n with UDP protocol set' );
+is( $sock->{timeout}, 120, 'timeout should default to 120' );
+
+# now try it with a custom timeout and a different protocol
+$sock = Net::Time::_socket('foo', 3, 'bar', 'tcp', 11);
+isa_ok( $sock, 'IO::Socket::INET' );
+is( $sock->{sent}, undef, '_socket() should send nothing unless UDP protocol' );
+is( $sock->{PeerAddr}, 'bar', '_socket() should set PeerAddr in socket' );
+is( $sock->{timeout}, 11, '_socket() should respect custom timeout value' );
+
+# inet_daytime
+# check for correct args (daytime, 13)
+IO::Socket::INET::set_message('z');
+is( Net::Time::inet_daytime('bob'), 'z', 'inet_daytime() should receive data' );
+
+# magic numbers defined in Net::Time
+my $offset = $^O eq 'MacOS' ?
+   (4 * 31536000) : (70 * 31536000 + 17 * 86400);
+
+# check for correct args (time, 13)
+# pretend it is only six seconds since the offset, create a fake message
+# inet_time
+IO::Socket::INET::set_message(pack("N", $offset + 6));
+is( Net::Time::inet_time('foo'), 6, 
+   'inet_time() should calculate time since offset for time()' );
--- /dev/null   Thu Aug 30 03:54:37 2001
+++ lib/Net/t/Mock.pm   Fri Oct 12 12:53:59 2001
@@ -0,0 +1,80 @@
+package Net::t::Mock;
+
+my %fail;
+
+sub import {
+   my $pkg = caller;
+   *{ $pkg . '::make_fail' } = sub {
+   my ($pack, $func, $num) = @_;
+   $num = 1 unless defined $num;
+
+   $fail{$pack}{$func} = $num;
+   };
+}
+
+package IO::Socket::INET;
+
+$INC{'IO/Socket/INET.pm'} = 1;
+
+$fail{'IO::Socket::INET'} = {
+   new => 0,
+   send=> 0,
+};
+
+sub new {
+   my $class = shift;
+   return if $fail{$class}{new} and $fail{$class}{new}--;
+   bless( { @_ }, $class );
+}
+
+sub send {
+   my $self = shift;
+   my $class = ref($self);
+   return if $fail{$class}{send} and $fail{$class}{send}--;
+   $self->{sent} .= shift;
+}
+
+my $msg;
+sub set_message {
+   if (ref($_[0])) {
+   $self->{msg} = $_[1];
+   } else {
+   $msg = shift;
+   }
+}
+
+sub do_recv (\$$$) {
+   my ($buf, $len, $msg) = @_;
+   $$buf .= substr($msg, 0, $len, '');
+}
+
+sub recv {
+   my ($self, $buf, $length, $flags) = @_;
+   my $message = exists $self->{msg} ?
+   $self->{msg} : $msg;
+
+   if (defined($message)) {
+   do_recv($_[1], $length, $message);
+   }
+   1;
+}
+
+package IO::Select;
+
+$INC{'IO/Select.pm'} = 1;
+
+sub new {
+   my $class = shift;
+   return if defined $fail{$class}{new} and $fail{$class}{new}--;
+   bless({sock => shift}, $class);
+}
+
+sub can_read {
+   my ($self, $timeout) = @_;
+   my $class = ref($self);
+   return if defined $fail{$class}{can_read} and $fail{class}{can_read}--;
+   $self->{sock}{timeout} = $timeout;
+   1;
+}
+
+1;



Re: [PATCH t/TEST t/harness vms/test.com] Set PERL_CORE environment var

2001-10-17 Thread Jarkko Hietaniemi

On Wed, Oct 17, 2001 at 04:04:13AM -0400, Michael G Schwern wrote:
> I spent a few hours synching up Test::Simple pretty much by hand.  A
> simple recursive diff won't produce a useful patch since there's some
> things in the core version that aren't in the CPAN version.  The most
> prevalent example being the test magic:
> 
> BEGIN {
> chdir 't' if -d 't';
> @INC = '../lib';
> }
> 
> This patch sets the PERL_CORE environment variable when running core
> tests.  This way, the CPAN version of any core module can look almost
> exactly like the core version.
> 
> BEGIN {
> if( $ENV{PERL_CORE} ) {
> chdir 't' if -d 't';
> @INC = '../lib';
> }
> }
> 
> This will make my life much, much, much easier.

Thanks, applied.  If this $ENV{PERL_CORE} scheme works we can ask the
other dual life citizens to do the same.  Will make the pumpkin's life
much, much, much easier.

-- 
$jhi++; # http://www.iki.fi/jhi/
# There is this special biologist word we use for 'stable'.
# It is 'dead'. -- Jack Cohen



Re: [PATCH] Test::Simple 0.32

2001-10-17 Thread Jarkko Hietaniemi

On Wed, Oct 17, 2001 at 03:42:41AM -0400, Michael G Schwern wrote:
> This brings bleadperl in step with Test::Simple 0.32.  This'll give us
> Test::Builder, plan() and is_deeply().  Also, failure diagnostics now
> go to STDERR like they used to.
> 
> t/lib/Test/Simple/Catch/More.pm and lib/Test/Utils.pm are removed.
> t/lib/Test/Simple/Catch/ can be deleted.  A whole bunch of tests in
> lib/Test/Simple/t/ are added.

Thanks, applied.

-- 
$jhi++; # http://www.iki.fi/jhi/
# There is this special biologist word we use for 'stable'.
# It is 'dead'. -- Jack Cohen



Re: Test::More and WWW::Chat fighting over fail()

2001-10-17 Thread Simon Wistow

On Sun, Oct 07, 2001 at 07:06:45PM -0400, Michael G Schwern said:
> > Both Test::More and WWW::Chat export a routine called fail().  This
> > makes it rather hard to write tests for web stuff using both these
> > modules.
> 
> I can solve this from my end by providing control over Test::More's
> imported functions, something I've been neglecting to do.

Ok, sorry it's taken me so long but a new version of WWW::Chat has been
uploaded fixing the namespace problem.

Been a bit of a funny week ...


-- 
: off the wagon and hitching a ride



[PATCH t/TEST t/harness vms/test.com] Set PERL_CORE environment var

2001-10-17 Thread Michael G Schwern

I spent a few hours synching up Test::Simple pretty much by hand.  A
simple recursive diff won't produce a useful patch since there's some
things in the core version that aren't in the CPAN version.  The most
prevalent example being the test magic:

BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
}

This patch sets the PERL_CORE environment variable when running core
tests.  This way, the CPAN version of any core module can look almost
exactly like the core version.

BEGIN {
if( $ENV{PERL_CORE} ) {
chdir 't' if -d 't';
@INC = '../lib';
}
}

This will make my life much, much, much easier.

-- 

Michael G. Schwern   <[EMAIL PROTECTED]>http://www.pobox.com/~schwern/
Perl6 Quality Assurance <[EMAIL PROTECTED]>   Kwalitee Is Job One
Let me check my notes.
http://www.sluggy.com


--- t/TEST  2001/10/17 07:55:49 1.1
+++ t/TEST  2001/10/17 07:56:27
@@ -5,6 +5,10 @@
 
 $| = 1;
 
+# Let tests know they're running in the perl core.  Useful for modules
+# which live dual lives on CPAN.
+$ENV{PERL_CORE} = 1;
+
 # Cheesy version of Getopt::Std.  Maybe we should replace it with that.
 if ($#ARGV >= 0) {
 foreach my $idx (0..$#ARGV) {
--- t/harness   2001/10/17 07:57:18 1.1
+++ t/harness   2001/10/17 07:57:36
@@ -14,6 +14,10 @@
 $Test::Harness::switches = "";# Too much noise otherwise
 $Test::Harness::verbose = shift if @ARGV && $ARGV[0] eq '-v';
 
+# Let tests know they're running in the perl core.  Useful for modules
+# which live dual lives on CPAN.
+$ENV{PERL_CORE} = 1;
+
 #fudge DATA for now.
 %datahandle = qw(
lib/bigint.t1
--- vms/test.com2001/10/17 07:57:52 1.1
+++ vms/test.com2001/10/17 07:58:15
@@ -134,6 +134,10 @@
 
 $| = 1;
 
+# Let tests know they're running in the perl core.  Useful for modules
+# which live dual lives on CPAN.
+$ENV{PERL_CORE} = 1;
+
 @ARGV = grep($_,@ARGV);  # remove empty elements due to "''p1'" syntax
 
 if (lc($ARGV[0]) eq '-v') {