4 if( $ENV{PERL_CORE} ) {
18 if ($^O =~ /MSWin32/i) {
21 plan skip_all => 'This is not Win32';
30 require_ok( 'ExtUtils::MM_Win32' );
32 # Dummy MM object until we have a real MM init method.
37 MAKEFILE => 'Makefile',
43 # replace_manpage_separator() => tr|/|.|s ?
45 my $man = 'a/path/to//something';
46 ( my $replaced = $man ) =~ tr|/|.|s;
47 is( $MM->replace_manpage_separator( $man ),
48 $replaced, 'replace_manpage_separator()' );
53 skip( '$ENV{COMSPEC} not set', 2 )
54 unless $ENV{COMSPEC} =~ m!((?:[a-z]:)?[^|<>]+)!i;
56 is( $MM->maybe_command( $comspec ),
57 $comspec, 'COMSPEC is a maybe_command()' );
58 ( my $comspec2 = $comspec ) =~ s|\..{3}$||;
59 like( $MM->maybe_command( $comspec2 ),
61 'maybe_command() without extension' );
64 my $had_pathext = exists $ENV{PATHEXT};
66 local $ENV{PATHEXT} = '.exe';
67 ok( ! $MM->maybe_command( 'not_a_command.com' ),
68 'not a maybe_command()' );
70 # Bug in Perl. local $ENV{FOO} won't delete the key afterward.
71 delete $ENV{PATHEXT} unless $had_pathext;
73 # file_name_is_absolute() [Does not support UNC-paths]
75 ok( $MM->file_name_is_absolute( 'C:/' ),
76 'file_name_is_absolute()' );
77 ok( ! $MM->file_name_is_absolute( 'some/path/' ),
78 'not file_name_is_absolute()' );
83 # Should be able to find running perl... $^X is OK on Win32
85 my $my_perl = $1 if $^X =~ /(.*)/; # are we in -T or -t?
86 my( $perl, $path ) = fileparse( $my_perl );
87 like( $MM->find_perl( $], [ $perl ], [ $path ], 0 ),
\r
88 qr/^\Q$my_perl\E$/i, 'find_perl() finds this perl' );
91 # catdir() (calls MM_Win32->canonpath)
93 my @path_eg = qw( c: trick dir/now_OK );
95 is( $MM->catdir( @path_eg ),
96 'C:\\trick\\dir\\now_OK', 'catdir()' );
97 is( $MM->catdir( @path_eg ),
98 File::Spec->catdir( @path_eg ),
99 'catdir() eq File::Spec->catdir()' );
101 # catfile() (calls MM_Win32->catdir)
102 push @path_eg, 'file.ext';
104 is( $MM->catfile( @path_eg ),
105 'C:\\trick\\dir\\now_OK\\file.ext', 'catfile()' );
107 is( $MM->catfile( @path_eg ),
108 File::Spec->catfile( @path_eg ),
109 'catfile() eq File::Spec->catfile()' );
112 # init_others(): check if all keys are created and set?
113 # qw( TOUCH CHMOD CP RM_F RM_RF MV NOOP TEST_F LD AR LDLOADLIBS DEV_NUL )
115 my $mm_w32 = bless( {}, 'MM' );
116 $mm_w32->init_others();
117 my @keys = qw( TOUCH CHMOD CP RM_F RM_RF MV NOOP
118 TEST_F LD AR LDLOADLIBS DEV_NULL );
119 for my $key ( @keys ) {
120 ok( $mm_w32->{ $key }, "init_others: $key" );
125 # XXX this test is probably useless now that we can call individual
126 # init_* methods and check the keys in $mm_w32 directly
129 NAME => 'TestMM_Win32',
131 PM => { 'MM_Win32.pm' => 1 },
134 # XXX Hack until we have a proper init method.
135 # Flesh out some necessary keys in the MM object.
136 @{$mm_w32}{qw(XS MAN1PODS MAN3PODS)} = ({}) x 3;
137 @{$mm_w32}{qw(C O_FILES H)} = ([]) x 3;
138 @{$mm_w32}{qw(PARENT_NAME)} = ('') x 3;
139 $mm_w32->{FULLEXT} = 'TestMM_Win32';
140 $mm_w32->{BASEEXT} = 'TestMM_Win32';
142 $mm_w32->init_VERSION;
143 $mm_w32->init_linker;
147 my $s_PM = join( " \\\n\t", sort keys %{$mm_w32->{PM}} );
148 my $k_PM = join( " \\\n\t", %{$mm_w32->{PM}} );
150 my $constants = $mm_w32->constants;
153 qr|^NAME \s* = \s* TestMM_Win32 \s* $|xms,
154 qr|^VERSION \s* = \s* 1\.00 \s* $|xms,
155 qr|^MAKEMAKER \s* = \s* \Q$INC{'ExtUtils/MakeMaker.pm'}\E \s* $|xms,
156 qr|^MM_VERSION \s* = \s* \Q$ExtUtils::MakeMaker::VERSION\E \s* $|xms,
157 qr|^TO_INST_PM \s* = \s* \Q$s_PM\E \s* $|xms,
158 qr|^PM_TO_BLIB \s* = \s* \Q$k_PM\E \s* $|xms,
161 like( $constants, $regex, 'constants() check' );
166 my $had_path = exists $ENV{PATH};
168 my @path_eg = ( qw( . .. ), 'C:\\Program Files' );
169 local $ENV{PATH} = join ';', @path_eg;
170 ok( eq_array( [ $MM->path() ], [ @path_eg ] ),
173 # Bug in Perl. local $ENV{FOO} will not delete key afterwards.
174 delete $ENV{PATH} unless $had_path;
176 # static_lib() should look into that
177 # dynamic_bs() should look into that
178 # dynamic_lib() should look into that
182 my $clean = $Config{cc} =~ /^gcc/i ? 'dll.base dll.exp' : '*.pdb';
183 like( $MM->clean(), qr/^clean ::\s+\Q-$(RM_F) $clean\E\s+$/m,
184 'clean() Makefile target' );
189 my $libperl = File::Spec->catfile('$(PERL_INC)',
190 $Config{libperl} || 'libperl.a');
191 my $export = '$(BASEEXT).def';
195 is( $MM->{PERL_ARCHIVE}, $libperl, 'PERL_ARCHIVE' );
196 is( $MM->{PERL_ARCHIVE_AFTER}, $after, 'PERL_ARCHIVE_AFTER' );
197 is( $MM->{EXPORT_LIST}, $export, 'EXPORT_LIST' );
202 my $path = 'c:\\Program Files/SomeApp\\Progje.exe';
203 is( $MM->canonpath( $path ), File::Spec->canonpath( $path ),
204 'canonpath() eq File::Spec->canonpath' );
209 my $script_name = 'mm_w32tmp';
212 skip( "Can't create temp file: $!", 4 )
213 unless open SCRIPT, "> $script_name";
214 print SCRIPT <<'EOSCRIPT';
218 skip( "Can't write to temp file: $!", 4 )
221 is( $MM->perl_script( $script_name ),
222 "${script_name}$script_ext", "perl_script ($script_ext)" );
224 skip( "Can't rename temp file: $!", 3 )
225 unless rename $script_name, "${script_name}.pl";
227 is( $MM->perl_script( $script_name ),
228 "${script_name}$script_ext", "perl_script ($script_ext)" );
230 skip( "Can't rename temp file: $!", 2 )
231 unless rename "${script_name}$script_ext", "${script_name}.bat";
232 $script_ext = '.bat';
233 is( $MM->perl_script( $script_name ),
234 "${script_name}$script_ext", "perl_script ($script_ext)" );
236 skip( "Can't rename temp file: $!", 1 )
237 unless rename "${script_name}$script_ext", "${script_name}.noscript";
238 $script_ext = '.noscript';
240 isnt( $MM->perl_script( $script_name ),
241 "${script_name}$script_ext",
242 "not a perl_script anymore ($script_ext)" );
243 is( $MM->perl_script( $script_name ), undef,
244 "perl_script ($script_ext) returns empty" );
246 unlink "${script_name}$script_ext" if -f "${script_name}$script_ext";
249 # xs_o() should look into that
250 # top_targets() should look into that
252 # dist_ci() should look into that
253 # dist_core() should look into that
257 my $pastru = "PASTHRU = " . ($Config{make} =~ /^nmake/i ? "-nologo" : "");
258 is( $MM->pasthru(), $pastru, 'pasthru()' );
264 bless(\(my $scalar), $_[0]);
276 MM_Win32.t - Tests for ExtUtils::MM_Win32
280 - Methods to still be checked:
281 # static_lib() should look into that
282 # dynamic_bs() should look into that
283 # dynamic_lib() should look into that
284 # xs_o() should look into that
285 # top_targets() should look into that
286 # dist_ci() should look into that
287 # dist_core() should look into that
291 20011228 Abe Timmerman <abe@ztreet.demon.nl>