From: Rafael Garcia-Suarez Date: Thu, 10 Aug 2006 08:14:46 +0000 (+0000) Subject: Upgrade to version.pm 0.67 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=317f7c8a941b7bf35ae65f6c2b1ed46e040c4441;p=p5sagit%2Fp5-mst-13.2.git Upgrade to version.pm 0.67 p4raw-id: //depot/perl@28687 --- diff --git a/lib/version.pm b/lib/version.pm index 74313c3..703c163 100644 --- a/lib/version.pm +++ b/lib/version.pm @@ -6,13 +6,13 @@ use strict; use vars qw(@ISA $VERSION $CLASS *qv); -$VERSION = 0.64; +$VERSION = 0.67; $CLASS = 'version'; # Preloaded methods go here. sub import { - my ($class, @args) = @_; + my ($class) = @_; my $callpkg = caller(); no strict 'refs'; diff --git a/lib/version.pod b/lib/version.pod index 0f4f20d..6874fa2 100644 --- a/lib/version.pod +++ b/lib/version.pod @@ -21,7 +21,7 @@ version - Perl extension for Version Objects =head1 DESCRIPTION -Overloaded version objects for all versions of Perl. This module +Overloaded version objects for all modern versions of Perl. This module implements all of the features of version objects which will be part of Perl 5.10.0. @@ -74,6 +74,54 @@ and it should Just Work(TM). Module::Build will [hopefully soon] include full support for version objects; there are no current plans to patch ExtUtils::MakeMaker to support version objects. +=back + +=head2 Using modules that use version.pm + +As much as possible, the version.pm module remains compatible with all +current code. However, if your module is using a module that has defined +C<$VERSION> using the version class, there are a couple of things to be +aware of. For purposes of discussion, we will assume that we have the +following module installed: + + package Example; + use version; $VERSION = qv('1.2.2'); + ...module code here... + 1; + +=over 4 + +=item Numeric versions always work + +Code of the form: + + use Example 1.002003; + +will always work correctly. The C will perform an automatic +C<$VERSION> comparison using the floating point number given as the first +term after the module name (e.g. above 1.002.003). In this case, the +installed module is too old for the requested line, so you would see an +error like: + + Example version 1.002003 (v1.2.3) required--this is only version 1.002002 (v1.2.2)... + +=item Extended version work sometimes + +With Perl >= 5.6.2, you can also use a line like this: + + use Example 1.2.3; + +and it will again work (i.e. give the error message as above), even with +releases of Perl which do not normally support v-strings (see L below). This has to do with that fact that C only checks +to see if the second term I and passes that to the +replacement L. This is not true in Perl 5.005_04, +however, so you are B to always use a numeric version +in your code, even for those versions of Perl which support the extended +version. + +=back + =head2 What IS a version For the purposes of this module, a version "number" is a sequence of diff --git a/lib/version.t b/lib/version.t index c9da642..cc2fde7 100644 --- a/lib/version.t +++ b/lib/version.t @@ -65,416 +65,424 @@ unlike ($@, qr/^Subroutine main::qv redefined/, sub BaseTests { - my ($CLASS, $no_qv) = @_; - - # 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"' ); - - # 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"' ); - - # Test stringify operator - diag "tests with stringify" if $Verbose; - $version = $CLASS->new("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"); - 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")}; - like($@, qr/multiple underscores/, - "Invalid version format (multiple underscores)"); - - eval {my $version = $CLASS->new("1.2_3.4")}; - like($@, qr/underscores before decimal/, - "Invalid version format (underscores before decimal)"); - - 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 - $version = $CLASS->new("1.2.3"); - - # Test boolean operator - ok ($version, 'boolean'); - - # Test class membership - 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' ); - 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 - $new_version = "5.8.0"; - diag "numeric tests with non-objects" if $Verbose; - 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; - 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; - 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"'); - 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'); - ok ( $version->numify == 2002.009030001, - '$version->numify == 2002.009030001'); - - # now test with alpha version form with string - $version = $CLASS->new("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' ); - - $version = $CLASS->new("1.2.4"); - diag "numeric tests with alpha-style non-objects" - if $Verbose; - 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; - 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; - 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"); - diag "tests with alpha-style objects with same subversion" - if $Verbose; - 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"); - ok ( $version == $new_version, '$version == $new_version' ); - $new_version = $CLASS->new("1.2.3_0"); - ok ( $version == $new_version, '$version == $new_version' ); - $new_version = $CLASS->new("1.2.3.1"); - ok ( $version < $new_version, '$version < $new_version' ); - $new_version = $CLASS->new("1.2.3_1"); - ok ( $version < $new_version, '$version < $new_version' ); - $new_version = $CLASS->new("1.1.999"); - ok ( $version > $new_version, '$version > $new_version' ); - - # that which is not expressly permitted is forbidden - diag "forbidden operations" if $Verbose; - ok ( !eval { ++$version }, "noop ++" ); - ok ( !eval { --$version }, "noop --" ); - ok ( !eval { $version/1 }, "noop /" ); - ok ( !eval { $version*3 }, "noop *" ); - ok ( !eval { abs($version) }, "noop abs" ); + my ($CLASS, $no_qv) = @_; + + # 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"' ); + + # 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"' ); + + # Test stringify operator + diag "tests with stringify" if $Verbose; + $version = $CLASS->new("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"); + 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")}; + like($@, qr/multiple underscores/, + "Invalid version format (multiple underscores)"); + + eval {my $version = $CLASS->new("1.2_3.4")}; + like($@, qr/underscores before decimal/, + "Invalid version format (underscores before decimal)"); + + 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 + $version = $CLASS->new("1.2.3"); + + # Test boolean operator + ok ($version, 'boolean'); + + # Test class membership + 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' ); + 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 + $new_version = "5.8.0"; + diag "numeric tests with non-objects" if $Verbose; + 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; + 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; + 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"'); + 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'); + ok ( $version->numify == 2002.009030001, + '$version->numify == 2002.009030001'); + + # now test with alpha version form with string + $version = $CLASS->new("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' ); + + $version = $CLASS->new("1.2.4"); + diag "numeric tests with alpha-style non-objects" + if $Verbose; + 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; + 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; + 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"); + diag "tests with alpha-style objects with same subversion" + if $Verbose; + 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"); + ok ( $version == $new_version, '$version == $new_version' ); + $new_version = $CLASS->new("1.2.3_0"); + ok ( $version == $new_version, '$version == $new_version' ); + $new_version = $CLASS->new("1.2.3.1"); + ok ( $version < $new_version, '$version < $new_version' ); + $new_version = $CLASS->new("1.2.3_1"); + ok ( $version < $new_version, '$version < $new_version' ); + $new_version = $CLASS->new("1.1.999"); + ok ( $version > $new_version, '$version > $new_version' ); + + # that which is not expressly permitted is forbidden + diag "forbidden operations" if $Verbose; + ok ( !eval { ++$version }, "noop ++" ); + ok ( !eval { --$version }, "noop --" ); + ok ( !eval { $version/1 }, "noop /" ); + ok ( !eval { $version*3 }, "noop *" ); + 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", 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 ); } - # test creation from existing version object - diag "create new from existing version" if $Verbose; - ok (eval {$new_version = $CLASS->new($version)}, - "new from existing object"); - ok ($new_version == $version, "class->new($version) identical"); - $new_version = $version->new(); - 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'); - - # test the CVS revision mode - diag "testing CVS Revision" if $Verbose; - $version = new $CLASS qw$Revision: 1.2$; - ok ( $version eq "1.2.0", 'qw$Revision: 1.2$ eq 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' ); - - # 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" ); - 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'); - - $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'); - - $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'); - - { # 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; - if ( $] < 5.008 ) { - $error_regex = 'xxx does not define \$xxx::VERSION'; - } - else { - $error_regex = 'xxx defines neither package nor 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"; - unlike ($@, qr/$error_regex/, - 'Replacement handles modules without package or VERSION'); - is ($versiona, undef, "Called as class method"); - unlink 'xxx.pm'; - } + # test creation from existing version object + diag "create new from existing version" if $Verbose; + ok (eval {$new_version = $CLASS->new($version)}, + "new from existing object"); + ok ($new_version == $version, "class->new($version) identical"); + $new_version = $version->new(); + 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'); + + # test the CVS revision mode + diag "testing CVS Revision" if $Verbose; + $version = new $CLASS qw$Revision: 1.2$; + ok ( $version eq "1.2.0", 'qw$Revision: 1.2$ eq 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' ); + + # 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" ); + 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'); - { # 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/, - 'Replacement handles modules without VERSION'); - eval "use lib '.'; use yyy; print yyy->VERSION"; - unlike ($@, qr/^yyy does not define \$yyy::VERSION/, - 'Replacement handles modules without VERSION'); - unlink 'yyy.pm'; + # 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'); + + $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'); + + $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'); + + { # 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; + if ( $] < 5.008 ) { + $error_regex = 'xxx does not define \$xxx::VERSION'; } - - { # 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/, - 'Replacement handles modules without VERSION'); - eval "use lib '.'; use zzz; print zzz->VERSION"; - unlike ($@, qr/^zzz does not define \$zzz::VERSION/, - 'Replacement handles modules without VERSION'); - unlink 'zzz.pm'; + else { + $error_regex = 'xxx defines neither package nor 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"; + unlike ($@, qr/$error_regex/, + 'Replacement handles modules without package or VERSION'); + ok (defined($version), "Called as class method"); + unlink 'xxx.pm'; + } + + { # 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/, + 'Replacement handles modules without VERSION'); + eval "use lib '.'; use yyy; print yyy->VERSION"; + unlike ($@, qr/^yyy does not define \$yyy::VERSION/, + 'Replacement handles modules without VERSION'); + unlink 'yyy.pm'; + } + + { # 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/, + 'Replacement handles modules without VERSION'); + eval "use lib '.'; use zzz; print zzz->VERSION"; + unlike ($@, qr/^zzz does not define \$zzz::VERSION/, + 'Replacement handles modules without VERSION'); + unlink 'zzz.pm'; + } + 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); - ok("$version" eq "v1.2.3", '"$version" eq 1.2.3'); - $version = $CLASS->new(1.0.0); - $new_version = $CLASS->new(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 '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); + ok("$version" eq "v1.2.3", '"$version" eq 1.2.3'); + $version = $CLASS->new(1.0.0); + $new_version = $CLASS->new(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()'); + } + + diag "Tests with real-world (malformed) data" if $Verbose; + + # trailing zero testing (reported by Andreas Koenig). + $version = $CLASS->new("1"); + ok($version->numify eq "1.000", "trailing zeros preserved"); + $version = $CLASS->new("1.0"); + ok($version->numify eq "1.000", "trailing zeros preserved"); + $version = $CLASS->new("1.0.0"); + ok($version->numify eq "1.000000", "trailing zeros preserved"); + $version = $CLASS->new("1.0.0.0"); + ok($version->numify eq "1.000000000", "trailing zeros preserved"); + + # leading zero testing (reported by Andreas Koenig). + $version = $CLASS->new(".7"); + ok($version->numify eq "0.700", "leading zero inferred"); + + # leading space testing (reported by Andreas Koenig). + $version = $CLASS->new(" 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'); + unlike($warning, qr/^Version string 'undef' contains invalid data/, + "Version string 'undef'"); + + $version = $CLASS->new(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 + 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"); + + $version = $CLASS->new(0.000001); + unlike($warning, qr/^Version string '1e-06' contains invalid data/, + "Very small version objects"); - diag "Tests with real-world (malformed) data" if $Verbose; - - # trailing zero testing (reported by Andreas Koenig). - $version = $CLASS->new("1"); - ok($version->numify eq "1.000", "trailing zeros preserved"); - $version = $CLASS->new("1.0"); - ok($version->numify eq "1.000", "trailing zeros preserved"); - $version = $CLASS->new("1.0.0"); - ok($version->numify eq "1.000000", "trailing zeros preserved"); - $version = $CLASS->new("1.0.0.0"); - ok($version->numify eq "1.000000000", "trailing zeros preserved"); - - # leading zero testing (reported by Andreas Koenig). - $version = $CLASS->new(".7"); - ok($version->numify eq "0.700", "leading zero inferred"); - - # leading space testing (reported by Andreas Koenig). - $version = $CLASS->new(" 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'); - unlike($warning, qr/^Version string 'undef' contains invalid data/, - "Version string 'undef'"); - - $version = $CLASS->new(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 - 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"); - -SKIP: { - - # dummy up a legal module for testing RT#19017 - open F, ">www.pm" or die "Cannot open www.pm: $!\n"; - print F <<"EOF"; +SKIP: { + # 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'); 1; EOF - close F; - - eval "use lib '.'; use www 0.000008;"; - like ($@, qr/^www version 0.000008 \(v0.0.8\) 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/, - "Comparing vs. version with no decimal"); - eval "use lib '.'; use www 1.;"; - like ($@, qr/^www version 1.000 \(v1.0.0\) required/, - "Comparing "); - - skip 'Cannot "use" extended versions with Perl < 5.6.2', 1 - if $] < 5.006_002; - 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"); - - unlink 'www.pm'; - } - - open F, ">vvv.pm" or die "Cannot open vvv.pm: $!\n"; - print F <<"EOF"; + close F; + + eval "use lib '.'; use www 0.000008;"; + like ($@, qr/^www version 0.000008 \(v0.0.8\) 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/, + "Comparing vs. version with no decimal"); + eval "use lib '.'; use www 1.;"; + like ($@, qr/^www version 1.000 \(v1.0.0\) required/, + "Comparing vs. version with decimal only"); + + skip 'Cannot "use" extended versions with Perl < 5.6.2', 1 + if $] < 5.006_002; + 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'; + } + + open F, ">vvv.pm" or die "Cannot open vvv.pm: $!\n"; + print F <<"EOF"; package vvv; 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 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'; } 1;