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