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