This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Bring core Perl in line with CPAN 0.86 release
[perl5.git] / lib / version.t
index bb5a8f8..23ad2c9 100644 (file)
@@ -5,43 +5,83 @@
 #########################
 
 use Test::More qw(no_plan);
+use Data::Dumper;
 require Test::Harness;
 no warnings 'once';
 *Verbose = \$Test::Harness::Verbose;
-
-diag "Tests with base class" unless $ENV{PERL_CORE};
+use POSIX qw/locale_h/;
+use File::Temp qw/tempfile/;
+use File::Basename;
 
 BEGIN {
-    use_ok("version", 0.50); # If we made it this far, we are ok.
+    use_ok("version", 0.77);
+    # If we made it this far, we are ok.
 }
 
-BaseTests("version");
+my $Verbose;
 
-diag "Tests with empty derived class" unless $ENV{PERL_CORE};
+diag "Tests with base class" unless $ENV{PERL_CORE};
 
-package version::Empty;
-use base version;
-$VERSION = 0.01;
-no warnings 'redefine';
-*::qv = sub { return bless version::qv(shift), __PACKAGE__; };
+BaseTests("version","new","qv");
+BaseTests("version","new","declare");
+BaseTests("version","parse", "qv");
+BaseTests("version","parse", "declare");
+
+# dummy up a redundant call to satify David Wheeler
+local $SIG{__WARN__} = sub { die $_[0] };
+eval 'use version;';
+unlike ($@, qr/^Subroutine main::declare redefined/,
+    "Only export declare once per package (to prevent redefined warnings)."); 
 
 package version::Bad;
-use base version;
+use base 'version';
 sub new { my($self,$n)=@_;  bless \$n, $self }
 
 package main;
-my $testobj = version::Empty->new(1.002_003);
-isa_ok( $testobj, "version::Empty" );
+
+my $warning;
+local $SIG{__WARN__} = sub { $warning = $_[0] };
+my ($fh, $filename) = tempfile('tXXXXXXX', SUFFIX => '.pm', UNLINK => 1);
+(my $package = basename($filename)) =~ s/\.pm$//;
+print $fh <<"EOF";
+# This is an empty subclass
+package $package;
+use base 'version';
+use vars '\$VERSION';
+\$VERSION=0.001;
+EOF
+close $fh;
+
+sub main_reset {
+    delete $main::INC{'$package'};
+    undef &qv; undef *::qv; # avoid 'used once' warning
+    undef &declare; undef *::declare; # avoid 'used once' warning
+}
+
+diag "Tests with empty derived class"  unless $ENV{PERL_CORE};
+
+use_ok($package, 0.001);
+my $testobj = $package->new(1.002_003);
+isa_ok( $testobj, $package );
 ok( $testobj->numify == 1.002003, "Numified correctly" );
 ok( $testobj->stringify eq "1.002003", "Stringified correctly" );
 ok( $testobj->normal eq "v1.2.3", "Normalified correctly" );
 
-my $verobj = version->new("1.2.4");
+my $verobj = version::->new("1.2.4");
 ok( $verobj > $testobj, "Comparison vs parent class" );
-ok( $verobj gt $testobj, "Comparison vs parent class" );
-BaseTests("version::Empty");
 
-diag "tests with bad subclass" unless $ENV{PERL_CORE};
+BaseTests($package, "new", "qv");
+main_reset;
+use_ok($package, 0.001, "declare");
+BaseTests($package, "new", "declare");
+main_reset;
+use_ok($package, 0.001);
+BaseTests($package, "parse", "qv");
+main_reset;
+use_ok($package, 0.001, "declare");
+BaseTests($package, "parse", "declare");
+
+diag "tests with bad subclass"  unless $ENV{PERL_CORE};
 $testobj = version::Bad->new(1.002_003);
 isa_ok( $testobj, "version::Bad" );
 eval { my $string = $testobj->numify };
@@ -53,89 +93,143 @@ like($@, qr/Invalid version object/,
 eval { my $string = $testobj->stringify };
 like($@, qr/Invalid version object/,
     "Bad subclass stringify");
-eval { my $test = $testobj > 1.0 };
+eval { my $test = ($testobj > 1.0) };
 like($@, qr/Invalid version object/,
     "Bad subclass vcmp");
 
-# dummy up a redundant call to satify David Wheeler
-local $SIG{__WARN__} = sub { die $_[0] };
-eval 'use version;';
-unlike ($@, qr/^Subroutine main::qv redefined/,
-    "Only export qv once per package (to prevent redefined warnings)."); 
+# Invalid structure
+eval { $a = \\version->new(1); bless $a, "version"; print "# $a\n" };
+like($@, qr/Invalid version object/,
+    "Bad internal structure (RT#78286)");
+
+# do strict lax tests in a sub to isolate a package to test importing
+strict_lax_tests();
+
+sub strict_lax_tests {
+  package temp12345;
+  # copied from perl core test t/op/packagev.t
+  # format: STRING STRICT_OK LAX_OK
+  my $strict_lax_data = << 'CASE_DATA';
+1.00           pass    pass
+1.00001                pass    pass
+0.123          pass    pass
+12.345         pass    pass
+42             pass    pass
+0              pass    pass
+0.0            pass    pass
+v1.2.3         pass    pass
+v1.2.3.4       pass    pass
+v0.1.2         pass    pass
+v0.0.0         pass    pass
+01             fail    pass
+01.0203                fail    pass
+v01            fail    pass
+v01.02.03      fail    pass
+.1             fail    pass
+.1.2           fail    pass
+1.             fail    pass
+1.a            fail    fail
+1._            fail    fail
+1.02_03                fail    pass
+v1.2_3         fail    pass
+v1.02_03       fail    pass
+v1.2_3_4       fail    fail
+v1.2_3.4       fail    fail
+1.2_3.4                fail    fail
+0_             fail    fail
+1_             fail    fail
+1_.            fail    fail
+1.1_           fail    fail
+1.02_03_04     fail    fail
+1.2.3          fail    pass
+v1.2           fail    pass
+v0             fail    pass
+v1             fail    pass
+v.1.2.3                fail    fail
+v              fail    fail
+v1.2345.6      fail    pass
+undef          fail    pass
+1a             fail    fail
+1.2a3          fail    fail
+bar            fail    fail
+_              fail    fail
+CASE_DATA
+
+  require version;
+  version->import( qw/is_strict is_lax/ );
+  for my $case ( split qr/\n/, $strict_lax_data ) {
+    my ($v, $strict, $lax) = split qr/\t+/, $case;
+    main::ok( $strict eq 'pass' ? is_strict($v) : ! is_strict($v), "is_strict($v) [$strict]" );
+    main::ok( $strict eq 'pass' ? version::is_strict($v) : ! version::is_strict($v), "version::is_strict($v) [$strict]" );
+    main::ok( $lax eq 'pass' ? is_lax($v) : ! is_lax($v), "is_lax($v) [$lax]" );
+    main::ok( $lax eq 'pass' ? version::is_lax($v) : ! version::is_lax($v), "version::is_lax($v) [$lax]" );
+  }
+}
 
 sub BaseTests {
 
-    my ($CLASS, $no_qv) = @_;
+    my ($CLASS, $method, $qv_declare) = @_;
+    my $warning;
+    local $SIG{__WARN__} = sub { $warning = $_[0] };
     
     # Insert your test code below, the Test module is use()ed here so read
     # its man page ( perldoc Test ) for help writing this test script.
     
     # Test bare number processing
-    diag "tests with bare numbers" if $Verbose;
-    $version = $CLASS->new(5.005_03);
-    is ( "$version" , "5.005030" , '5.005_03 eq 5.5.30' );
-    $version = $CLASS->new(1.23);
-    is ( "$version" , "1.230" , '1.23 eq "1.230"' );
+    diag "tests with bare numbers" unless $ENV{PERL_CORE};
+    $version = $CLASS->$method(5.005_03);
+    is ( "$version" , "5.00503" , '5.005_03 eq 5.00503' );
+    $version = $CLASS->$method(1.23);
+    is ( "$version" , "1.23" , '1.23 eq "1.23"' );
     
     # Test quoted number processing
-    diag "tests with quoted numbers" if $Verbose;
-    $version = $CLASS->new("5.005_03");
-    is ( "$version" , "5.005_030" , '"5.005_03" eq "5.005_030"' );
-    $version = $CLASS->new("v1.23");
-    is ( "$version" , "v1.23.0" , '"v1.23" eq "v1.23.0"' );
+    diag "tests with quoted numbers" unless $ENV{PERL_CORE};
+    $version = $CLASS->$method("5.005_03");
+    is ( "$version" , "5.005_03" , '"5.005_03" eq "5.005_03"' );
+    $version = $CLASS->$method("v1.23");
+    is ( "$version" , "v1.23" , '"v1.23" eq "v1.23"' );
     
     # Test stringify operator
-    diag "tests with stringify" if $Verbose;
-    $version = $CLASS->new("5.005");
+    diag "tests with stringify" unless $ENV{PERL_CORE};
+    $version = $CLASS->$method("5.005");
     is ( "$version" , "5.005" , '5.005 eq "5.005"' );
-    $version = $CLASS->new("5.006.001");
-    is ( "$version" , "v5.6.1" , '5.006.001 eq v5.6.1' );
-    $version = $CLASS->new("1.2.3_4");
+    $version = $CLASS->$method("5.006.001");
+    is ( "$version" , "5.006.001" , '5.006.001 eq v5.6.1' );
+    unlike ($warning, qr/v-string without leading 'v' deprecated/, 'No leading v');
+    $version = $CLASS->$method("v1.2.3_4");
     is ( "$version" , "v1.2.3_4" , 'alpha version 1.2.3_4 eq v1.2.3_4' );
     
     # test illegal formats
-    diag "test illegal formats" if $Verbose;
-    eval {my $version = $CLASS->new("1.2_3_4")};
+    diag "test illegal formats" unless $ENV{PERL_CORE};
+    eval {my $version = $CLASS->$method("1.2_3_4")};
     like($@, qr/multiple underscores/,
        "Invalid version format (multiple underscores)");
     
-    eval {my $version = $CLASS->new("1.2_3.4")};
+    eval {my $version = $CLASS->$method("1.2_3.4")};
     like($@, qr/underscores before decimal/,
        "Invalid version format (underscores before decimal)");
     
-    eval {my $version = $CLASS->new("1_2")};
+    eval {my $version = $CLASS->$method("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");
+    eval { $version = $CLASS->$method("1.2b3")};
+    like($@, qr/non-numeric data/,
+       "Invalid version format (non-numeric data)");
 
     # 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");
+    {
+    eval{$version = $CLASS->$method("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');
+    like($@, qr/non-numeric data/,
+       "Invalid version format (non-numeric data)");
     
-    $version = $CLASS->new("something");
-    like($warning, qr/$warnregex/,
-       "Version string contains invalid data; ignoring");
-    ok (defined $version, 'defined $version');
+    eval{$version = $CLASS->$method("something")};
+    like($@, qr/non-numeric data/,
+       "Invalid version format (non-numeric data)");
     
     # reset the test object to something reasonable
-    $version = $CLASS->new("1.2.3");
+    $version = $CLASS->$method("1.2.3");
     
     # Test boolean operator
     ok ($version, 'boolean');
@@ -144,119 +238,98 @@ sub BaseTests {
     isa_ok ( $version, $CLASS );
     
     # Test comparison operators with self
-    diag "tests with self" if $Verbose;
-    ok ( $version eq $version, '$version eq $version' );
-    is ( $version cmp $version, 0, '$version cmp $version == 0' );
+    diag "tests with self" unless $ENV{PERL_CORE};
+    is ( $version <=> $version, 0, '$version <=> $version == 0' );
     ok ( $version == $version, '$version == $version' );
     
-    # test first with non-object
-    $version = $CLASS->new("5.006.001");
-    $new_version = "5.8.0";
-    diag "tests with non-objects" if $Verbose;
-    ok ( $version ne $new_version, '$version ne $new_version' );
-    ok ( $version lt $new_version, '$version lt $new_version' );
-    ok ( $new_version gt $version, '$new_version gt $version' );
-    ok ( ref(\$new_version) eq 'SCALAR', 'no auto-upgrade');
-    $new_version = "$version";
-    ok ( $version eq $new_version, '$version eq $new_version' );
-    ok ( $new_version eq $version, '$new_version eq $version' );
-    
-    # now test with existing object
-    $new_version = $CLASS->new("5.8.0");
-    diag "tests with objects" if $Verbose;
-    ok ( $version ne $new_version, '$version ne $new_version' );
-    ok ( $version lt $new_version, '$version lt $new_version' );
-    ok ( $new_version gt $version, '$new_version gt $version' );
-    $new_version = $CLASS->new("$version");
-    ok ( $version eq $new_version, '$version eq $new_version' );
-    
     # Test Numeric Comparison operators
     # test first with non-object
+    $version = $CLASS->$method("5.006.001");
     $new_version = "5.8.0";
-    diag "numeric tests with non-objects" if $Verbose;
+    diag "numeric tests with non-objects" unless $ENV{PERL_CORE};
     ok ( $version == $version, '$version == $version' );
     ok ( $version < $new_version, '$version < $new_version' );
     ok ( $new_version > $version, '$new_version > $version' );
     ok ( $version != $new_version, '$version != $new_version' );
     
     # now test with existing object
-    $new_version = $CLASS->new($new_version);
-    diag "numeric tests with objects" if $Verbose;
+    $new_version = $CLASS->$method($new_version);
+    diag "numeric tests with objects" unless $ENV{PERL_CORE};
     ok ( $version < $new_version, '$version < $new_version' );
     ok ( $new_version > $version, '$new_version > $version' );
     ok ( $version != $new_version, '$version != $new_version' );
     
     # now test with actual numbers
-    diag "numeric tests with numbers" if $Verbose;
+    diag "numeric tests with numbers" unless $ENV{PERL_CORE};
     ok ( $version->numify() == 5.006001, '$version->numify() == 5.006001' );
     ok ( $version->numify() <= 5.006001, '$version->numify() <= 5.006001' );
     ok ( $version->numify() < 5.008, '$version->numify() < 5.008' );
     #ok ( $version->numify() > v5.005_02, '$version->numify() > 5.005_02' );
     
     # test with long decimals
-    diag "Tests with extended decimal versions" if $Verbose;
-    $version = $CLASS->new(1.002003);
-    ok ( $version eq "1.2.3", '$version eq "1.2.3"');
+    diag "Tests with extended decimal versions" unless $ENV{PERL_CORE};
+    $version = $CLASS->$method(1.002003);
+    ok ( $version == "1.2.3", '$version == "1.2.3"');
     ok ( $version->numify == 1.002003, '$version->numify == 1.002003');
-    $version = $CLASS->new("2002.09.30.1");
-    ok ( $version eq "2002.9.30.1",'$version eq 2002.9.30.1');
+    $version = $CLASS->$method("2002.09.30.1");
+    ok ( $version == "2002.9.30.1",'$version == 2002.9.30.1');
     ok ( $version->numify == 2002.009030001,
        '$version->numify == 2002.009030001');
     
     # now test with alpha version form with string
-    $version = $CLASS->new("1.2.3");
+    $version = $CLASS->$method("1.2.3");
     $new_version = "1.2.3_4";
-    diag "tests with alpha-style non-objects" if $Verbose;
-    ok ( $version lt $new_version, '$version lt $new_version' );
-    ok ( $new_version gt $version, '$new_version gt $version' );
-    ok ( $version ne $new_version, '$version ne $new_version' );
+    diag "numeric tests with alpha-style non-objects" unless $ENV{PERL_CORE};
+    ok ( $version < $new_version, '$version < $new_version' );
+    ok ( $new_version > $version, '$new_version > $version' );
+    ok ( $version != $new_version, '$version != $new_version' );
     
-    $version = $CLASS->new("1.2.4");
+    $version = $CLASS->$method("1.2.4");
     diag "numeric tests with alpha-style non-objects"
-       if $Verbose;
+       unless $ENV{PERL_CORE};
     ok ( $version > $new_version, '$version > $new_version' );
     ok ( $new_version < $version, '$new_version < $version' );
     ok ( $version != $new_version, '$version != $new_version' );
     
     # now test with alpha version form with object
-    $version = $CLASS->new("1.2.3");
-    $new_version = $CLASS->new("1.2.3_4");
-    diag "tests with alpha-style objects" if $Verbose;
+    $version = $CLASS->$method("1.2.3");
+    $new_version = $CLASS->$method("1.2.3_4");
+    diag "tests with alpha-style objects" unless $ENV{PERL_CORE};
     ok ( $version < $new_version, '$version < $new_version' );
     ok ( $new_version > $version, '$new_version > $version' );
     ok ( $version != $new_version, '$version != $new_version' );
     ok ( !$version->is_alpha, '!$version->is_alpha');
     ok ( $new_version->is_alpha, '$new_version->is_alpha');
     
-    $version = $CLASS->new("1.2.4");
-    diag "tests with alpha-style objects" if $Verbose;
+    $version = $CLASS->$method("1.2.4");
+    diag "tests with alpha-style objects" unless $ENV{PERL_CORE};
     ok ( $version > $new_version, '$version > $new_version' );
     ok ( $new_version < $version, '$new_version < $version' );
     ok ( $version != $new_version, '$version != $new_version' );
     
-    $version = $CLASS->new("1.2.3.4");
-    $new_version = $CLASS->new("1.2.3_4");
+    $version = $CLASS->$method("1.2.3.4");
+    $new_version = $CLASS->$method("1.2.3_4");
     diag "tests with alpha-style objects with same subversion"
-       if $Verbose;
+       unless $ENV{PERL_CORE};
     ok ( $version > $new_version, '$version > $new_version' );
     ok ( $new_version < $version, '$new_version < $version' );
     ok ( $version != $new_version, '$version != $new_version' );
     
-    diag "test implicit [in]equality" if $Verbose;
-    $version = $CLASS->new("v1.2.3");
-    $new_version = $CLASS->new("1.2.3.0");
+    diag "test implicit [in]equality" unless $ENV{PERL_CORE};
+    $version = $CLASS->$method("v1.2.3");
+    $new_version = $CLASS->$method("1.2.3.0");
     ok ( $version == $new_version, '$version == $new_version' );
-    $new_version = $CLASS->new("1.2.3_0");
+    $new_version = $CLASS->$method("1.2.3_0");
     ok ( $version == $new_version, '$version == $new_version' );
-    $new_version = $CLASS->new("1.2.3.1");
+    $new_version = $CLASS->$method("1.2.3.1");
     ok ( $version < $new_version, '$version < $new_version' );
-    $new_version = $CLASS->new("1.2.3_1");
+    $new_version = $CLASS->$method("1.2.3_1");
     ok ( $version < $new_version, '$version < $new_version' );
-    $new_version = $CLASS->new("1.1.999");
+    $new_version = $CLASS->$method("1.1.999");
     ok ( $version > $new_version, '$version > $new_version' );
     
     # that which is not expressly permitted is forbidden
-    diag "forbidden operations" if $Verbose;
+    diag "forbidden operations" unless $ENV{PERL_CORE};
     ok ( !eval { ++$version }, "noop ++" );
     ok ( !eval { --$version }, "noop --" );
     ok ( !eval { $version/1 }, "noop /" );
@@ -264,250 +337,390 @@ sub BaseTests {
     ok ( !eval { abs($version) }, "noop abs" );
 
 SKIP: {
-    skip "version require'd instead of use'd, cannot test qv", 3
-       if defined $no_qv;
-    # test the qv() sub
-    diag "testing qv" if $Verbose;
-    $version = qv("1.2");
-    cmp_ok ( $version, "eq", "v1.2.0", 'qv("1.2") eq "1.2.0"' );
-    $version = qv(1.2);
-    cmp_ok ( $version, "eq", "v1.2.0", 'qv(1.2) eq "1.2.0"' );
-    isa_ok( qv('5.008'), $CLASS );
+    skip "version require'd instead of use'd, cannot test $qv_declare", 3
+       unless defined $qv_declare;
+    # test the $qv_declare() sub
+    diag "testing $qv_declare" unless $ENV{PERL_CORE};
+    $version = $CLASS->$qv_declare("1.2");
+    is ( "$version", "v1.2", $qv_declare.'("1.2") == "1.2.0"' );
+    $version = $CLASS->$qv_declare(1.2);
+    is ( "$version", "v1.2", $qv_declare.'(1.2) == "1.2.0"' );
+    isa_ok( $CLASS->$qv_declare('5.008'), $CLASS );
 }
 
     # test creation from existing version object
-    diag "create new from existing version" if $Verbose;
-    ok (eval {$new_version = $CLASS->new($version)},
+    diag "create new from existing version" unless $ENV{PERL_CORE};
+    ok (eval {$new_version = $CLASS->$method($version)},
            "new from existing object");
-    ok ($new_version == $version, "class->new($version) identical");
-    $new_version = $version->new();
+    ok ($new_version == $version, "class->$method($version) identical");
+    $new_version = $version->$method(0);
     isa_ok ($new_version, $CLASS );
-    is ($new_version, "0.000", "version->new() doesn't clone");
-    $new_version = $version->new("1.2.3");
-    is ($new_version, "v1.2.3" , '$version->new("1.2.3") works too');
+    is ($new_version, "0", "version->$method() doesn't clone");
+    $new_version = $version->$method("1.2.3");
+    is ($new_version, "1.2.3" , '$version->$method("1.2.3") works too');
 
     # test the CVS revision mode
-    diag "testing CVS Revision" if $Verbose;
+    diag "testing CVS Revision" unless $ENV{PERL_CORE};
     $version = new $CLASS qw$Revision: 1.2$;
-    ok ( $version eq "1.2.0", 'qw$Revision: 1.2$ eq 1.2.0' );
+    ok ( $version == "1.2.0", 'qw$Revision: 1.2$ == 1.2.0' );
     $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' );
+    ok ( $version == "1.2.3.4", 'qw$Revision: 1.2.3.4$ == 1.2.3.4' );
     
     # test the CPAN style reduced significant digit form
-    diag "testing CPAN-style versions" if $Verbose;
-    $version = $CLASS->new("1.23_01");
-    is ( "$version" , "1.23_0100", "CPAN-style alpha version" );
+    diag "testing CPAN-style versions" unless $ENV{PERL_CORE};
+    $version = $CLASS->$method("1.23_01");
+    is ( "$version" , "1.23_01", "CPAN-style alpha version" );
     ok ( $version > 1.23, "1.23_01 > 1.23");
     ok ( $version < 1.24, "1.23_01 < 1.24");
 
     # test reformed UNIVERSAL::VERSION
-    diag "Replacement UNIVERSAL::VERSION tests" if $Verbose;
-    
-    # we know this file is here since we require it ourselves
-    $version = $Test::More::VERSION;
-    eval "use Test::More $version";
-    unlike($@, qr/Test::More version $version/,
-           'Replacement eval works with exact version');
-    
-    # test as class method
-    $new_version = Test::More->VERSION;
-    cmp_ok($new_version,'cmp',$version, "Called as class method");
-
-    # this should fail even with old UNIVERSAL::VERSION
-    $version = $Test::More::VERSION+0.01;
-    eval "use Test::More $version";
-    like($@, qr/Test::More version $version/,
-           'Replacement eval works with incremented version');
-    
-    TODO: {
-        local $TODO = "Test fails with Test::More versions ending in _0X";
-        $version =~ s/\.0$//; #convert to string and remove trailing '.0'
-        chop($version);        # shorten by 1 digit, should still succeed
-        eval "use Test::More $version";
-        unlike($@, qr/Test::More version $version/,
-           'Replacement eval works with single digit');
-    }
+    diag "Replacement UNIVERSAL::VERSION tests" unless $ENV{PERL_CORE};
+
+    my $error_regex = $] < 5.006
+       ? 'version \d required'
+       : 'does not define \$t.{7}::VERSION';
+    
+    {
+       my ($fh, $filename) = tempfile('tXXXXXXX', SUFFIX => '.pm', UNLINK => 1);
+       (my $package = basename($filename)) =~ s/\.pm$//;
+       print $fh "package $package;\n\$$package\::VERSION=0.58;\n1;\n";
+       close $fh;
+
+       $version = 0.58;
+       eval "use lib '.'; use $package $version";
+       unlike($@, qr/$package version $version/,
+               'Replacement eval works with exact version');
+       
+       # test as class method
+       $new_version = $package->VERSION;
+       cmp_ok($new_version,'==',$version, "Called as class method");
+
+       eval "print Completely::Unknown::Module->VERSION";
+       if ( $] < 5.008 ) {
+           unlike($@, qr/$error_regex/,
+               "Don't freak if the module doesn't even exist");
+       }
+       else {
+           unlike($@, qr/defines neither package nor VERSION/,
+               "Don't freak if the module doesn't even exist");
+       }
 
-    $version += 0.1; # this would fail with old UNIVERSAL::VERSION
-    eval "use Test::More $version";
-    like($@, qr/Test::More version $version/,
-           'Replacement eval works with incremented digit');
+       # this should fail even with old UNIVERSAL::VERSION
+       $version += 0.01;
+       eval "use lib '.'; use $package $version";
+       like($@, qr/$package version $version/,
+               'Replacement eval works with incremented version');
+       
+       $version =~ s/0+$//; #convert to string and remove trailing 0's
+       chop($version); # shorten by 1 digit, should still succeed
+       eval "use lib '.'; use $package $version";
+       unlike($@, qr/$package version $version/,
+               'Replacement eval works with single digit');
+       
+       # this would fail with old UNIVERSAL::VERSION
+       $version += 0.1;
+       eval "use lib '.'; use $package $version";
+       like($@, qr/$package version $version/,
+               'Replacement eval works with incremented digit');
+       unlink $filename;
+    }
 
     { # dummy up some variously broken modules for testing
-       open F, ">xxx.pm" or die "Cannot open xxx.pm: $!\n";
-       print F "1;\n";
-       close F;
-       my $error_regex;
+       my ($fh, $filename) = tempfile('tXXXXXXX', SUFFIX => '.pm', UNLINK => 1);
+       (my $package = basename($filename)) =~ s/\.pm$//;
+       print $fh "1;\n";
+       close $fh;
+
+       eval "use lib '.'; use $package 3;";
        if ( $] < 5.008 ) {
-           $error_regex = 'xxx does not define \$xxx::VERSION';
+           like($@, qr/$error_regex/,
+               'Replacement handles modules without package or VERSION'); 
        }
        else {
-           $error_regex = 'xxx defines neither package nor VERSION';
+           like($@, qr/defines neither package nor VERSION/,
+               'Replacement handles modules without package or VERSION'); 
        }
-
-       eval "use lib '.'; use xxx 3;";
-       like ($@, qr/$error_regex/,
-           'Replacement handles modules without package or VERSION'); 
-       eval "use lib '.'; use xxx; $version = xxx->VERSION";
+       eval "use lib '.'; use $package; \$version = $package->VERSION";
        unlike ($@, qr/$error_regex/,
            'Replacement handles modules without package or VERSION'); 
-       ok (defined($version), "Called as class method");
-       unlink 'xxx.pm';
+       ok (!defined($version), "Called as class method");
+       unlink $filename;
     }
     
     { # dummy up some variously broken modules for testing
-       open F, ">yyy.pm" or die "Cannot open yyy.pm: $!\n";
-       print F "package yyy;\n#look ma no VERSION\n1;\n";
-       close F;
-       eval "use lib '.'; use yyy 3;";
-       like ($@, qr/^yyy does not define \$yyy::VERSION/,
+       my ($fh, $filename) = tempfile('tXXXXXXX', SUFFIX => '.pm', UNLINK => 1);
+       (my $package = basename($filename)) =~ s/\.pm$//;
+       print $fh "package $package;\n#look ma no VERSION\n1;\n";
+       close $fh;
+       eval "use lib '.'; use $package 3;";
+       like ($@, qr/$error_regex/,
            'Replacement handles modules without VERSION'); 
-       eval "use lib '.'; use yyy; print yyy->VERSION";
-       unlike ($@, qr/^yyy does not define \$yyy::VERSION/,
+       eval "use lib '.'; use $package; print $package->VERSION";
+       unlike ($@, qr/$error_regex/,
            'Replacement handles modules without VERSION'); 
-       unlink 'yyy.pm';
+       unlink $filename;
     }
 
     { # dummy up some variously broken modules for testing
-       open F, ">zzz.pm" or die "Cannot open zzz.pm: $!\n";
-       print F "package zzz;\n\@VERSION = ();\n1;\n";
-       close F;
-       eval "use lib '.'; use zzz 3;";
-       like ($@, qr/^zzz does not define \$zzz::VERSION/,
+       my ($fh, $filename) = tempfile('tXXXXXXX', SUFFIX => '.pm', UNLINK => 1);
+       (my $package = basename($filename)) =~ s/\.pm$//;
+       print $fh "package $package;\n\@VERSION = ();\n1;\n";
+       close $fh;
+       eval "use lib '.'; use $package 3;";
+       like ($@, qr/$error_regex/,
            'Replacement handles modules without VERSION'); 
-       eval "use lib '.'; use zzz; print zzz->VERSION";
-       unlike ($@, qr/^zzz does not define \$zzz::VERSION/,
+       eval "use lib '.'; use $package; print $package->VERSION";
+       unlike ($@, qr/$error_regex/,
            'Replacement handles modules without VERSION'); 
-       unlink 'zzz.pm';
+       unlink $filename;
     }
 
 SKIP:  {
-       skip 'Cannot test bare v-strings with Perl < 5.8.1', 4
-               if $] < 5.008_001
-       diag "Tests with v-strings" if $Verbose;
-       $version = $CLASS->new(1.2.3);
+       skip 'Cannot test bare v-strings with Perl < 5.6.0', 4
+               if $] < 5.006_000
+       diag "Tests with v-strings" unless $ENV{PERL_CORE};
+       $version = $CLASS->$method(1.2.3);
        ok("$version" eq "v1.2.3", '"$version" eq 1.2.3');
-       $version = $CLASS->new(1.0.0);
-       $new_version = $CLASS->new(1);
+       $version = $CLASS->$method(1.0.0);
+       $new_version = $CLASS->$method(1);
        ok($version == $new_version, '$version == $new_version');
-       ok($version eq $new_version, '$version eq $new_version');
-       skip "version require'd instead of use'd, cannot test qv", 1
-           if defined $no_qv;
-       $version = qv(1.2.3);
-       ok("$version" eq "v1.2.3", 'v-string initialized qv()');
+       skip "version require'd instead of use'd, cannot test declare", 1
+           unless defined $qv_declare;
+       $version = &$qv_declare(1.2.3);
+       ok("$version" eq "v1.2.3", 'v-string initialized $qv_declare()');
     }
 
-    diag "Tests with real-world (malformed) data" if $Verbose;
+SKIP:  {
+       skip 'Cannot test bare alpha v-strings with Perl < 5.8.1', 2
+               if $] lt 5.008_001; 
+       diag "Tests with bare alpha v-strings" unless $ENV{PERL_CORE};
+       $version = $CLASS->$method(v1.2.3_4);
+       is($version, "v1.2.3_4", '"$version" eq "v1.2.3_4"');
+       $version = $CLASS->$method(eval "v1.2.3_4");
+       is($version, "v1.2.3_4", '"$version" eq "v1.2.3_4" (from eval)');
+    }
+
+    diag "Tests with real-world (malformed) data" unless $ENV{PERL_CORE};
 
     # trailing zero testing (reported by Andreas Koenig).
-    $version = $CLASS->new("1");
+    $version = $CLASS->$method("1");
     ok($version->numify eq "1.000", "trailing zeros preserved");
-    $version = $CLASS->new("1.0");
+    $version = $CLASS->$method("1.0");
     ok($version->numify eq "1.000", "trailing zeros preserved");
-    $version = $CLASS->new("1.0.0");
+    $version = $CLASS->$method("1.0.0");
     ok($version->numify eq "1.000000", "trailing zeros preserved");
-    $version = $CLASS->new("1.0.0.0");
+    $version = $CLASS->$method("1.0.0.0");
     ok($version->numify eq "1.000000000", "trailing zeros preserved");
     
     # leading zero testing (reported by Andreas Koenig).
-    $version = $CLASS->new(".7");
+    $version = $CLASS->$method(".7");
     ok($version->numify eq "0.700", "leading zero inferred");
 
     # leading space testing (reported by Andreas Koenig).
-    $version = $CLASS->new(" 1.7");
+    $version = $CLASS->$method(" 1.7");
     ok($version->numify eq "1.700", "leading space ignored");
 
     # RT 19517 - deal with undef and 'undef' initialization
-    ok($version ne 'undef', "Undef version comparison #1");
-    ok($version ne undef, "Undef version comparison #2");
-    $version = $CLASS->new('undef');
+    ok("$version" ne 'undef', "Undef version comparison #1");
+    ok("$version" ne undef, "Undef version comparison #2");
+    $version = $CLASS->$method('undef');
     unlike($warning, qr/^Version string 'undef' contains invalid data/,
        "Version string 'undef'");
 
-    $version = $CLASS->new(undef);
+    $version = $CLASS->$method(undef);
     like($warning, qr/^Use of uninitialized value/,
        "Version string 'undef'");
-    ok($version eq 'undef', "Undef version comparison #3");
-    ok($version eq undef, "Undef version comparison #4");
-    eval "\$version = \$CLASS->new()"; # no parameter at all
+    ok($version == 'undef', "Undef version comparison #3");
+    ok($version ==  undef,  "Undef version comparison #4");
+    eval "\$version = \$CLASS->$method()"; # no parameter at all
     unlike($@, qr/^Bizarre copy of CODE/, "No initializer at all");
-    ok($version eq 'undef', "Undef version comparison #5");
-    ok($version eq undef, "Undef version comparison #6");
+    ok($version == 'undef', "Undef version comparison #5");
+    ok($version ==  undef,  "Undef version comparison #6");
 
-    $version = $CLASS->new(0.000001);
+    $version = $CLASS->$method(0.000001);
     unlike($warning, qr/^Version string '1e-06' contains invalid data/,
        "Very small version objects");
+    }
 
 SKIP: {
+       my $warning;
+       local $SIG{__WARN__} = sub { $warning = $_[0] };
        # dummy up a legal module for testing RT#19017
-       open F, ">www.pm" or die "Cannot open www.pm: $!\n";
-       print F <<"EOF";
-package www;
-use version; \$VERSION = qv('0.0.4');
+       my ($fh, $filename) = tempfile('tXXXXXXX', SUFFIX => '.pm', UNLINK => 1);
+       (my $package = basename($filename)) =~ s/\.pm$//;
+       print $fh <<"EOF";
+package $package;
+use $CLASS; \$VERSION = ${CLASS}->new('0.0.4');
 1;
 EOF
-       close F;
+       close $fh;
 
-       eval "use lib '.'; use www 0.000008;";
-       like ($@, qr/^www version 0.000008 \(v0.0.8\) required/,
+       eval "use lib '.'; use $package 0.000008;";
+       like ($@, qr/^$package version 0.000008 required/,
            "Make sure very small versions don't freak"); 
-       eval "use lib '.'; use www 1;";
-       like ($@, qr/^www version 1.000 \(v1.0.0\) required/,
+       eval "use lib '.'; use $package 1;";
+       like ($@, qr/^$package version 1 required/,
            "Comparing vs. version with no decimal"); 
-       eval "use lib '.'; use www 1.;";
-       like ($@, qr/^www version 1.000 \(v1.0.0\) required/,
+       eval "use lib '.'; use $package 1.;";
+       like ($@, qr/^$package version 1 required/,
            "Comparing vs. version with decimal only"); 
-
-       if ( $] < 5.006_002 ) {
-           unlink 'www.pm';
-           skip 'Cannot "use" extended versions with Perl < 5.6.2', 3; 
+       if ( $] < 5.006_000 ) {
+           skip 'Cannot "use" extended versions with Perl < 5.6.0', 3; 
        }
-       eval "use lib '.'; use www 0.0.8;";
-       like ($@, qr/^www version 0.000008 \(v0.0.8\) required/,
-           "Make sure very small versions don't freak"); 
-
-       eval "use lib '.'; use www 0.0.4;";
-       unlike($@, qr/^www version 0.000004 \(v0.0.4\) required/,
-           'Succeed - required == VERSION');
-       cmp_ok ( "www"->VERSION, 'eq', '0.000004', 'No undef warnings' );
-
-       unlink 'www.pm';
+       eval "use lib '.'; use $package v0.0.8;";
+       my $regex = "^$package version v0.0.8 required";
+       like ($@, qr/$regex/, "Make sure very small versions don't freak"); 
+
+       $regex =~ s/8/4/; # set for second test
+       eval "use lib '.'; use $package v0.0.4;";
+       unlike($@, qr/$regex/, 'Succeed - required == VERSION');
+       cmp_ok ( $package->VERSION, 'eq', '0.0.4', 'No undef warnings' );
+       unlink $filename;
     }
 
-    open F, ">vvv.pm" or die "Cannot open vvv.pm: $!\n";
-    print F <<"EOF";
-package vvv;
+SKIP: {
+    skip 'Cannot test "use base qw(version)"  when require is used', 3
+       unless defined $qv_declare;
+    my ($fh, $filename) = tempfile('tXXXXXXX', SUFFIX => '.pm', UNLINK => 1);
+    (my $package = basename($filename)) =~ s/\.pm$//;
+    print $fh <<"EOF";
+package $package;
 use base qw(version);
 1;
 EOF
-    close F;
-    # need to eliminate any other qv()'s
-    undef *main::qv;
-    ok(!defined(&{"main\::qv"}), "make sure we cleared qv() properly");
-    eval "use lib '.'; use vvv;";
-    ok(defined(&{"main\::qv"}), "make sure we exported qv() properly");
-    isa_ok( qv(1.2), "vvv");
-    unlink 'vvv.pm';
+    close $fh;
+    # need to eliminate any other $qv_declare()'s
+    undef *{"main\::$qv_declare"};
+    ok(!defined(&{"main\::$qv_declare"}), "make sure we cleared $qv_declare() properly");
+    eval "use lib '.'; use $package qw/declare qv/;";
+    ok(defined(&{"main\::$qv_declare"}), "make sure we exported $qv_declare() properly");
+    isa_ok( &$qv_declare(1.2), $package);
+    unlink $filename;
+}
+
+SKIP: {
+       if ( $] < 5.006_000 ) {
+           skip 'Cannot "use" extended versions with Perl < 5.6.0', 3; 
+       }
+       my ($fh, $filename) = tempfile('tXXXXXXX', SUFFIX => '.pm', UNLINK => 1);
+       (my $package = basename($filename)) =~ s/\.pm$//;
+       print $fh <<"EOF";
+package $package;
+\$VERSION = 1.0;
+1;
+EOF
+       close $fh;
+       eval "use lib '.'; use $package 1.001;";
+       like ($@, qr/^$package version 1.001 required/,
+           "User typed numeric so we error with numeric"); 
+       eval "use lib '.'; use $package v1.1.0;";
+       like ($@, qr/^$package version v1.1.0 required/,
+           "User typed extended so we error with extended"); 
+       unlink $filename;
+    }
 
 SKIP: {
        # test locale handling
+       my $warning;
+       local $SIG{__WARN__} = sub { $warning = $_[0] };
+
+$DB::single = 1;
+       my $v = eval { $CLASS->$method('1,7') };
+#      is( $@, "", 'Directly test comma as decimal compliance');
+
        my $ver = 1.23;  # has to be floating point number
+       my $orig_loc = setlocale( LC_ALL );
        my $loc;
        while (<DATA>) {
            chomp;
-           $loc = POSIX::setlocale( &POSIX::LC_ALL, $_);
-           last if POSIX::localeconv()->{decimal_point} eq ',';
+           $loc = setlocale( LC_ALL, $_);
+           last if localeconv()->{decimal_point} eq ',';
        }
        skip 'Cannot test locale handling without a comma locale', 4
            unless ( $loc and ($ver eq '1,23') );
 
-       diag ("Testing locale handling with $loc") if $Verbose;
+       diag ("Testing locale handling with $loc") unless $ENV{PERL_CORE};
 
-       my $v = $CLASS->new($ver);
-       unlike($warning,qr/Version string '1,23' contains invalid data/,
+       $v = $CLASS->$method($ver);
+       unlike($warning, qr/Version string '1,23' contains invalid data/,
            "Process locale-dependent floating point");
-       is ($v, "1.230", "Locale doesn't apply to version objects");
+       is ($v, "1.23", "Locale doesn't apply to version objects");
        ok ($v == $ver, "Comparison to locale floating point");
+
+       setlocale( LC_ALL, $orig_loc); # reset this before possible skip
+       skip 'Cannot test RT#46921 with Perl < 5.008', 1
+           if ($] < 5.008);
+       skip 'Cannot test RT#46921 with pure Perl module', 1
+           if exists $INC{'version/vpp.pm'};
+       my ($fh, $filename) = tempfile('tXXXXXXX', SUFFIX => '.pm', UNLINK => 1);
+       (my $package = basename($filename)) =~ s/\.pm$//;
+       print $fh <<"EOF";
+package $package;
+use POSIX qw(locale_h);
+\$^W = 1;
+use $CLASS;
+setlocale (LC_ALL, '$loc');
+use $CLASS ;
+eval "use Socket 1.7";
+setlocale( LC_ALL, '$orig_loc');
+1;
+EOF
+       close $fh;
+
+       eval "use lib '.'; use $package;";
+       unlike($warning, qr"Version string '1,7' contains invalid data",
+           'Handle locale action-at-a-distance');
+    }
+
+    eval 'my $v = $CLASS->$method("1._1");';
+    unlike($@, qr/^Invalid version format \(alpha with zero width\)/,
+       "Invalid version format 1._1");
+
+    {
+       my $warning;
+       local $SIG{__WARN__} = sub { $warning = $_[0] };
+       eval 'my $v = $CLASS->$method(~0);';
+       unlike($@, qr/Integer overflow in version/, "Too large version");
+       like($warning, qr/Integer overflow in version/, "Too large version");
+    }
+
+    {
+       # http://rt.cpan.org/Public/Bug/Display.html?id=30004
+       my $v1 = $CLASS->$method("v0.1_1");
+       (my $alpha1 = Dumper($v1)) =~ s/.+'alpha' => ([^,]+),.+/$1/ms;
+       my $v2 = $CLASS->$method($v1);
+       (my $alpha2 = Dumper($v2)) =~ s/.+'alpha' => ([^,]+),.+/$1/ms;
+       is $alpha2, $alpha1, "Don't fall for Data::Dumper's tricks";
+    }
+
+    {
+       # http://rt.perl.org/rt3/Ticket/Display.html?id=56606
+       my $badv = bless { version => [1,2,3] }, "version";
+       is $badv, '1.002003', "Deal with badly serialized versions from YAML";  
+       my $badv2 = bless { qv => 1, version => [1,2,3] }, "version";
+       is $badv2, 'v1.2.3', "Deal with badly serialized versions from YAML ";  
+    }
+SKIP: {
+       if ( $] < 5.006_000 ) {
+           skip 'No v-string support at all < 5.6.0', 2; 
+       }
+       # https://rt.cpan.org/Ticket/Display.html?id=49348
+       my $v = $CLASS->$method("420");
+       is "$v", "420", 'Correctly guesses this is not a v-string';
+       $v = $CLASS->$method(4.2.0);
+       is "$v", 'v4.2.0', 'Correctly guess that this is a v-string';
+    }
+SKIP: {
+       if ( $] < 5.006_000 ) {
+           skip 'No v-string support at all < 5.6.0', 4; 
+       }
+       # https://rt.cpan.org/Ticket/Display.html?id=50347
+       # Check that the qv() implementation does not change
+
+       ok $CLASS->$method(1.2.3) < $CLASS->$method(1.2.3.1), 'Compare 3 and 4 digit v-strings' ;
+       ok $CLASS->$method(v1.2.3) < $CLASS->$method(v1.2.3.1), 'Compare 3 and 4 digit v-strings, leaving v';
+       ok $CLASS->$method("1.2.3") < $CLASS->$method("1.2.3.1"), 'Compare 3 and 4 digit v-strings, quoted';
+       ok $CLASS->$method("v1.2.3") < $CLASS->$method("v1.2.3.1"), 'Compare 3 and 4 digit v-strings, quoted leading v';
     }
 }