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