Upgrade to ExtUtils::MakeMaker 6.52
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / t / MM_Cygwin.t
CommitLineData
6df87cfb 1#!/usr/bin/perl
c9b71ffd 2
3BEGIN {
6df87cfb 4 if( $ENV{PERL_CORE} ) {
5 chdir 't' if -d 't';
6 @INC = '../lib';
7 }
8 else {
9 unshift @INC, 't/lib';
10 }
c9b71ffd 11}
6df87cfb 12chdir 't';
c9b71ffd 13
479d2113 14use strict;
c9b71ffd 15use Test::More;
16
17BEGIN {
18 if ($^O =~ /cygwin/i) {
5bdf71cc 19 plan tests => 14;
c9b71ffd 20 } else {
6df87cfb 21 plan skip_all => "This is not cygwin";
c9b71ffd 22 }
23}
24
25use Config;
26use File::Spec;
6df87cfb 27use ExtUtils::MM;
5bdf71cc 28use Config;
c9b71ffd 29
30use_ok( 'ExtUtils::MM_Cygwin' );
31
32# test canonpath
33my $path = File::Spec->canonpath('/a/../../c');
34is( 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
479d2113 38my $MM = bless({
c9b71ffd 39 CFLAGS => 'fakeflags',
40 CCFLAGS => '',
479d2113 41}, 'MM');
c9b71ffd 42
43# with CFLAGS set, it should be returned
479d2113 44is( $MM->cflags(), 'fakeflags',
c9b71ffd 45 'cflags() should return CFLAGS member data, if set' );
46
479d2113 47delete $MM->{CFLAGS};
c9b71ffd 48
49# ExtUtils::MM_Cygwin::cflags() calls this, fake the output
6df87cfb 50{
57b1a898 51 local $SIG{__WARN__} = sub {
57b1a898 52 warn @_ unless $_[0] =~ /^Subroutine .* redefined/;
53 };
479d2113 54 *ExtUtils::MM_Unix::cflags = sub { return $_[1] };
6df87cfb 55}
c9b71ffd 56
57# respects the config setting, should ignore whitespace around equal sign
58my $ccflags = $Config{useshrplib} eq 'true' ? ' -DUSEIMPORTLIB' : '';
6df87cfb 59{
479d2113 60 local $MM->{NEEDS_LINKING} = 1;
61 $MM->cflags(<<FLAGS);
c9b71ffd 62OPTIMIZE = opt
63PERLTYPE =pt
c9b71ffd 64FLAGS
6df87cfb 65}
c9b71ffd 66
479d2113 67like( $MM->{CFLAGS}, qr/OPTIMIZE = opt/, '... should set OPTIMIZE' );
68like( $MM->{CFLAGS}, qr/PERLTYPE = pt/, '... should set PERLTYPE' );
69like( $MM->{CFLAGS}, qr/CCFLAGS = $ccflags/, '... should set CCFLAGS' );
c9b71ffd 70
71# test manifypods
479d2113 72$MM = bless({
c9b71ffd 73 NOECHO => 'noecho',
74 MAN3PODS => {},
75 MAN1PODS => {},
6df87cfb 76 MAKEFILE => 'Makefile',
c9b71ffd 77}, 'MM');
479d2113 78unlike( $MM->manifypods(), qr/foo/,
c9b71ffd 79 'manifypods() should return without PODS values set' );
80
479d2113 81$MM->{MAN3PODS} = { foo => 'foo.1' };
82my $res = $MM->manifypods();
83like( $res, qr/pure_all.*foo.*foo.1/s, '... should add MAN3PODS targets' );
84
6df87cfb 85
479d2113 86# init_linker
87{
88 my $libperl = $Config{libperl} || 'libperl.a';
a7d1454b 89 $libperl =~ s/\.a/.dll.a/ if $] >= 5.006002;
479d2113 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
5bdf71cc 101# Tests for correct handling of maybe_command in /cygdrive/*
102# and c:/*. $ENV{COMSPEC}, if it exists, should always be executable.
103
104SKIP: {
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");
c9b71ffd 117
5bdf71cc 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}
c9b71ffd 131
132package FakeOut;
133
134sub TIEHANDLE {
135 bless(\(my $scalar), $_[0]);
136}
137
138sub PRINT {
139 my $self = shift;
140 $$self .= shift;
141}