82dee7de92a0bd35 failed to add ext/lib/Makefile.PL. Oops.
[p5sagit/p5-mst-13.2.git] / ext / ExtUtils-MakeMaker / t / parse_version.t
1 #!/usr/bin/perl -w
2
3 BEGIN {
4     unshift @INC, 't/lib';
5 }
6 chdir 't';
7
8 use Test::More;
9 use ExtUtils::MakeMaker;
10
11 my $Has_Version = eval 'require version; "version"->import; 1';
12
13 my %versions = (q[$VERSION = '1.00']            => '1.00',
14                 q[*VERSION = \'1.01']           => '1.01',
15                 q[($VERSION) = q$Revision: 32208 $ =~ /(\d+)/g;] => 32208,
16                 q[$FOO::VERSION = '1.10';]      => '1.10',
17                 q[*FOO::VERSION = \'1.11';]     => '1.11',
18                 '$VERSION = 0.02'               => 0.02,
19                 '$VERSION = 0.0'                => 0.0,
20                 '$VERSION = -1.0'               => -1.0,
21                 '$VERSION = undef'              => 'undef',
22                 '$wibble  = 1.0'                => 'undef',
23                 q[my $VERSION = '1.01']         => 'undef',
24                 q[local $VERISON = '1.02']      => 'undef',
25                 q[local $FOO::VERSION = '1.30'] => 'undef',
26                 q[if( $Foo::VERSION >= 3.00 ) {]=> 'undef',
27                 q[our $VERSION = '1.23';]       => '1.23',
28
29                 '$Something::VERSION == 1.0'    => 'undef',
30                 '$Something::VERSION <= 1.0'    => 'undef',
31                 '$Something::VERSION >= 1.0'    => 'undef',
32                 '$Something::VERSION != 1.0'    => 'undef',
33
34                 qq[\$Something::VERSION == 1.0\n\$VERSION = 2.3\n]                     => '2.3',
35                 qq[\$Something::VERSION == 1.0\n\$VERSION = 2.3\n\$VERSION = 4.5\n]    => '2.3',
36
37                 '$VERSION = sprintf("%d.%03d", q$Revision: 3.74 $ =~ /(\d+)\.(\d+)/);' => '3.074',
38                 '$VERSION = substr(q$Revision: 2.8 $, 10) + 2 . "";'                   => '4.8',
39                );
40
41 if( $Has_Version ) {
42     $versions{q[use version; $VERSION = qv("1.2.3");]} = qv("1.2.3");
43     $versions{q[$VERSION = qv("1.2.3")]}               = qv("1.2.3");
44 }
45
46 plan tests => (2 * keys %versions) + 4;
47
48 while( my($code, $expect) = each %versions ) {
49     is( parse_version_string($code), $expect, $code );
50 }
51
52
53 sub parse_version_string {
54     my $code = shift;
55
56     open(FILE, ">VERSION.tmp") || die $!;
57     print FILE "$code\n";
58     close FILE;
59
60     $_ = 'foo';
61     my $version = MM->parse_version('VERSION.tmp');
62     is( $_, 'foo', '$_ not leaked by parse_version' );
63     
64     unlink "VERSION.tmp";
65     
66     return $version;
67 }
68
69
70 # This is a specific test to see if a version subroutine in the $VERSION
71 # declaration confuses later calls to the version class.
72 # [rt.cpan.org 30747]
73 SKIP: {
74     skip "need version.pm", 4 unless $Has_Version;
75     is parse_version_string(q[ $VERSION = '1.00'; sub version { $VERSION } ]),
76        '1.00';
77     is parse_version_string(q[ use version; $VERSION = version->new("1.2.3") ]),
78        qv("1.2.3");
79 }