[perl #71000] Wrong variable name in warning
[p5sagit/p5-mst-13.2.git] / cpan / ExtUtils-MakeMaker / t / parse_version.t
CommitLineData
a7d1454b 1#!/usr/bin/perl -w
2
3BEGIN {
b78fd716 4 unshift @INC, 't/lib';
a7d1454b 5}
6chdir 't';
7
277189c8 8use Test::More;
a7d1454b 9use ExtUtils::MakeMaker;
10
e9f47f3b 11my $Has_Version = eval 'require version; "version"->import; 1';
c8d65f10 12
e9f47f3b 13my %versions = (q[$VERSION = '1.00'] => '1.00',
14 q[*VERSION = \'1.01'] => '1.01',
277189c8 15 q[($VERSION) = q$Revision: 32208 $ =~ /(\d+)/g;] => 32208,
e9f47f3b 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',
277189c8 23 q[my $VERSION = '1.01'] => 'undef',
24 q[local $VERISON = '1.02'] => 'undef',
25 q[local $FOO::VERSION = '1.30'] => 'undef',
5bdf71cc 26 q[if( $Foo::VERSION >= 3.00 ) {]=> 'undef',
e9f47f3b 27 q[our $VERSION = '1.23';] => '1.23',
5bdf71cc 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',
a7d1454b 39 );
40
c8d65f10 41if( $Has_Version ) {
e9f47f3b 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");
277189c8 44}
45
c8d65f10 46plan tests => (2 * keys %versions) + 4;
277189c8 47
a7d1454b 48while( my($code, $expect) = each %versions ) {
c8d65f10 49 is( parse_version_string($code), $expect, $code );
50}
51
52
53sub parse_version_string {
54 my $code = shift;
55
a7d1454b 56 open(FILE, ">VERSION.tmp") || die $!;
57 print FILE "$code\n";
58 close FILE;
59
60 $_ = 'foo';
c8d65f10 61 my $version = MM->parse_version('VERSION.tmp');
a7d1454b 62 is( $_, 'foo', '$_ not leaked by parse_version' );
c8d65f10 63
a7d1454b 64 unlink "VERSION.tmp";
c8d65f10 65
66 return $version;
67}
68
69
e9f47f3b 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]
c8d65f10 73SKIP: {
e9f47f3b 74 skip "need version.pm", 4 unless $Has_Version;
c8d65f10 75 is parse_version_string(q[ $VERSION = '1.00'; sub version { $VERSION } ]),
76 '1.00';
e9f47f3b 77 is parse_version_string(q[ use version; $VERSION = version->new("1.2.3") ]),
78 qv("1.2.3");
a7d1454b 79}