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