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