Upgrade to ExtUtils::MakeMaker 6.52
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / t / MM_Win32.t
CommitLineData
39234879 1#!/usr/bin/perl
a9200272 2
3BEGIN {
39234879 4 if( $ENV{PERL_CORE} ) {
5 chdir 't' if -d 't';
6 @INC = '../lib';
7 }
f6d6199c 8 else {
9 unshift @INC, 't/lib';
10 }
a9200272 11}
39234879 12chdir 't';
a9200272 13
f6d6199c 14use strict;
a9200272 15use Test::More;
16
17BEGIN {
18 if ($^O =~ /MSWin32/i) {
2e65e370 19 plan tests => 49;
a9200272 20 } else {
f49b7d07 21 plan skip_all => 'This is not Win32';
a9200272 22 }
23}
24
25use Config;
26use File::Spec;
27use File::Basename;
f6d6199c 28use ExtUtils::MM;
a9200272 29
30require_ok( 'ExtUtils::MM_Win32' );
31
f6d6199c 32# Dummy MM object until we have a real MM init method.
33my $MM = bless {
34 DIR => [],
35 NOECHO => '@',
e0678a30 36 XS => {},
f6d6199c 37 MAKEFILE => 'Makefile',
38 RM_RF => 'rm -rf',
39 MV => 'mv',
58d32538 40 MAKE => $Config{make}
f6d6199c 41 }, 'MM';
a9200272 42
a9200272 43
44# replace_manpage_separator() => tr|/|.|s ?
45{
46 my $man = 'a/path/to//something';
47 ( my $replaced = $man ) =~ tr|/|.|s;
f6d6199c 48 is( $MM->replace_manpage_separator( $man ),
a9200272 49 $replaced, 'replace_manpage_separator()' );
50}
51
52# maybe_command()
53SKIP: {
54 skip( '$ENV{COMSPEC} not set', 2 )
55 unless $ENV{COMSPEC} =~ m!((?:[a-z]:)?[^|<>]+)!i;
56 my $comspec = $1;
f6d6199c 57 is( $MM->maybe_command( $comspec ),
a9200272 58 $comspec, 'COMSPEC is a maybe_command()' );
59 ( my $comspec2 = $comspec ) =~ s|\..{3}$||;
f6d6199c 60 like( $MM->maybe_command( $comspec2 ),
a9200272 61 qr/\Q$comspec/i,
62 'maybe_command() without extension' );
63}
f6d6199c 64
65my $had_pathext = exists $ENV{PATHEXT};
a9200272 66{
67 local $ENV{PATHEXT} = '.exe';
f6d6199c 68 ok( ! $MM->maybe_command( 'not_a_command.com' ),
a9200272 69 'not a maybe_command()' );
70}
f6d6199c 71# Bug in Perl. local $ENV{FOO} won't delete the key afterward.
72delete $ENV{PATHEXT} unless $had_pathext;
a9200272 73
74# file_name_is_absolute() [Does not support UNC-paths]
75{
f6d6199c 76 ok( $MM->file_name_is_absolute( 'C:/' ),
a9200272 77 'file_name_is_absolute()' );
f6d6199c 78 ok( ! $MM->file_name_is_absolute( 'some/path/' ),
a9200272 79 'not file_name_is_absolute()' );
80
81}
82
83# find_perl()
84# Should be able to find running perl... $^X is OK on Win32
85{
86 my $my_perl = $1 if $^X =~ /(.*)/; # are we in -T or -t?
87 my( $perl, $path ) = fileparse( $my_perl );
5dca256e 88 like( $MM->find_perl( $], [ $perl ], [ $path ], 0 ),
a9200272 89 qr/^\Q$my_perl\E$/i, 'find_perl() finds this perl' );
90}
91
92# catdir() (calls MM_Win32->canonpath)
93{
94 my @path_eg = qw( c: trick dir/now_OK );
95
f6d6199c 96 is( $MM->catdir( @path_eg ),
a9200272 97 'C:\\trick\\dir\\now_OK', 'catdir()' );
f6d6199c 98 is( $MM->catdir( @path_eg ),
a9200272 99 File::Spec->catdir( @path_eg ),
100 'catdir() eq File::Spec->catdir()' );
101
102# catfile() (calls MM_Win32->catdir)
103 push @path_eg, 'file.ext';
104
f6d6199c 105 is( $MM->catfile( @path_eg ),
a9200272 106 'C:\\trick\\dir\\now_OK\\file.ext', 'catfile()' );
107
f6d6199c 108 is( $MM->catfile( @path_eg ),
a9200272 109 File::Spec->catfile( @path_eg ),
110 'catfile() eq File::Spec->catfile()' );
111}
112
113# init_others(): check if all keys are created and set?
60537fc0 114# qw( TOUCH CHMOD CP RM_F RM_RF MV NOOP TEST_F LD AR LDLOADLIBS DEV_NUL )
a9200272 115{
30361541 116 my $mm_w32 = bless( { BASEEXT => 'Foo' }, 'MM' );
a9200272 117 $mm_w32->init_others();
118 my @keys = qw( TOUCH CHMOD CP RM_F RM_RF MV NOOP
60537fc0 119 TEST_F LD AR LDLOADLIBS DEV_NULL );
a9200272 120 for my $key ( @keys ) {
121 ok( $mm_w32->{ $key }, "init_others: $key" );
122 }
123}
124
125# constants()
479d2113 126# XXX this test is probably useless now that we can call individual
127# init_* methods and check the keys in $mm_w32 directly
a9200272 128{
129 my $mm_w32 = bless {
130 NAME => 'TestMM_Win32',
131 VERSION => '1.00',
a9200272 132 PM => { 'MM_Win32.pm' => 1 },
133 }, 'MM';
39234879 134
135 # XXX Hack until we have a proper init method.
136 # Flesh out some necessary keys in the MM object.
479d2113 137 @{$mm_w32}{qw(XS MAN1PODS MAN3PODS)} = ({}) x 3;
138 @{$mm_w32}{qw(C O_FILES H)} = ([]) x 3;
139 @{$mm_w32}{qw(PARENT_NAME)} = ('') x 3;
140 $mm_w32->{FULLEXT} = 'TestMM_Win32';
141 $mm_w32->{BASEEXT} = 'TestMM_Win32';
142
143 $mm_w32->init_VERSION;
144 $mm_w32->init_linker;
145 $mm_w32->init_INST;
146 $mm_w32->init_xs;
147
a9200272 148 my $s_PM = join( " \\\n\t", sort keys %{$mm_w32->{PM}} );
149 my $k_PM = join( " \\\n\t", %{$mm_w32->{PM}} );
150
479d2113 151 my $constants = $mm_w32->constants;
152
153 foreach my $regex (
154 qr|^NAME \s* = \s* TestMM_Win32 \s* $|xms,
155 qr|^VERSION \s* = \s* 1\.00 \s* $|xms,
156 qr|^MAKEMAKER \s* = \s* \Q$INC{'ExtUtils/MakeMaker.pm'}\E \s* $|xms,
157 qr|^MM_VERSION \s* = \s* \Q$ExtUtils::MakeMaker::VERSION\E \s* $|xms,
158 qr|^TO_INST_PM \s* = \s* \Q$s_PM\E \s* $|xms,
159 qr|^PM_TO_BLIB \s* = \s* \Q$k_PM\E \s* $|xms,
160 )
161 {
162 like( $constants, $regex, 'constants() check' );
163 }
a9200272 164}
165
166# path()
167{
3461c7c9 168 ok( eq_array( [ $MM->path() ], [ File::Spec->path ] ),
a9200272 169 'path() [preset]' );
170}
171
172# static_lib() should look into that
173# dynamic_bs() should look into that
174# dynamic_lib() should look into that
175
479d2113 176# init_linker
a9200272 177{
479d2113 178 my $libperl = File::Spec->catfile('$(PERL_INC)',
179 $Config{libperl} || 'libperl.a');
180 my $export = '$(BASEEXT).def';
181 my $after = '';
182 $MM->init_linker;
183
184 is( $MM->{PERL_ARCHIVE}, $libperl, 'PERL_ARCHIVE' );
185 is( $MM->{PERL_ARCHIVE_AFTER}, $after, 'PERL_ARCHIVE_AFTER' );
186 is( $MM->{EXPORT_LIST}, $export, 'EXPORT_LIST' );
a9200272 187}
188
189# canonpath()
190{
191 my $path = 'c:\\Program Files/SomeApp\\Progje.exe';
f6d6199c 192 is( $MM->canonpath( $path ), File::Spec->canonpath( $path ),
a9200272 193 'canonpath() eq File::Spec->canonpath' );
194}
195
196# perl_script()
197my $script_ext = '';
198my $script_name = 'mm_w32tmp';
199SKIP: {
200 local *SCRIPT;
201 skip( "Can't create temp file: $!", 4 )
202 unless open SCRIPT, "> $script_name";
203 print SCRIPT <<'EOSCRIPT';
204#! perl
205__END__
206EOSCRIPT
207 skip( "Can't write to temp file: $!", 4 )
208 unless close SCRIPT;
209 # now start tests:
f6d6199c 210 is( $MM->perl_script( $script_name ),
a9200272 211 "${script_name}$script_ext", "perl_script ($script_ext)" );
212
213 skip( "Can't rename temp file: $!", 3 )
214 unless rename $script_name, "${script_name}.pl";
215 $script_ext = '.pl';
f6d6199c 216 is( $MM->perl_script( $script_name ),
a9200272 217 "${script_name}$script_ext", "perl_script ($script_ext)" );
218
219 skip( "Can't rename temp file: $!", 2 )
220 unless rename "${script_name}$script_ext", "${script_name}.bat";
221 $script_ext = '.bat';
f6d6199c 222 is( $MM->perl_script( $script_name ),
a9200272 223 "${script_name}$script_ext", "perl_script ($script_ext)" );
224
225 skip( "Can't rename temp file: $!", 1 )
226 unless rename "${script_name}$script_ext", "${script_name}.noscript";
227 $script_ext = '.noscript';
228
f6d6199c 229 isnt( $MM->perl_script( $script_name ),
a9200272 230 "${script_name}$script_ext",
231 "not a perl_script anymore ($script_ext)" );
f6d6199c 232 is( $MM->perl_script( $script_name ), undef,
a9200272 233 "perl_script ($script_ext) returns empty" );
234}
235unlink "${script_name}$script_ext" if -f "${script_name}$script_ext";
236
2e65e370 237# is_make_type()
238{
239 # Check for literal nmake
240 SKIP: {
241 skip("Not using 'nmake'", 2) unless $Config{make} eq 'nmake';
242 ok( $MM->is_make_type('nmake'), '->is_make_type(nmake) true' );
243 ok( ! $MM->is_make_type('dmake'), '->is_make_type(dmake) false' );
244 }
245
246 # Check for literal nmake
247 SKIP: {
248 skip("Not using /nmake/", 2) unless $Config{make} =~ /nmake/;
249 ok( $MM->is_make_type('nmake'), '->is_make_type(nmake) true' );
250 ok( ! $MM->is_make_type('dmake'), '->is_make_type(dmake) false' );
251 }
252
253 # Check for literal dmake
254 SKIP: {
255 skip("Not using 'dmake'", 2) unless $Config{make} eq 'dmake';
256 ok( $MM->is_make_type('dmake'), '->is_make_type(dmake) true' );
257 ok( ! $MM->is_make_type('nmake'), '->is_make_type(nmake) false' );
258 }
259
260 # Check for literal dmake
261 SKIP: {
262 skip("Not using /dmake/", 2) unless $Config{make} =~ /dmake/;
263 ok( $MM->is_make_type('dmake'), '->is_make_type(dmake) true' );
264 ok( ! $MM->is_make_type('nmake'), '->is_make_type(nmake) false' );
265 }
266
267}
a9200272 268
a9200272 269# xs_o() should look into that
270# top_targets() should look into that
271
a9200272 272# dist_ci() should look into that
273# dist_core() should look into that
274
275# pasthru()
276{
071e6b84 277 my $pastru = "PASTHRU = " . ($Config{make} =~ /^nmake/i ? "-nologo" : "");
278 is( $MM->pasthru(), $pastru, 'pasthru()' );
a9200272 279}
280
281package FakeOut;
282
283sub TIEHANDLE {
284 bless(\(my $scalar), $_[0]);
285}
286
287sub PRINT {
288 my $self = shift;
289 $$self .= shift;
290}
291
292__END__
293
294=head1 NAME
295
296MM_Win32.t - Tests for ExtUtils::MM_Win32
297
298=head1 TODO
299
300 - Methods to still be checked:
301 # static_lib() should look into that
302 # dynamic_bs() should look into that
303 # dynamic_lib() should look into that
304 # xs_o() should look into that
305 # top_targets() should look into that
306 # dist_ci() should look into that
307 # dist_core() should look into that
308
309=head1 AUTHOR
310
31120011228 Abe Timmerman <abe@ztreet.demon.nl>
312
313=cut