perlunifaq, uniintro: fix for 80 col display
[p5sagit/p5-mst-13.2.git] / cpan / Module-Load-Conditional / t / 02_Parse_Version.t
1 BEGIN { chdir 't' if -d 't' }
2
3 use strict;
4 use lib         qw[../lib];
5 use Test::More  'no_plan';
6
7 my $Class   = 'Module::Load::Conditional';
8 my $Meth    = '_parse_version';
9 my $Verbose = @ARGV ? 1 : 0;
10
11 use_ok( $Class );
12
13 ### versions that should parse
14 {   for my $str ( __PACKAGE__->_succeed ) {
15         my $res = $Class->$Meth( $str, $Verbose );
16         ok( defined $res,       "String '$str' identified as version string" );
17         
18         ### XXX version.pm 0.69 pure perl fails tests under 5.6.2.
19         ### XXX version.pm <= 0.69 do not have a complete overload 
20         ### implementation, which causes the following error:
21         ### $ perl -Mversion -le'qv(1)+0'
22         ### Operation "+": no method found,
23         ###        left argument in overloaded package version,
24         ###        right argument has no overloaded magic at -e line 1
25         ### so we do the comparison ourselves, and then feed it to
26         ### the Test::More::ok().
27         ###
28         ### Mailed jpeacock and p5p about both issues on 25-1-2007:
29         ###     http://xrl.us/uem7
30         ###     (http://www.xray.mpe.mpg.de/mailing-lists/
31         ###         perl5-porters/2007-01/msg00805.html)
32
33         ### Quell "Argument isn't numeric in gt" warnings...
34         my $bool = do { local $^W; $res > 0 };
35         
36         ok( $bool,              "   Version is '$res'" );
37         isnt( $res, '0.0',      "   Not the default value" );
38     }             
39 }
40
41 ### version that should fail
42 {   for my $str ( __PACKAGE__->_fail ) {
43         my $res = $Class->$Meth( $str, $Verbose );
44         ok( ! defined $res,     "String '$str' is not a version string" );
45     }
46 }    
47
48
49 ################################
50 ###
51 ### VERSION declarations to test
52 ###
53 ################################
54
55 sub _succeed {
56     return grep { /\S/ } map { s/^\s*//; $_ } split "\n", q[
57         $VERSION = 1;
58         *VERSION = \'1.01';
59         use version; $VERSION = qv('0.0.2');
60         use version; $VERSION = qv('3.0.14');
61         ($VERSION) = '$Revision: 2.03 $' =~ /\s(\d+\.\d+)\s/; 
62         ( $VERSION ) = sprintf "%d.%02d", q$Revision: 1.23 $ =~ m/ (\d+) \. (\d+) /gx;
63         ($GD::Graph::area::VERSION) = '$Revision: 1.16.2.3 $' =~ /\s([\d.]+)/;
64         ($GD::Graph::axestype::VERSION) = '$Revision: 1.44.2.14 $' =~ /\s([\d.]+)/;
65         ($GD::Graph::colour::VERSION) = '$Revision: 1.10 $' =~ /\s([\d.]+)/;
66         ($GD::Graph::pie::VERSION) = '$Revision: 1.20.2.4 $' =~ /\s([\d.]+)/;
67         ($GD::Text::Align::VERSION) = '$Revision: 1.18 $' =~ /\s([\d.]+)/;
68         $VERSION = qv('0.0.1');
69         use version; $VERSION = qv('0.0.3');
70         $VERSION = do { my @r = ( ( $v = q<Version value="0.20.1"> ) =~ /\d+/g ); sprintf "%d.%02d", $r[0], int( $r[1] / 10 ) };
71         ($VERSION) = sprintf '%i.%03i', split(/\./,('$Revision: 2.0 $' =~ /Revision: (\S+)\s/)[0]); # $Date: 2005/11/16 02:16:00 $
72         ( $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
73         ($VERSION) = q $Revision: 2.120 $ =~ /([\d.]+)/;
74         ($VERSION) = q$Revision: 1.00 $ =~ /([\d.]+)/;
75         $VERSION = "3.0.8";
76         $VERSION = '1.0.5';
77     ];
78 }
79
80 sub _fail {
81     return grep { /\S/ } map { s/^\s*//; $_ } split "\n", q[
82         use vars qw($VERSION $AUTOLOAD %ERROR $ERROR $Warn $Die);
83         sub version { $GD::Graph::colour::VERSION }
84         my $VERS = qr{ $HWS VERSION $HWS \n }xms;
85         diag( "Testing $main_module \$${main_module}::VERSION" );
86         our ( $VERSION, $v, $_VERSION );
87         my $seen = { q{::} => { 'VERSION' => 1 } }; # avoid multiple scans
88         eval "$module->VERSION"
89         'VERSION' => '1.030' # Variable and Value
90         'VERSION' => '2.121_020'
91         'VERSION' => '0.050', # Standard variable $VERSION
92         use vars qw( $VERSION $seq @FontDirs );
93         $VERSION
94         # *VERSION = \'1.01';
95         # ( $VERSION ) = '$Revision: 1.56 $ ' =~ /\$Revision:\s+([^\s]+)/;
96         #$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: $ =~ /-(\d+)_([\d_]+)/);
97         #$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: $ =~ /-(\d+)_([\d_]+)/);
98     ];
99 }