Move ExtUtils tests to lib/ExtUtils/t.
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / t / MM_Cygwin.t
1 #!./perl
2
3 BEGIN {
4         chdir 't' if -d 't';
5         @INC = '../lib';
6 }
7
8 use Test::More;
9
10 BEGIN {
11         if ($^O =~ /cygwin/i) {
12                 plan tests => 17;
13         } else {
14                 plan skip_all => "This is not cygwin";
15         }
16 }
17
18 use Config;
19 use File::Spec;
20
21 # MM package faked up by messy MI entanglement
22 @MM::ISA = qw( ExtUtils::MM_Unix ExtUtils::Liblist::Kid ExtUtils::MakeMaker );
23
24 use_ok( 'ExtUtils::MM_Cygwin' );
25
26 # test canonpath
27 my $path = File::Spec->canonpath('/a/../../c');
28 is( 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
32 my $args = bless({
33         CFLAGS  => 'fakeflags',
34         CCFLAGS => '',
35 }, MM);
36
37 # with CFLAGS set, it should be returned
38 is( $args->cflags(), 'fakeflags',
39         'cflags() should return CFLAGS member data, if set' );
40
41 delete $args->{CFLAGS};
42
43 # ExtUtils::MM_Cygwin::cflags() calls this, fake the output
44 *ExtUtils::MM_Unix::cflags = sub { return $_[1] };
45
46 # respects the config setting, should ignore whitespace around equal sign
47 my $ccflags = $Config{useshrplib} eq 'true' ? ' -DUSEIMPORTLIB' : '';
48 $args->cflags(<<FLAGS);
49 OPTIMIZE = opt
50 PERLTYPE  =pt
51 LARGE= lg
52 SPLIT=split
53 FLAGS
54
55 like( $args->{CFLAGS}, qr/OPTIMIZE = opt/, '... should set OPTIMIZE' );
56 like( $args->{CFLAGS}, qr/PERLTYPE = pt/, '... should set PERLTYPE' );
57 like( $args->{CFLAGS}, qr/LARGE = lg/, '... should set LARGE' );
58 like( $args->{CFLAGS}, qr/SPLIT = split/, '... should set SPLIT' );
59 like( $args->{CFLAGS}, qr/CCFLAGS = $ccflags/, '... should set CCFLAGS' );
60
61 # test manifypods
62 $args = bless({
63         NOECHO => 'noecho',
64         MAN3PODS => {},
65         MAN1PODS => {},
66 }, 'MM');
67 like( $args->manifypods(), qr/pure_all\n\tnoecho/,
68         'manifypods() should return without PODS values set' );
69
70 $args->{MAN3PODS} = { foo => 1 };
71 my $out = tie *STDOUT, 'FakeOut';
72 my $res = $args->manifypods();
73 like( $$out, qr/could not locate your pod2man/,
74         '... should warn if pod2man cannot be located' );
75 like( $res, qr/POD2MAN_EXE = -S pod2man/,
76         '... should use default pod2man target' );
77 like( $res, qr/pure_all.+foo/, '... should add MAN3PODS targets' );
78
79 $args->{PERL_SRC} = File::Spec->updir;
80 $args->{MAN1PODS} = { bar => 1 };
81 $$out = '';
82 $res = $args->manifypods();
83 is( $$out, '', '... should not warn if PERL_SRC provided' );
84 like( $res, qr/bar \\\n\t1 \\\n\tfoo/, '... should join MAN1PODS and MAN3PODS');
85
86 # test perl_archive
87 my $libperl = $Config{libperl} || 'libperl.a';
88 is( $args->perl_archive(), "\$(PERL_INC)/$libperl",
89         'perl_archive() should respect libperl setting' );
90
91 # test import of $Verbose and &neatvalue
92 can_ok( 'ExtUtils::MM_Cygwin', 'neatvalue' );
93 is( $ExtUtils::MM_Cygwin::Verbose, $ExtUtils::MakeMaker::Verbose, 
94         'ExtUtils::MM_Cygwin should import $Verbose from ExtUtils::MakeMaker' );
95
96 package FakeOut;
97
98 sub TIEHANDLE {
99         bless(\(my $scalar), $_[0]);
100 }
101
102 sub PRINT {
103         my $self = shift;
104         $$self .= shift;
105 }