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 | } |
a9200272 |
8 | } |
39234879 |
9 | chdir 't'; |
a9200272 |
10 | |
11 | use Test::More; |
12 | |
13 | BEGIN { |
14 | if ($^O =~ /MSWin32/i) { |
15 | plan tests => 44; |
16 | } else { |
f49b7d07 |
17 | plan skip_all => 'This is not Win32'; |
a9200272 |
18 | } |
19 | } |
20 | |
21 | use Config; |
22 | use File::Spec; |
23 | use File::Basename; |
39234879 |
24 | use ExtUtils::MakeMaker; |
a9200272 |
25 | |
26 | require_ok( 'ExtUtils::MM_Win32' ); |
27 | |
28 | # test import of $Verbose and &neatvalue |
29 | can_ok( 'MM', 'neatvalue' ); |
39234879 |
30 | () = $ExtUtils::MM_Win32::Verbose; |
31 | () = $ExtUtils::MakeMaker::Verbose; |
a9200272 |
32 | is( $ExtUtils::MM_Win32::Verbose, $ExtUtils::MakeMaker::Verbose, |
33 | 'ExtUtils::MM_Win32 should import $Verbose from ExtUtils::MakeMaker' ); |
34 | |
35 | |
36 | ##### Start new tests at the top of MM_Win32 |
37 | |
38 | # replace_manpage_separator() => tr|/|.|s ? |
39 | { |
40 | my $man = 'a/path/to//something'; |
41 | ( my $replaced = $man ) =~ tr|/|.|s; |
42 | is( MM->replace_manpage_separator( $man ), |
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; |
51 | is( MM->maybe_command( $comspec ), |
52 | $comspec, 'COMSPEC is a maybe_command()' ); |
53 | ( my $comspec2 = $comspec ) =~ s|\..{3}$||; |
54 | like( MM->maybe_command( $comspec2 ), |
55 | qr/\Q$comspec/i, |
56 | 'maybe_command() without extension' ); |
57 | } |
58 | { |
59 | local $ENV{PATHEXT} = '.exe'; |
60 | ok( ! MM->maybe_command( 'not_a_command.com' ), |
61 | 'not a maybe_command()' ); |
62 | } |
63 | |
64 | # file_name_is_absolute() [Does not support UNC-paths] |
65 | { |
66 | ok( MM->file_name_is_absolute( 'C:/' ), |
67 | 'file_name_is_absolute()' ); |
68 | ok( ! MM->file_name_is_absolute( 'some/path/' ), |
69 | 'not file_name_is_absolute()' ); |
70 | |
71 | } |
72 | |
73 | # find_perl() |
74 | # Should be able to find running perl... $^X is OK on Win32 |
75 | { |
76 | my $my_perl = $1 if $^X =~ /(.*)/; # are we in -T or -t? |
77 | my( $perl, $path ) = fileparse( $my_perl ); |
78 | like( MM->find_perl( $], [ $perl ], [ $path ] ), |
79 | qr/^\Q$my_perl\E$/i, 'find_perl() finds this perl' ); |
80 | } |
81 | |
82 | # catdir() (calls MM_Win32->canonpath) |
83 | { |
84 | my @path_eg = qw( c: trick dir/now_OK ); |
85 | |
86 | is( MM->catdir( @path_eg ), |
87 | 'C:\\trick\\dir\\now_OK', 'catdir()' ); |
88 | is( MM->catdir( @path_eg ), |
89 | File::Spec->catdir( @path_eg ), |
90 | 'catdir() eq File::Spec->catdir()' ); |
91 | |
92 | # catfile() (calls MM_Win32->catdir) |
93 | push @path_eg, 'file.ext'; |
94 | |
95 | is( MM->catfile( @path_eg ), |
96 | 'C:\\trick\\dir\\now_OK\\file.ext', 'catfile()' ); |
97 | |
98 | is( MM->catfile( @path_eg ), |
99 | File::Spec->catfile( @path_eg ), |
100 | 'catfile() eq File::Spec->catfile()' ); |
101 | } |
102 | |
103 | # init_others(): check if all keys are created and set? |
104 | # qw( TOUCH CHMOD CP RM_F RM_RF MV NOOP TEST_F LD AR LDLOADLIBS DEV_NUL ) |
105 | { |
106 | my $mm_w32 = bless( {}, 'MM' ); |
107 | $mm_w32->init_others(); |
108 | my @keys = qw( TOUCH CHMOD CP RM_F RM_RF MV NOOP |
109 | TEST_F LD AR LDLOADLIBS DEV_NULL ); |
110 | for my $key ( @keys ) { |
111 | ok( $mm_w32->{ $key }, "init_others: $key" ); |
112 | } |
113 | } |
114 | |
115 | # constants() |
116 | { |
117 | my $mm_w32 = bless { |
118 | NAME => 'TestMM_Win32', |
119 | VERSION => '1.00', |
120 | VERSION_FROM => 'TestMM_Win32', |
121 | PM => { 'MM_Win32.pm' => 1 }, |
122 | }, 'MM'; |
39234879 |
123 | |
124 | # XXX Hack until we have a proper init method. |
125 | # Flesh out some necessary keys in the MM object. |
126 | foreach my $key (qw(XS C O_FILES H HTMLLIBPODS HTMLSCRIPTPODS |
127 | MAN1PODS MAN3PODS PARENT_NAME)) { |
128 | $mm_w32{$key} = ''; |
129 | } |
a9200272 |
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.+ |
39234879 |
135 | MAKEMAKER\ =\ $INC{'ExtUtils/MakeMaker.pm'}\s+ |
a9200272 |
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)" ); |
a37c3bb4 |
219 | is( MM->perl_script( $script_name ), undef, |
a9200272 |
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" ); |
84a9aad5 |
258 | $bin_sh = "SHELL = $bin_sh" if $bin_sh; |
a9200272 |
259 | |
260 | my $tools = join "\n", map "$_ = $mm_w32->{ $_ }" |
261 | => qw(CHMOD CP LD MV NOOP RM_F RM_RF TEST_F TOUCH UMASK_NULL DEV_NULL); |
262 | |
263 | like( $mm_w32->tools_other(), |
84a9aad5 |
264 | qr/^\Q$bin_sh$tools/m, |
a9200272 |
265 | 'tools_other()' ); |
266 | }; |
267 | |
268 | # xs_o() should look into that |
269 | # top_targets() should look into that |
270 | |
271 | # htmlify_pods() |
272 | { |
273 | my $mm_w32 = bless { |
274 | HTMLLIBPODS => { 'MM_Win32.pm' => 1 }, |
275 | HTMLSCRIPTPODS => { 'MM_Win32.t' => 1 }, |
276 | PERL_SRC => undef, |
277 | }, 'MM'; |
278 | my $pods = join " \\\n\t", keys %{$mm_w32->{HTMLLIBPODS}}, |
279 | keys %{$mm_w32->{HTMLSCRIPTPODS}}; |
84a9aad5 |
280 | |
a9200272 |
281 | my $pod2html_exe = $mm_w32->catfile($Config{scriptdirexp},'pod2html'); |
84a9aad5 |
282 | unless ( $pod2html_exe = $mm_w32->perl_script( $pod2html_exe ) ) { |
283 | $pod2html_exe = '-S pod2html'; |
284 | } |
a9200272 |
285 | |
286 | like( $mm_w32->htmlifypods(), |
287 | qr/^POD2HTML_EXE\ =\ \Q$pod2html_exe\E\n |
288 | POD2HTML\ =.+\n |
289 | htmlifypods\ :\ pure_all\ \Q$pods\E |
290 | /xs, |
291 | 'htmlifypods() Makefile target' ); |
292 | } |
293 | |
294 | # manifypods() |
295 | { |
296 | my $mm_w32 = bless { NOECHO => '' }, 'MM'; |
297 | like( $mm_w32->manifypods(), |
298 | qr/^\nmanifypods :\n\t\$\Q(NOOP)\E\n$/, |
299 | 'manifypods() Makefile target' ); |
300 | } |
301 | |
302 | # dist_ci() should look into that |
303 | # dist_core() should look into that |
304 | |
305 | # pasthru() |
306 | { |
307 | my $pastru = "PASTHRU = " . ($Config{make} =~ /^nmake/i ? "-nologo" : ""); |
308 | is( MM->pasthru(), $pastru, 'pasthru()' ); |
309 | } |
310 | |
311 | package FakeOut; |
312 | |
313 | sub TIEHANDLE { |
314 | bless(\(my $scalar), $_[0]); |
315 | } |
316 | |
317 | sub PRINT { |
318 | my $self = shift; |
319 | $$self .= shift; |
320 | } |
321 | |
322 | __END__ |
323 | |
324 | =head1 NAME |
325 | |
326 | MM_Win32.t - Tests for ExtUtils::MM_Win32 |
327 | |
328 | =head1 TODO |
329 | |
330 | - Methods to still be checked: |
331 | # static_lib() should look into that |
332 | # dynamic_bs() should look into that |
333 | # dynamic_lib() should look into that |
334 | # xs_o() should look into that |
335 | # top_targets() should look into that |
336 | # dist_ci() should look into that |
337 | # dist_core() should look into that |
338 | |
339 | =head1 AUTHOR |
340 | |
341 | 20011228 Abe Timmerman <abe@ztreet.demon.nl> |
342 | |
343 | =cut |