Commit | Line | Data |
6df87cfb |
1 | #!/usr/bin/perl |
c9b71ffd |
2 | |
3 | BEGIN { |
b78fd716 |
4 | unshift @INC, 't/lib'; |
c9b71ffd |
5 | } |
6df87cfb |
6 | chdir 't'; |
c9b71ffd |
7 | |
479d2113 |
8 | use strict; |
c9b71ffd |
9 | use Test::More; |
10 | |
11 | BEGIN { |
12 | if ($^O =~ /cygwin/i) { |
5bdf71cc |
13 | plan tests => 14; |
c9b71ffd |
14 | } else { |
6df87cfb |
15 | plan skip_all => "This is not cygwin"; |
c9b71ffd |
16 | } |
17 | } |
18 | |
19 | use Config; |
20 | use File::Spec; |
6df87cfb |
21 | use ExtUtils::MM; |
5bdf71cc |
22 | use Config; |
c9b71ffd |
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 |
479d2113 |
32 | my $MM = bless({ |
c9b71ffd |
33 | CFLAGS => 'fakeflags', |
34 | CCFLAGS => '', |
479d2113 |
35 | }, 'MM'); |
c9b71ffd |
36 | |
37 | # with CFLAGS set, it should be returned |
479d2113 |
38 | is( $MM->cflags(), 'fakeflags', |
c9b71ffd |
39 | 'cflags() should return CFLAGS member data, if set' ); |
40 | |
479d2113 |
41 | delete $MM->{CFLAGS}; |
c9b71ffd |
42 | |
43 | # ExtUtils::MM_Cygwin::cflags() calls this, fake the output |
6df87cfb |
44 | { |
57b1a898 |
45 | local $SIG{__WARN__} = sub { |
57b1a898 |
46 | warn @_ unless $_[0] =~ /^Subroutine .* redefined/; |
47 | }; |
479d2113 |
48 | *ExtUtils::MM_Unix::cflags = sub { return $_[1] }; |
6df87cfb |
49 | } |
c9b71ffd |
50 | |
51 | # respects the config setting, should ignore whitespace around equal sign |
52 | my $ccflags = $Config{useshrplib} eq 'true' ? ' -DUSEIMPORTLIB' : ''; |
6df87cfb |
53 | { |
479d2113 |
54 | local $MM->{NEEDS_LINKING} = 1; |
55 | $MM->cflags(<<FLAGS); |
c9b71ffd |
56 | OPTIMIZE = opt |
57 | PERLTYPE =pt |
c9b71ffd |
58 | FLAGS |
6df87cfb |
59 | } |
c9b71ffd |
60 | |
479d2113 |
61 | like( $MM->{CFLAGS}, qr/OPTIMIZE = opt/, '... should set OPTIMIZE' ); |
62 | like( $MM->{CFLAGS}, qr/PERLTYPE = pt/, '... should set PERLTYPE' ); |
63 | like( $MM->{CFLAGS}, qr/CCFLAGS = $ccflags/, '... should set CCFLAGS' ); |
c9b71ffd |
64 | |
65 | # test manifypods |
479d2113 |
66 | $MM = bless({ |
c9b71ffd |
67 | NOECHO => 'noecho', |
68 | MAN3PODS => {}, |
69 | MAN1PODS => {}, |
6df87cfb |
70 | MAKEFILE => 'Makefile', |
c9b71ffd |
71 | }, 'MM'); |
479d2113 |
72 | unlike( $MM->manifypods(), qr/foo/, |
c9b71ffd |
73 | 'manifypods() should return without PODS values set' ); |
74 | |
479d2113 |
75 | $MM->{MAN3PODS} = { foo => 'foo.1' }; |
76 | my $res = $MM->manifypods(); |
77 | like( $res, qr/pure_all.*foo.*foo.1/s, '... should add MAN3PODS targets' ); |
78 | |
6df87cfb |
79 | |
479d2113 |
80 | # init_linker |
81 | { |
82 | my $libperl = $Config{libperl} || 'libperl.a'; |
a7d1454b |
83 | $libperl =~ s/\.a/.dll.a/ if $] >= 5.006002; |
479d2113 |
84 | $libperl = "\$(PERL_INC)/$libperl"; |
85 | |
86 | my $export = ''; |
87 | my $after = ''; |
88 | $MM->init_linker; |
89 | |
90 | is( $MM->{PERL_ARCHIVE}, $libperl, 'PERL_ARCHIVE' ); |
91 | is( $MM->{PERL_ARCHIVE_AFTER}, $after, 'PERL_ARCHIVE_AFTER' ); |
92 | is( $MM->{EXPORT_LIST}, $export, 'EXPORT_LIST' ); |
93 | } |
94 | |
5bdf71cc |
95 | # Tests for correct handling of maybe_command in /cygdrive/* |
96 | # and c:/*. $ENV{COMSPEC}, if it exists, should always be executable. |
5bdf71cc |
97 | SKIP: { |
75e3c8a3 |
98 | skip "Needs Cygwin::win_to_posix_path()", 2 unless defined &Cygwin::win_to_posix_path; |
5bdf71cc |
99 | |
75e3c8a3 |
100 | SKIP: { |
101 | my $comspec = $ENV{COMSPEC}; |
102 | skip(q[$ENV{COMSPEC} does not exist], 1) unless $comspec; |
5bdf71cc |
103 | |
75e3c8a3 |
104 | $comspec = Cygwin::win_to_posix_path($comspec); |
5bdf71cc |
105 | |
75e3c8a3 |
106 | ok(MM->maybe_command($comspec), qq{'$comspec' should be executable"}); |
107 | } |
108 | |
109 | # 'C:/' should *never* be executable, it's a directory. |
110 | { |
111 | my $cdrive = Cygwin::win_to_posix_path("C:/"); |
5bdf71cc |
112 | |
75e3c8a3 |
113 | ok(!MM->maybe_command($cdrive), qq{'$cdrive' should never be executable}); |
114 | } |
c0956255 |
115 | } |
5bdf71cc |
116 | |
c0956255 |
117 | # Our copy of Perl (with a unix-path) should always be executable. |
75e3c8a3 |
118 | ok(MM->maybe_command($Config{perlpath}), qq{'$Config{perlpath}' should be executable}); |
5bdf71cc |
119 | |
c9b71ffd |
120 | |
121 | package FakeOut; |
122 | |
123 | sub TIEHANDLE { |
124 | bless(\(my $scalar), $_[0]); |
125 | } |
126 | |
127 | sub PRINT { |
128 | my $self = shift; |
129 | $$self .= shift; |
130 | } |