Undo #16091, a time-warped escapee.
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / t / MM_Cygwin.t
1 #!/usr/bin/perl
2
3 BEGIN {
4     if( $ENV{PERL_CORE} ) {
5         chdir 't' if -d 't';
6         @INC = '../lib';
7     }
8     else {
9         unshift @INC, 't/lib';
10     }
11 }
12 chdir 't';
13
14 use Test::More;
15
16 BEGIN {
17         if ($^O =~ /cygwin/i) {
18                 plan tests => 13;
19         } else {
20                 plan skip_all => "This is not cygwin";
21         }
22 }
23
24 use Config;
25 use File::Spec;
26 use ExtUtils::MM;
27
28 use_ok( 'ExtUtils::MM_Cygwin' );
29
30 # test canonpath
31 my $path = File::Spec->canonpath('/a/../../c');
32 is( MM->canonpath('/a/../../c'), $path,
33         'canonpath() method should work just like the one in File::Spec' );
34
35 # test cflags, with the fake package below
36 my $args = bless({
37         CFLAGS  => 'fakeflags',
38         CCFLAGS => '',
39 }, MM);
40
41 # with CFLAGS set, it should be returned
42 is( $args->cflags(), 'fakeflags',
43         'cflags() should return CFLAGS member data, if set' );
44
45 delete $args->{CFLAGS};
46
47 # ExtUtils::MM_Cygwin::cflags() calls this, fake the output
48 {
49     no warnings 'redefine';
50     sub ExtUtils::MM_Unix::cflags { return $_[1] };
51 }
52
53 # respects the config setting, should ignore whitespace around equal sign
54 my $ccflags = $Config{useshrplib} eq 'true' ? ' -DUSEIMPORTLIB' : '';
55 {
56     local $args->{NEEDS_LINKING} = 1;
57     $args->cflags(<<FLAGS);
58 OPTIMIZE = opt
59 PERLTYPE  =pt
60 FLAGS
61 }
62
63 like( $args->{CFLAGS}, qr/OPTIMIZE = opt/, '... should set OPTIMIZE' );
64 like( $args->{CFLAGS}, qr/PERLTYPE = pt/, '... should set PERLTYPE' );
65 like( $args->{CFLAGS}, qr/CCFLAGS = $ccflags/, '... should set CCFLAGS' );
66
67 # test manifypods
68 $args = bless({
69         NOECHO => 'noecho',
70         MAN3PODS => {},
71         MAN1PODS => {},
72     MAKEFILE => 'Makefile',
73 }, 'MM');
74 like( $args->manifypods(), qr/pure_all\n\tnoecho/,
75         'manifypods() should return without PODS values set' );
76
77 $args->{MAN3PODS} = { foo => 1 };
78 my $out = tie *STDOUT, 'FakeOut';
79 {
80     no warnings 'once';
81     local *MM::perl_script = sub { return };
82     my $res = $args->manifypods();
83     like( $$out, qr/could not locate your pod2man/,
84           '... should warn if pod2man cannot be located' );
85     like( $res, qr/POD2MAN_EXE = -S pod2man/,
86           '... should use default pod2man target' );
87     like( $res, qr/pure_all.+foo/, '... should add MAN3PODS targets' );
88 }
89
90 SKIP: {
91     skip "Only relevent in the core", 2 unless $ENV{PERL_CORE};
92     $args->{PERL_SRC} = File::Spec->updir;
93     $args->{MAN1PODS} = { bar => 1 };
94     $$out = '';
95     $res = $args->manifypods();
96     is( $$out, '', '... should not warn if PERL_SRC provided' );
97     like( $res, qr/bar \\\n\t1 \\\n\tfoo/,
98           '... should join MAN1PODS and MAN3PODS');
99 }
100
101 # test perl_archive
102 my $libperl = $Config{libperl} || 'libperl.a';
103 $libperl =~ s/\.a/.dll.a/;
104 is( $args->perl_archive(), "\$(PERL_INC)/$libperl",
105         'perl_archive() should respect libperl setting' );
106
107
108 package FakeOut;
109
110 sub TIEHANDLE {
111         bless(\(my $scalar), $_[0]);
112 }
113
114 sub PRINT {
115         my $self = shift;
116         $$self .= shift;
117 }