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