diff options
author | Nicholas Clark <nick@ccl4.org> | 2009-09-26 14:52:33 +0100 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2009-09-26 14:52:33 +0100 |
commit | b2f35940bb67ef1897a3424ba54bae0f74434d8e (patch) | |
tree | 7ed3fe4101000c53c9f1baef9dbce1a603369b70 /cpan/Module-Load-Conditional/t | |
parent | 1ac05d83359ab0b4e03b39df1d104eb71a8437cf (diff) | |
download | perl-b2f35940bb67ef1897a3424ba54bae0f74434d8e.tar.gz |
Move Module::Load::Conditional from ext/ to cpan/
Diffstat (limited to 'cpan/Module-Load-Conditional/t')
8 files changed, 355 insertions, 0 deletions
diff --git a/cpan/Module-Load-Conditional/t/01_Module_Load_Conditional.t b/cpan/Module-Load-Conditional/t/01_Module_Load_Conditional.t new file mode 100644 index 0000000000..b5d78c7a5d --- /dev/null +++ b/cpan/Module-Load-Conditional/t/01_Module_Load_Conditional.t @@ -0,0 +1,233 @@ +### Module::Load::Conditional test suite ### +### this should no longer be needed +# BEGIN { +# if( $ENV{PERL_CORE} ) { +# chdir '../lib/Module/Load/Conditional' +# if -d '../lib/Module/Load/Conditional'; +# unshift @INC, '../../../..'; +# +# ### fix perl location too +# $^X = '../../../../../t/' . $^X; +# } +# } + +BEGIN { use FindBin; } +BEGIN { chdir 't' if -d 't' } + +use strict; +use File::Spec (); +use Test::More 'no_plan'; + +use constant ON_VMS => $^O eq 'VMS'; + +use lib File::Spec->catdir($FindBin::Bin, qw[.. lib] ); +use lib File::Spec->catdir($FindBin::Bin, q[to_load] ); + +use_ok( 'Module::Load::Conditional' ); + +### stupid stupid warnings ### +{ $Module::Load::Conditional::VERBOSE = + $Module::Load::Conditional::VERBOSE = 0; + + *can_load = *Module::Load::Conditional::can_load + = *Module::Load::Conditional::can_load; + *check_install = *Module::Load::Conditional::check_install + = *Module::Load::Conditional::check_install; + *requires = *Module::Load::Conditional::requires + = *Module::Load::Conditional::requires; +} + +{ + my $rv = check_install( + module => 'Module::Load::Conditional', + version => $Module::Load::Conditional::VERSION, + ); + + ok( $rv->{uptodate}, q[Verify self] ); + is( $rv->{version}, $Module::Load::Conditional::VERSION, + q[ Found proper version] ); + ok( $rv->{dir}, q[ Found directory information] ); + + { my $dir = File::Spec->canonpath( $rv->{dir} ); + + ### special rules apply on VMS, as always... + if (ON_VMS) { + ### Need path syntax for VMS compares. + $dir = VMS::Filespec::pathify($dir); + ### Remove the trailing VMS specific directory delimiter + $dir =~ s/\]//; + } + + ### quote for Win32 paths, use | to avoid slash confusion + my $dir_re = qr|^\Q$dir\E|i; + like( File::Spec->canonpath( $rv->{file} ), $dir_re, + q[ Dir subset of file path] ); + } + + ### break up the specification + my @rv_path = do { + + ### Use the UNIX specific method, as the VMS one currently + ### converts the file spec back to VMS format. + my $class = ON_VMS ? 'File::Spec::Unix' : 'File::Spec'; + + my($vol, $path, $file) = $class->splitpath( $rv->{'file'} ); + + my @path = ($vol, $class->splitdir( $path ), $file ); + + ### First element could be blank for some system types like VMS + shift @path if $vol eq ''; + + ### and return it + @path; + }; + my $inc_path = $INC{'Module/Load/Conditional.pm'}; + if ( $^O eq 'MSWin32' ) { + $inc_path = File::Spec->canonpath( $inc_path ); + $inc_path =~ s{\\}{/}g; # to meet with unix path + } + is( $inc_path, + File::Spec::Unix->catfile(@rv_path), + q[ Found proper file] + ); + + + +} + +### the version may contain an _, which means perl will warn about 'not +### numeric' -- turn off that warning here. +{ local $^W; + my $rv = check_install( + module => 'Module::Load::Conditional', + version => $Module::Load::Conditional::VERSION + 1, + ); + + ok( !$rv->{uptodate} && $rv->{version} && $rv->{file}, + q[Verify out of date module] + ); +} + +{ + my $rv = check_install( module => 'Module::Load::Conditional' ); + + ok( $rv->{uptodate} && $rv->{version} && $rv->{file}, + q[Verify any module] + ); +} + +{ + my $rv = check_install( module => 'Module::Does::Not::Exist' ); + + ok( !$rv->{uptodate} && !$rv->{version} && !$rv->{file}, + q[Verify non-existant module] + ); + +} + +### test finding a version of a module that mentions $VERSION in pod +{ my $rv = check_install( module => 'InPod' ); + ok( $rv, 'Testing $VERSION in POD' ); + ok( $rv->{version}, " Version found" ); + is( $rv->{version}, 2, " Version is correct" ); +} + +### test beta/developer release versions +{ my $test_ver = $Module::Load::Conditional::VERSION; + + ### strip beta tags + $test_ver =~ s/_\d+//g; + $test_ver .= '_99'; + + my $rv = check_install( + module => 'Module::Load::Conditional', + version => $test_ver, + ); + + ok( $rv, "Checking beta versions" ); + ok( !$rv->{'uptodate'}, " Beta version is higher" ); + +} + +### test $FIND_VERSION +{ local $Module::Load::Conditional::FIND_VERSION = 0; + local $Module::Load::Conditional::FIND_VERSION = 0; + + my $rv = check_install( module => 'Module::Load::Conditional' ); + + ok( $rv, 'Testing $FIND_VERSION' ); + is( $rv->{version}, undef, " No version info returned" ); + ok( $rv->{uptodate}, " Module marked as uptodate" ); +} + +### test 'can_load' ### + +{ + my $use_list = { 'LoadIt' => 1 }; + my $bool = can_load( modules => $use_list ); + + ok( $bool, q[Load simple module] ); +} + +{ + my $use_list = { 'Commented' => 2 }; + my $bool = can_load( modules => $use_list ); + + ok( $bool, q[Load module with a second, commented-out $VERSION] ); +} + +{ + my $use_list = { 'MustBe::Loaded' => 1 }; + my $bool = can_load( modules => $use_list ); + + ok( !$bool, q[Detect out of date module] ); +} + +{ + delete $INC{'LoadIt.pm'}; + delete $INC{'MustBe/Loaded.pm'}; + + my $use_list = { 'LoadIt' => 1, 'MustBe::Loaded' => 1 }; + my $bool = can_load( modules => $use_list ); + + ok( !$INC{'LoadIt.pm'} && !$INC{'MustBe/Loaded.pm'}, + q[Do not load if one prerequisite fails] + ); +} + + +### test 'requires' ### +SKIP:{ + skip "Depends on \$^X, which doesn't work well when testing the Perl core", + 1 if $ENV{PERL_CORE}; + + my %list = map { $_ => 1 } requires('Carp'); + + my $flag; + $flag++ unless delete $list{'Exporter'}; + + ok( !$flag, q[Detecting requirements] ); +} + +### test using the %INC lookup for check_install +{ local $Module::Load::Conditional::CHECK_INC_HASH = 1; + local $Module::Load::Conditional::CHECK_INC_HASH = 1; + + { package A::B::C::D; + $A::B::C::D::VERSION = $$; + $INC{'A/B/C/D.pm'} = $$.$$; + + ### XXX this is no longer needed with M::Load 0.11_01 + #$INC{'[.A.B.C]D.pm'} = $$.$$ if $^O eq 'VMS'; + } + + my $href = check_install( module => 'A::B::C::D', version => 0 ); + + ok( $href, 'Found package in %INC' ); + is( $href->{'file'}, $$.$$, ' Found correct file' ); + is( $href->{'version'}, $$, ' Found correct version' ); + ok( $href->{'uptodate'}, ' Marked as uptodate' ); + ok( can_load( modules => { 'A::B::C::D' => 0 } ), + ' can_load successful' ); +} + diff --git a/cpan/Module-Load-Conditional/t/02_Parse_Version.t b/cpan/Module-Load-Conditional/t/02_Parse_Version.t new file mode 100644 index 0000000000..dd29c67657 --- /dev/null +++ b/cpan/Module-Load-Conditional/t/02_Parse_Version.t @@ -0,0 +1,99 @@ +BEGIN { chdir 't' if -d 't' } + +use strict; +use lib qw[../lib]; +use Test::More 'no_plan'; + +my $Class = 'Module::Load::Conditional'; +my $Meth = '_parse_version'; +my $Verbose = @ARGV ? 1 : 0; + +use_ok( $Class ); + +### versions that should parse +{ for my $str ( __PACKAGE__->_succeed ) { + my $res = $Class->$Meth( $str, $Verbose ); + ok( defined $res, "String '$str' identified as version string" ); + + ### XXX version.pm 0.69 pure perl fails tests under 5.6.2. + ### XXX version.pm <= 0.69 do not have a complete overload + ### implementation, which causes the following error: + ### $ perl -Mversion -le'qv(1)+0' + ### Operation "+": no method found, + ### left argument in overloaded package version, + ### right argument has no overloaded magic at -e line 1 + ### so we do the comparison ourselves, and then feed it to + ### the Test::More::ok(). + ### + ### Mailed jpeacock and p5p about both issues on 25-1-2007: + ### http://xrl.us/uem7 + ### (http://www.xray.mpe.mpg.de/mailing-lists/ + ### perl5-porters/2007-01/msg00805.html) + + ### Quell "Argument isn't numeric in gt" warnings... + my $bool = do { local $^W; $res > 0 }; + + ok( $bool, " Version is '$res'" ); + isnt( $res, '0.0', " Not the default value" ); + } +} + +### version that should fail +{ for my $str ( __PACKAGE__->_fail ) { + my $res = $Class->$Meth( $str, $Verbose ); + ok( ! defined $res, "String '$str' is not a version string" ); + } +} + + +################################ +### +### VERSION declarations to test +### +################################ + +sub _succeed { + return grep { /\S/ } map { s/^\s*//; $_ } split "\n", q[ + $VERSION = 1; + *VERSION = \'1.01'; + use version; $VERSION = qv('0.0.2'); + use version; $VERSION = qv('3.0.14'); + ($VERSION) = '$Revision: 2.03 $' =~ /\s(\d+\.\d+)\s/; + ( $VERSION ) = sprintf "%d.%02d", q$Revision: 1.23 $ =~ m/ (\d+) \. (\d+) /gx; + ($GD::Graph::area::VERSION) = '$Revision: 1.16.2.3 $' =~ /\s([\d.]+)/; + ($GD::Graph::axestype::VERSION) = '$Revision: 1.44.2.14 $' =~ /\s([\d.]+)/; + ($GD::Graph::colour::VERSION) = '$Revision: 1.10 $' =~ /\s([\d.]+)/; + ($GD::Graph::pie::VERSION) = '$Revision: 1.20.2.4 $' =~ /\s([\d.]+)/; + ($GD::Text::Align::VERSION) = '$Revision: 1.18 $' =~ /\s([\d.]+)/; + $VERSION = qv('0.0.1'); + use version; $VERSION = qv('0.0.3'); + $VERSION = do { my @r = ( ( $v = q<Version value="0.20.1"> ) =~ /\d+/g ); sprintf "%d.%02d", $r[0], int( $r[1] / 10 ) }; + ($VERSION) = sprintf '%i.%03i', split(/\./,('$Revision: 2.0 $' =~ /Revision: (\S+)\s/)[0]); # $Date: 2005/11/16 02:16:00 $ + ( $VERSION = q($Id: Tidy.pm,v 1.56 2006/07/19 23:13:33 perltidy Exp $) ) =~ s/^.*\s+(\d+)\/(\d+)\/(\d+).*$/$1$2$3/; # all one line for MakeMaker + ($VERSION) = q $Revision: 2.120 $ =~ /([\d.]+)/; + ($VERSION) = q$Revision: 1.00 $ =~ /([\d.]+)/; + $VERSION = "3.0.8"; + $VERSION = '1.0.5'; + ]; +} + +sub _fail { + return grep { /\S/ } map { s/^\s*//; $_ } split "\n", q[ + use vars qw($VERSION $AUTOLOAD %ERROR $ERROR $Warn $Die); + sub version { $GD::Graph::colour::VERSION } + my $VERS = qr{ $HWS VERSION $HWS \n }xms; + diag( "Testing $main_module \$${main_module}::VERSION" ); + our ( $VERSION, $v, $_VERSION ); + my $seen = { q{::} => { 'VERSION' => 1 } }; # avoid multiple scans + eval "$module->VERSION" + 'VERSION' => '1.030' # Variable and Value + 'VERSION' => '2.121_020' + 'VERSION' => '0.050', # Standard variable $VERSION + use vars qw( $VERSION $seq @FontDirs ); + $VERSION + # *VERSION = \'1.01'; + # ( $VERSION ) = '$Revision: 1.56 $ ' =~ /\$Revision:\s+([^\s]+)/; + #$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: $ =~ /-(\d+)_([\d_]+)/); + #$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: $ =~ /-(\d+)_([\d_]+)/); + ]; +} diff --git a/cpan/Module-Load-Conditional/t/to_load/Commented.pm b/cpan/Module-Load-Conditional/t/to_load/Commented.pm new file mode 100644 index 0000000000..1e3e057f33 --- /dev/null +++ b/cpan/Module-Load-Conditional/t/to_load/Commented.pm @@ -0,0 +1,4 @@ +# $VERSION = 1;
+$VERSION = 2;
+
+1;
diff --git a/cpan/Module-Load-Conditional/t/to_load/InPod.pm b/cpan/Module-Load-Conditional/t/to_load/InPod.pm new file mode 100644 index 0000000000..0d4c39b60c --- /dev/null +++ b/cpan/Module-Load-Conditional/t/to_load/InPod.pm @@ -0,0 +1,11 @@ +=pod + +$VERSION = 1; + +=cut + +package InPod; + +$VERSION = 2; + +1; diff --git a/cpan/Module-Load-Conditional/t/to_load/LoadIt.pm b/cpan/Module-Load-Conditional/t/to_load/LoadIt.pm new file mode 100644 index 0000000000..b97123dac7 --- /dev/null +++ b/cpan/Module-Load-Conditional/t/to_load/LoadIt.pm @@ -0,0 +1,3 @@ +$VERSION = 1;
+
+1;
\ No newline at end of file diff --git a/cpan/Module-Load-Conditional/t/to_load/LoadMe.pl b/cpan/Module-Load-Conditional/t/to_load/LoadMe.pl new file mode 100644 index 0000000000..6912615643 --- /dev/null +++ b/cpan/Module-Load-Conditional/t/to_load/LoadMe.pl @@ -0,0 +1 @@ +1;
\ No newline at end of file diff --git a/cpan/Module-Load-Conditional/t/to_load/MustBe/Loaded.pm b/cpan/Module-Load-Conditional/t/to_load/MustBe/Loaded.pm new file mode 100644 index 0000000000..e1af010dc8 --- /dev/null +++ b/cpan/Module-Load-Conditional/t/to_load/MustBe/Loaded.pm @@ -0,0 +1,3 @@ +$VERSION = 0.01;
+
+1;
\ No newline at end of file diff --git a/cpan/Module-Load-Conditional/t/to_load/ToBeLoaded b/cpan/Module-Load-Conditional/t/to_load/ToBeLoaded new file mode 100644 index 0000000000..6912615643 --- /dev/null +++ b/cpan/Module-Load-Conditional/t/to_load/ToBeLoaded @@ -0,0 +1 @@ +1;
\ No newline at end of file |