1#!/usr/bin/perl 2 3BEGIN { 4 unshift @INC, 't/lib'; 5} 6chdir 't'; 7 8use strict; 9use Test::More; 10 11BEGIN { 12 if ($^O =~ /cygwin/i) { 13 plan tests => 14; 14 } else { 15 plan skip_all => "This is not cygwin"; 16 } 17} 18 19use Config; 20use File::Spec; 21use ExtUtils::MM; 22use Config; 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 32my $MM = bless({ 33 CFLAGS => 'fakeflags', 34 CCFLAGS => '', 35}, 'MM'); 36 37# with CFLAGS set, it should be returned 38is( $MM->cflags(), 'fakeflags', 39 'cflags() should return CFLAGS member data, if set' ); 40 41delete $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 52my $ccflags = $Config{useshrplib} eq 'true' ? ' -DUSEIMPORTLIB' : ''; 53{ 54 local $MM->{NEEDS_LINKING} = 1; 55 $MM->cflags(<<FLAGS); 56OPTIMIZE = opt 57PERLTYPE =pt 58FLAGS 59} 60 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' ); 64 65# test manifypods 66$MM = bless({ 67 NOECHO => 'noecho', 68 MAN3PODS => {}, 69 MAN1PODS => {}, 70 MAKEFILE => 'Makefile', 71}, 'MM'); 72unlike( $MM->manifypods(), qr/foo/, 73 'manifypods() should return without PODS values set' ); 74 75$MM->{MAN3PODS} = { foo => 'foo.1' }; 76my $res = $MM->manifypods(); 77like( $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. 97SKIP: { 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. 118ok(MM->maybe_command($Config{perlpath}), qq{'$Config{perlpath}' should be executable}); 119 120 121package FakeOut; 122 123sub TIEHANDLE { 124 bless(\(my $scalar), $_[0]); 125} 126 127sub PRINT { 128 my $self = shift; 129 $$self .= shift; 130} 131