assorted VMS test fix-ups, $Config{prefixexp} revisited
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / t / MM_Win32.t
CommitLineData
39234879 1#!/usr/bin/perl
c9d79356 2use strict;
a9200272 3
4BEGIN {
39234879 5 if( $ENV{PERL_CORE} ) {
6 chdir 't' if -d 't';
7 @INC = '../lib';
8 }
a9200272 9}
39234879 10chdir 't';
a9200272 11
12use Test::More;
13
14BEGIN {
15 if ($^O =~ /MSWin32/i) {
16 plan tests => 44;
17 } else {
f49b7d07 18 plan skip_all => 'This is not Win32';
a9200272 19 }
20}
21
22use Config;
23use File::Spec;
24use File::Basename;
39234879 25use ExtUtils::MakeMaker;
a9200272 26
27require_ok( 'ExtUtils::MM_Win32' );
28
29# test import of $Verbose and &neatvalue
30can_ok( 'MM', 'neatvalue' );
39234879 31() = $ExtUtils::MM_Win32::Verbose;
32() = $ExtUtils::MakeMaker::Verbose;
a9200272 33is( $ExtUtils::MM_Win32::Verbose, $ExtUtils::MakeMaker::Verbose,
34 'ExtUtils::MM_Win32 should import $Verbose from ExtUtils::MakeMaker' );
35
36
37##### Start new tests at the top of MM_Win32
38
39# replace_manpage_separator() => tr|/|.|s ?
40{
41 my $man = 'a/path/to//something';
42 ( my $replaced = $man ) =~ tr|/|.|s;
43 is( MM->replace_manpage_separator( $man ),
44 $replaced, 'replace_manpage_separator()' );
45}
46
47# maybe_command()
48SKIP: {
49 skip( '$ENV{COMSPEC} not set', 2 )
50 unless $ENV{COMSPEC} =~ m!((?:[a-z]:)?[^|<>]+)!i;
51 my $comspec = $1;
52 is( MM->maybe_command( $comspec ),
53 $comspec, 'COMSPEC is a maybe_command()' );
54 ( my $comspec2 = $comspec ) =~ s|\..{3}$||;
55 like( MM->maybe_command( $comspec2 ),
56 qr/\Q$comspec/i,
57 'maybe_command() without extension' );
58}
59{
60 local $ENV{PATHEXT} = '.exe';
61 ok( ! MM->maybe_command( 'not_a_command.com' ),
62 'not a maybe_command()' );
63}
64
65# file_name_is_absolute() [Does not support UNC-paths]
66{
67 ok( MM->file_name_is_absolute( 'C:/' ),
68 'file_name_is_absolute()' );
69 ok( ! MM->file_name_is_absolute( 'some/path/' ),
70 'not file_name_is_absolute()' );
71
72}
73
74# find_perl()
75# Should be able to find running perl... $^X is OK on Win32
76{
77 my $my_perl = $1 if $^X =~ /(.*)/; # are we in -T or -t?
78 my( $perl, $path ) = fileparse( $my_perl );
79 like( MM->find_perl( $], [ $perl ], [ $path ] ),
80 qr/^\Q$my_perl\E$/i, 'find_perl() finds this perl' );
81}
82
83# catdir() (calls MM_Win32->canonpath)
84{
85 my @path_eg = qw( c: trick dir/now_OK );
86
87 is( MM->catdir( @path_eg ),
88 'C:\\trick\\dir\\now_OK', 'catdir()' );
89 is( MM->catdir( @path_eg ),
90 File::Spec->catdir( @path_eg ),
91 'catdir() eq File::Spec->catdir()' );
92
93# catfile() (calls MM_Win32->catdir)
94 push @path_eg, 'file.ext';
95
96 is( MM->catfile( @path_eg ),
97 'C:\\trick\\dir\\now_OK\\file.ext', 'catfile()' );
98
99 is( MM->catfile( @path_eg ),
100 File::Spec->catfile( @path_eg ),
101 'catfile() eq File::Spec->catfile()' );
102}
103
104# init_others(): check if all keys are created and set?
105# qw( TOUCH CHMOD CP RM_F RM_RF MV NOOP TEST_F LD AR LDLOADLIBS DEV_NUL )
106{
107 my $mm_w32 = bless( {}, 'MM' );
108 $mm_w32->init_others();
109 my @keys = qw( TOUCH CHMOD CP RM_F RM_RF MV NOOP
110 TEST_F LD AR LDLOADLIBS DEV_NULL );
111 for my $key ( @keys ) {
112 ok( $mm_w32->{ $key }, "init_others: $key" );
113 }
114}
115
116# constants()
117{
118 my $mm_w32 = bless {
119 NAME => 'TestMM_Win32',
120 VERSION => '1.00',
121 VERSION_FROM => 'TestMM_Win32',
122 PM => { 'MM_Win32.pm' => 1 },
123 }, 'MM';
39234879 124
125 # XXX Hack until we have a proper init method.
126 # Flesh out some necessary keys in the MM object.
127 foreach my $key (qw(XS C O_FILES H HTMLLIBPODS HTMLSCRIPTPODS
128 MAN1PODS MAN3PODS PARENT_NAME)) {
c9d79356 129 $mm_w32->{$key} = '';
39234879 130 }
a9200272 131 my $s_PM = join( " \\\n\t", sort keys %{$mm_w32->{PM}} );
132 my $k_PM = join( " \\\n\t", %{$mm_w32->{PM}} );
133
134 like( $mm_w32->constants(),
c9d79356 135 qr!^NAME\ =\ TestMM_Win32\s+VERSION\ =\ 1\.00.+
136 MAKEMAKER\ =\ \Q$INC{'ExtUtils/MakeMaker.pm'}\E\s+
137 MM_VERSION\ =\ \Q$ExtUtils::MakeMaker::VERSION\E.+
a9200272 138 VERSION_FROM\ =\ TestMM_Win32.+
139 TO_INST_PM\ =\ \Q$s_PM\E\s+
140 PM_TO_BLIB\ =\ \Q$k_PM\E
c9d79356 141 !xs, 'constants()' );
a9200272 142
143}
144
145# path()
146{
147 my @path_eg = ( qw( . .. ), 'C:\\Program Files' );
148 local $ENV{PATH} = join ';', @path_eg;
149 ok( eq_array( [ MM->path() ], [ @path_eg ] ),
150 'path() [preset]' );
151}
152
153# static_lib() should look into that
154# dynamic_bs() should look into that
155# dynamic_lib() should look into that
156
157# clean()
158{
159 my $clean = $Config{cc} =~ /^gcc/i ? 'dll.base dll.exp' : '*.pdb';
160 like( MM->clean(), qr/^clean ::\s+\Q-$(RM_F) $clean\E\s+$/m,
161 'clean() Makefile target' );
162}
163
164# perl_archive()
165{
166 my $libperl = $Config{libperl} || 'libperl.a';
167 is( MM->perl_archive(), File::Spec->catfile('$(PERL_INC)', $libperl ),
168 'perl_archive() should respect libperl setting' );
169}
170
171# export_list
172{
173 my $mm_w32 = bless { BASEEXT => 'someext' }, 'ExtUtils::MM_Win32';
174 is( $mm_w32->export_list(), 'someext.def', 'export_list()' );
175}
176
177# canonpath()
178{
179 my $path = 'c:\\Program Files/SomeApp\\Progje.exe';
180 is( MM->canonpath( $path ), File::Spec->canonpath( $path ),
181 'canonpath() eq File::Spec->canonpath' );
182}
183
184# perl_script()
185my $script_ext = '';
186my $script_name = 'mm_w32tmp';
187SKIP: {
188 local *SCRIPT;
189 skip( "Can't create temp file: $!", 4 )
190 unless open SCRIPT, "> $script_name";
191 print SCRIPT <<'EOSCRIPT';
192#! perl
193__END__
194EOSCRIPT
195 skip( "Can't write to temp file: $!", 4 )
196 unless close SCRIPT;
197 # now start tests:
198 is( MM->perl_script( $script_name ),
199 "${script_name}$script_ext", "perl_script ($script_ext)" );
200
201 skip( "Can't rename temp file: $!", 3 )
202 unless rename $script_name, "${script_name}.pl";
203 $script_ext = '.pl';
204 is( MM->perl_script( $script_name ),
205 "${script_name}$script_ext", "perl_script ($script_ext)" );
206
207 skip( "Can't rename temp file: $!", 2 )
208 unless rename "${script_name}$script_ext", "${script_name}.bat";
209 $script_ext = '.bat';
210 is( MM->perl_script( $script_name ),
211 "${script_name}$script_ext", "perl_script ($script_ext)" );
212
213 skip( "Can't rename temp file: $!", 1 )
214 unless rename "${script_name}$script_ext", "${script_name}.noscript";
215 $script_ext = '.noscript';
216
217 isnt( MM->perl_script( $script_name ),
218 "${script_name}$script_ext",
219 "not a perl_script anymore ($script_ext)" );
a37c3bb4 220 is( MM->perl_script( $script_name ), undef,
a9200272 221 "perl_script ($script_ext) returns empty" );
222}
223unlink "${script_name}$script_ext" if -f "${script_name}$script_ext";
224
225
226# pm_to_blib()
227{
228 like( MM->pm_to_blib(),
229 qr/^pm_to_blib: \Q$(TO_INST_PM)\E.+\Q$(TOUCH) \E\$@\s+$/ms,
230 'pm_to_blib' );
231}
232
233# test_via_harness()
234{
235 like( MM->test_via_harness( $^X, 'MM_Win32.t' ),
236 qr/^\t\Q$^X\E \-Mblib.+"use Test::Harness.+MM_Win32.t\n$/,
237 'test_via_harness()' );
238}
239
240# tool_autosplit()
241{
242 my %attribs = ( MAXLEN => 255 );
243 like( MM->tool_autosplit( %attribs ),
244 qr/^\#\ Usage:\ \$\(AUTOSPLITFILE\)
245 \ FileToSplit\ AutoDirToSplitInto.+
246 AUTOSPLITFILE\ =\ \$\(PERL\)\
247 "\-I\$\(PERL_ARCHLIB\)"\ "\-I\$\(PERL_LIB\)".+
248 \$AutoSplit::Maxlen=$attribs{MAXLEN};
249 /xms,
250 'tool_autosplit()' );
251}
252
253# tools_other()
254{
255 ( my $mm_w32 = bless { }, 'MM' )->init_others();
256
257 my $bin_sh = ( $Config{make} =~ /^dmake/i
258 ? "" : ($Config{sh} || 'cmd /c') . "\n" );
84a9aad5 259 $bin_sh = "SHELL = $bin_sh" if $bin_sh;
a9200272 260
261 my $tools = join "\n", map "$_ = $mm_w32->{ $_ }"
262 => qw(CHMOD CP LD MV NOOP RM_F RM_RF TEST_F TOUCH UMASK_NULL DEV_NULL);
263
264 like( $mm_w32->tools_other(),
84a9aad5 265 qr/^\Q$bin_sh$tools/m,
a9200272 266 'tools_other()' );
267};
268
269# xs_o() should look into that
270# top_targets() should look into that
271
272# htmlify_pods()
273{
274 my $mm_w32 = bless {
275 HTMLLIBPODS => { 'MM_Win32.pm' => 1 },
276 HTMLSCRIPTPODS => { 'MM_Win32.t' => 1 },
277 PERL_SRC => undef,
278 }, 'MM';
279 my $pods = join " \\\n\t", keys %{$mm_w32->{HTMLLIBPODS}},
280 keys %{$mm_w32->{HTMLSCRIPTPODS}};
84a9aad5 281
a9200272 282 my $pod2html_exe = $mm_w32->catfile($Config{scriptdirexp},'pod2html');
84a9aad5 283 unless ( $pod2html_exe = $mm_w32->perl_script( $pod2html_exe ) ) {
284 $pod2html_exe = '-S pod2html';
285 }
a9200272 286
287 like( $mm_w32->htmlifypods(),
288 qr/^POD2HTML_EXE\ =\ \Q$pod2html_exe\E\n
289 POD2HTML\ =.+\n
290 htmlifypods\ :\ pure_all\ \Q$pods\E
291 /xs,
292 'htmlifypods() Makefile target' );
293}
294
295# manifypods()
296{
297 my $mm_w32 = bless { NOECHO => '' }, 'MM';
298 like( $mm_w32->manifypods(),
299 qr/^\nmanifypods :\n\t\$\Q(NOOP)\E\n$/,
300 'manifypods() Makefile target' );
301}
302
303# dist_ci() should look into that
304# dist_core() should look into that
305
306# pasthru()
307{
308 my $pastru = "PASTHRU = " . ($Config{make} =~ /^nmake/i ? "-nologo" : "");
309 is( MM->pasthru(), $pastru, 'pasthru()' );
310}
311
312package FakeOut;
313
314sub TIEHANDLE {
315 bless(\(my $scalar), $_[0]);
316}
317
318sub PRINT {
319 my $self = shift;
320 $$self .= shift;
321}
322
323__END__
324
325=head1 NAME
326
327MM_Win32.t - Tests for ExtUtils::MM_Win32
328
329=head1 TODO
330
331 - Methods to still be checked:
332 # static_lib() should look into that
333 # dynamic_bs() should look into that
334 # dynamic_lib() should look into that
335 # xs_o() should look into that
336 # top_targets() should look into that
337 # dist_ci() should look into that
338 # dist_core() should look into that
339
340=head1 AUTHOR
341
34220011228 Abe Timmerman <abe@ztreet.demon.nl>
343
344=cut