Upgrade to Test::Harness 2.57_05
[p5sagit/p5-mst-13.2.git] / lib / version.t
index e387095..9ed5d5b 100644 (file)
@@ -4,12 +4,12 @@
 
 #########################
 
-use Test::More tests => 200;
+use Test::More qw(no_plan);
 
 diag "Tests with base class" unless $ENV{PERL_CORE};
 
 BEGIN {
-    use_ok("version", 0.47); # If we made it this far, we are ok.
+    use_ok("version", 0.50); # If we made it this far, we are ok.
 }
 
 BaseTests("version");
@@ -17,10 +17,10 @@ BaseTests("version");
 diag "Tests with empty derived class" unless $ENV{PERL_CORE};
 
 package version::Empty;
-use vars qw($VERSION @ISA);
-use version 0.30;
-@ISA = qw(version);
+use base version;
 $VERSION = 0.01;
+no warnings 'redefine';
+*::qv = sub { return bless version::qv(shift), __PACKAGE__; };
 
 package version::Bad;
 use base version;
@@ -94,12 +94,35 @@ sub BaseTests {
        like($@, qr/underscores before decimal/,
            "Invalid version format (underscores before decimal)");
        
-       $version = $CLASS->new("99 and 44/100 pure");
+       eval {my $version = $CLASS->new("1_2")};
+       like($@, qr/alpha without decimal/,
+           "Invalid version format (alpha without decimal)");
+
+       # for this first test, just upgrade the warn() to die()
+       eval {
+           local $SIG{__WARN__} = sub { die $_[0] };
+           $version = $CLASS->new("1.2b3");
+       };
+       my $warnregex = "Version string '.+' contains invalid data; ".
+               "ignoring: '.+'";
+
+       like($@, qr/$warnregex/,
+           "Version string contains invalid data; ignoring");
+
+       # from here on out capture the warning and test independently
+       my $warning;
+       local $SIG{__WARN__} = sub { $warning = $_[0] };
+       $version = $CLASS->new("99 and 44/100 pure");
+
+       like($warning, qr/$warnregex/,
+           "Version string contains invalid data; ignoring");
        ok ("$version" eq "99.000", '$version eq "99.000"');
        ok ($version->numify == 99.0, '$version->numify == 99.0');
        ok ($version->normal eq "v99.0.0", '$version->normal eq v99.0.0');
        
        $version = $CLASS->new("something");
+       like($warning, qr/$warnregex/,
+           "Version string contains invalid data; ignoring");
        ok (defined $version, 'defined $version');
        
        # reset the test object to something reasonable
@@ -109,7 +132,7 @@ sub BaseTests {
        ok ($version, 'boolean');
        
        # Test class membership
-       isa_ok ( $version, "version" );
+       isa_ok ( $version, $CLASS );
        
        # Test comparison operators with self
        diag "tests with self" unless $ENV{PERL_CORE};
@@ -235,10 +258,11 @@ sub BaseTests {
        ok ( $version eq "1.2.0", 'qv("1.2") eq "1.2.0"' );
        $version = qv(1.2);
        ok ( $version eq "1.2.0", 'qv(1.2) eq "1.2.0"' );
+       isa_ok( qv('5.008'), $CLASS );
 
        # test creation from existing version object
        diag "create new from existing version" unless $ENV{PERL_CORE};
-       ok (eval {$new_version = version->new($version)},
+       ok (eval {$new_version = $CLASS->new($version)},
                "new from existing object");
        ok ($new_version == $version, "class->new($version) identical");
        $new_version = $version->new();
@@ -248,9 +272,9 @@ sub BaseTests {
 
        # test the CVS revision mode
        diag "testing CVS Revision" unless $ENV{PERL_CORE};
-       $version = new version qw$Revision: 1.2$;
+       $version = new $CLASS qw$Revision: 1.2$;
        ok ( $version eq "1.2.0", 'qw$Revision: 1.2$ eq 1.2.0' );
-       $version = new version qw$Revision: 1.2.3.4$;
+       $version = new $CLASS qw$Revision: 1.2.3.4$;
        ok ( $version eq "1.2.3.4", 'qw$Revision: 1.2.3.4$ eq 1.2.3.4' );
        
        # test the CPAN style reduced significant digit form
@@ -320,3 +344,5 @@ SKIP:       {
        ok($version->numify eq "1.700", "leading space ignored");
 
 }
+
+1;