Upgrade to ExtUtils::MakeMaker 6.52
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / t / MM_Cygwin.t
1 #!/usr/bin/perl
2
3 BEGIN {
4     if( $ENV{PERL_CORE} ) {
5         chdir 't' if -d 't';
6         @INC = '../lib';
7     }
8     else {
9         unshift @INC, 't/lib';
10     }
11 }
12 chdir 't';
13
14 use strict;
15 use Test::More;
16
17 BEGIN {
18         if ($^O =~ /cygwin/i) {
19                 plan tests => 14;
20         } else {
21                 plan skip_all => "This is not cygwin";
22         }
23 }
24
25 use Config;
26 use File::Spec;
27 use ExtUtils::MM;
28 use Config;
29
30 use_ok( 'ExtUtils::MM_Cygwin' );
31
32 # test canonpath
33 my $path = File::Spec->canonpath('/a/../../c');
34 is( MM->canonpath('/a/../../c'), $path,
35         'canonpath() method should work just like the one in File::Spec' );
36
37 # test cflags, with the fake package below
38 my $MM = bless({
39         CFLAGS  => 'fakeflags',
40         CCFLAGS => '',
41 }, 'MM');
42
43 # with CFLAGS set, it should be returned
44 is( $MM->cflags(), 'fakeflags',
45         'cflags() should return CFLAGS member data, if set' );
46
47 delete $MM->{CFLAGS};
48
49 # ExtUtils::MM_Cygwin::cflags() calls this, fake the output
50 {
51     local $SIG{__WARN__} = sub { 
52         warn @_ unless $_[0] =~ /^Subroutine .* redefined/;
53     };
54     *ExtUtils::MM_Unix::cflags = sub { return $_[1] };
55 }
56
57 # respects the config setting, should ignore whitespace around equal sign
58 my $ccflags = $Config{useshrplib} eq 'true' ? ' -DUSEIMPORTLIB' : '';
59 {
60     local $MM->{NEEDS_LINKING} = 1;
61     $MM->cflags(<<FLAGS);
62 OPTIMIZE = opt
63 PERLTYPE  =pt
64 FLAGS
65 }
66
67 like( $MM->{CFLAGS}, qr/OPTIMIZE = opt/, '... should set OPTIMIZE' );
68 like( $MM->{CFLAGS}, qr/PERLTYPE = pt/, '... should set PERLTYPE' );
69 like( $MM->{CFLAGS}, qr/CCFLAGS = $ccflags/, '... should set CCFLAGS' );
70
71 # test manifypods
72 $MM = bless({
73         NOECHO => 'noecho',
74         MAN3PODS => {},
75         MAN1PODS => {},
76     MAKEFILE => 'Makefile',
77 }, 'MM');
78 unlike( $MM->manifypods(), qr/foo/,
79         'manifypods() should return without PODS values set' );
80
81 $MM->{MAN3PODS} = { foo => 'foo.1' };
82 my $res = $MM->manifypods();
83 like( $res, qr/pure_all.*foo.*foo.1/s, '... should add MAN3PODS targets' );
84
85
86 # init_linker
87 {
88     my $libperl = $Config{libperl} || 'libperl.a';
89     $libperl =~ s/\.a/.dll.a/ if $] >= 5.006002;
90     $libperl = "\$(PERL_INC)/$libperl";
91
92     my $export  = '';
93     my $after   = '';
94     $MM->init_linker;
95
96     is( $MM->{PERL_ARCHIVE},        $libperl,   'PERL_ARCHIVE' );
97     is( $MM->{PERL_ARCHIVE_AFTER},  $after,     'PERL_ARCHIVE_AFTER' );
98     is( $MM->{EXPORT_LIST},         $export,    'EXPORT_LIST' );
99 }
100
101 # Tests for correct handling of maybe_command in /cygdrive/*
102 # and c:/*.  $ENV{COMSPEC}, if it exists, should always be executable.
103
104 SKIP: {
105     my $comspec = $ENV{COMSPEC};
106
107     skip("\$ENV{COMSPEC} does not exist", 3) unless $comspec;
108
109     # Convert into cygwin-flavoured '/cygdrive/c/...' path.
110     # Is there a better way than direct munging?  A File::*
111     # module perhaps?
112
113     $comspec =~ s{^(\w):}  {/cygdrive/\l$1}x;
114     $comspec =~ s{\\    }  {/}gx;
115
116     ok(MM->maybe_command($comspec),"$comspec should be executable");
117
118     # /cygdrive/c should *never* be executable, it's a directory. 
119
120     ok(! MM->maybe_command(q{/cygdrive/c}), 
121        qq{/cygdrive/c should never be executable}
122     );
123
124     # Our copy of Perl (with a unix-path) should always be executable.
125
126     ok(MM->maybe_command($Config{perlpath}),
127        qq{$Config{perlpath} should be executable}
128     );
129
130 }
131
132 package FakeOut;
133
134 sub TIEHANDLE {
135         bless(\(my $scalar), $_[0]);
136 }
137
138 sub PRINT {
139         my $self = shift;
140         $$self .= shift;
141 }