Re: Win32 status - progress !
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / t / MM_Win32.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 =~ /MSWin32/i) {
12                 plan tests => 44;
13         } else {
14                 plan skip_all => 'This is not Win32';
15         }
16 }
17
18 use Config;
19 use File::Spec;
20 use 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
34 require_ok( 'ExtUtils::MM_Win32' );
35
36 # test import of $Verbose and &neatvalue
37 can_ok( 'MM', 'neatvalue' );
38 is( $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()
53 SKIP: {
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()
183 my $script_ext  = '';
184 my $script_name = 'mm_w32tmp';
185 SKIP: {
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__
192 EOSCRIPT
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 ), undef,
219         "perl_script ($script_ext) returns empty" );
220 }
221 unlink "${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     $bin_sh = "SHELL = $bin_sh" if $bin_sh;
258
259     my $tools = join "\n", map "$_ = $mm_w32->{ $_ }"
260         => qw(CHMOD CP LD MV NOOP RM_F RM_RF TEST_F TOUCH UMASK_NULL DEV_NULL);
261
262     like( $mm_w32->tools_other(),
263           qr/^\Q$bin_sh$tools/m,
264           'tools_other()' );
265 };
266
267 # xs_o() should look into that
268 # top_targets() should look into that
269
270 # htmlify_pods()
271 {
272     my $mm_w32 = bless {
273         HTMLLIBPODS    => { 'MM_Win32.pm' => 1 },
274         HTMLSCRIPTPODS => { 'MM_Win32.t'  => 1 },
275         PERL_SRC       => undef,
276     }, 'MM';
277     my $pods = join " \\\n\t", keys %{$mm_w32->{HTMLLIBPODS}}, 
278                                keys %{$mm_w32->{HTMLSCRIPTPODS}};
279
280     my $pod2html_exe = $mm_w32->catfile($Config{scriptdirexp},'pod2html');
281     unless ( $pod2html_exe = $mm_w32->perl_script( $pod2html_exe ) ) {
282         $pod2html_exe = '-S pod2html';
283     }
284
285     like( $mm_w32->htmlifypods(),
286           qr/^POD2HTML_EXE\ =\ \Q$pod2html_exe\E\n
287              POD2HTML\ =.+\n
288              htmlifypods\ :\ pure_all\ \Q$pods\E
289           /xs,
290           'htmlifypods() Makefile target' );
291 }
292
293 # manifypods()
294 {
295     my $mm_w32 = bless { NOECHO    => '' }, 'MM';
296     like( $mm_w32->manifypods(),
297           qr/^\nmanifypods :\n\t\$\Q(NOOP)\E\n$/,
298           'manifypods() Makefile target' );
299 }
300
301 # dist_ci() should look into that
302 # dist_core() should look into that
303
304 # pasthru()
305 {
306     my $pastru = "PASTHRU = " . ($Config{make} =~ /^nmake/i ? "-nologo" : "");
307     is( MM->pasthru(), $pastru, 'pasthru()' );
308 }
309
310 package FakeOut;
311
312 sub TIEHANDLE {
313         bless(\(my $scalar), $_[0]);
314 }
315
316 sub PRINT {
317         my $self = shift;
318         $$self .= shift;
319 }
320
321 __END__
322
323 =head1 NAME
324
325 MM_Win32.t - Tests for ExtUtils::MM_Win32
326
327 =head1 TODO
328
329  - Methods to still be checked:
330  # static_lib() should look into that
331  # dynamic_bs() should look into that
332  # dynamic_lib() should look into that
333  # xs_o() should look into that
334  # top_targets() should look into that
335  # dist_ci() should look into that
336  # dist_core() should look into that
337
338 =head1 AUTHOR
339
340 20011228 Abe Timmerman <abe@ztreet.demon.nl>
341
342 =cut