This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Replace #20763 with
[perl5.git] / lib / ExtUtils / t / MM_Cygwin.t
CommitLineData
6df87cfb 1#!/usr/bin/perl
c9b71ffd 2
3BEGIN {
6df87cfb
JH
4 if( $ENV{PERL_CORE} ) {
5 chdir 't' if -d 't';
6 @INC = '../lib';
7 }
8 else {
9 unshift @INC, 't/lib';
10 }
c9b71ffd 11}
6df87cfb 12chdir 't';
c9b71ffd 13
479d2113 14use strict;
c9b71ffd 15use Test::More;
16
17BEGIN {
18 if ($^O =~ /cygwin/i) {
dedf98bc 19 plan tests => 11;
c9b71ffd 20 } else {
6df87cfb 21 plan skip_all => "This is not cygwin";
c9b71ffd 22 }
23}
24
25use Config;
26use File::Spec;
6df87cfb 27use ExtUtils::MM;
c9b71ffd 28
29use_ok( 'ExtUtils::MM_Cygwin' );
30
31# test canonpath
32my $path = File::Spec->canonpath('/a/../../c');
33is( MM->canonpath('/a/../../c'), $path,
34 'canonpath() method should work just like the one in File::Spec' );
35
36# test cflags, with the fake package below
479d2113 37my $MM = bless({
c9b71ffd 38 CFLAGS => 'fakeflags',
39 CCFLAGS => '',
479d2113 40}, 'MM');
c9b71ffd 41
42# with CFLAGS set, it should be returned
479d2113 43is( $MM->cflags(), 'fakeflags',
c9b71ffd 44 'cflags() should return CFLAGS member data, if set' );
45
479d2113 46delete $MM->{CFLAGS};
c9b71ffd 47
48# ExtUtils::MM_Cygwin::cflags() calls this, fake the output
6df87cfb 49{
57b1a898 50 local $SIG{__WARN__} = sub {
57b1a898
MS
51 warn @_ unless $_[0] =~ /^Subroutine .* redefined/;
52 };
479d2113 53 *ExtUtils::MM_Unix::cflags = sub { return $_[1] };
6df87cfb 54}
c9b71ffd 55
56# respects the config setting, should ignore whitespace around equal sign
57my $ccflags = $Config{useshrplib} eq 'true' ? ' -DUSEIMPORTLIB' : '';
6df87cfb 58{
479d2113
MS
59 local $MM->{NEEDS_LINKING} = 1;
60 $MM->cflags(<<FLAGS);
c9b71ffd 61OPTIMIZE = opt
62PERLTYPE =pt
c9b71ffd 63FLAGS
6df87cfb 64}
c9b71ffd 65
479d2113
MS
66like( $MM->{CFLAGS}, qr/OPTIMIZE = opt/, '... should set OPTIMIZE' );
67like( $MM->{CFLAGS}, qr/PERLTYPE = pt/, '... should set PERLTYPE' );
68like( $MM->{CFLAGS}, qr/CCFLAGS = $ccflags/, '... should set CCFLAGS' );
c9b71ffd 69
70# test manifypods
479d2113 71$MM = bless({
c9b71ffd 72 NOECHO => 'noecho',
73 MAN3PODS => {},
74 MAN1PODS => {},
6df87cfb 75 MAKEFILE => 'Makefile',
c9b71ffd 76}, 'MM');
479d2113 77unlike( $MM->manifypods(), qr/foo/,
c9b71ffd 78 'manifypods() should return without PODS values set' );
79
479d2113
MS
80$MM->{MAN3PODS} = { foo => 'foo.1' };
81my $res = $MM->manifypods();
82like( $res, qr/pure_all.*foo.*foo.1/s, '... should add MAN3PODS targets' );
83
6df87cfb 84
479d2113
MS
85# init_linker
86{
87 my $libperl = $Config{libperl} || 'libperl.a';
88 $libperl =~ s/\.a/.dll.a/ if $] >= 5.007;
89 $libperl = "\$(PERL_INC)/$libperl";
90
91 my $export = '';
92 my $after = '';
93 $MM->init_linker;
94
95 is( $MM->{PERL_ARCHIVE}, $libperl, 'PERL_ARCHIVE' );
96 is( $MM->{PERL_ARCHIVE_AFTER}, $after, 'PERL_ARCHIVE_AFTER' );
97 is( $MM->{EXPORT_LIST}, $export, 'EXPORT_LIST' );
98}
99
c9b71ffd 100
c9b71ffd 101
102package FakeOut;
103
104sub TIEHANDLE {
105 bless(\(my $scalar), $_[0]);
106}
107
108sub PRINT {
109 my $self = shift;
110 $$self .= shift;
111}