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