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