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