Commit | Line | Data |
f355267c |
1 | #!/usr/bin/perl |
2 | |
3 | BEGIN { |
4 | if( $ENV{PERL_CORE} ) { |
5 | chdir 't' if -d 't'; |
6 | unshift @INC, '../lib'; |
7 | } |
8 | else { |
9 | unshift @INC, 't/lib'; |
10 | } |
11 | } |
12 | chdir 't'; |
13 | |
14 | |
15 | use Test::More; |
16 | |
17 | BEGIN { |
18 | if ($^O =~ /NetWare/i) { |
19 | plan tests => 40; |
20 | } else { |
21 | plan skip_all => 'This is not NW5'; |
22 | } |
23 | } |
24 | |
25 | use Config; |
26 | use File::Spec; |
27 | use File::Basename; |
28 | use ExtUtils::MM; |
29 | |
30 | require_ok( 'ExtUtils::MM_NW5' ); |
31 | |
32 | # Dummy MM object until we have a real MM init method. |
33 | my $MM = bless { |
34 | DIR => [], |
35 | NOECHO => '@', |
36 | XS => {}, |
37 | MAKEFILE => 'Makefile', |
38 | RM_RF => 'rm -rf', |
39 | MV => 'mv', |
40 | }, 'MM'; |
41 | |
42 | |
43 | # replace_manpage_separator() => tr|/|.|s ? |
44 | { |
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()' ); |
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; |
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 ), |
60 | qr/\Q$comspec/i, |
61 | 'maybe_command() without extension' ); |
62 | } |
63 | |
64 | my $had_pathext = exists $ENV{PATHEXT}; |
65 | { |
66 | local $ENV{PATHEXT} = '.exe'; |
67 | ok( ! $MM->maybe_command( 'not_a_command.com' ), |
68 | 'not a maybe_command()' ); |
69 | } |
70 | # Bug in Perl. local $ENV{FOO} won't delete the key afterward. |
71 | delete $ENV{PATHEXT} unless $had_pathext; |
72 | |
73 | # file_name_is_absolute() [Does not support UNC-paths] |
74 | { |
75 | ok( $MM->file_name_is_absolute( 'SYS:/' ), |
76 | 'file_name_is_absolute()' ); |
77 | ok( ! $MM->file_name_is_absolute( 'some/path/' ), |
78 | 'not file_name_is_absolute()' ); |
79 | |
80 | } |
81 | |
82 | # find_perl() |
83 | # Should be able to find running perl... $^X is OK on NW5 |
84 | { |
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 ] ), |
88 | qr/^\Q$my_perl\E$/i, 'find_perl() finds this perl' ); |
89 | } |
90 | |
91 | # catdir() (calls MM_NW5->canonpath) |
92 | { |
93 | my @path_eg = qw( SYS trick dir/now_OK ); |
94 | |
95 | is( $MM->catdir( @path_eg ), |
96 | 'SYS\\trick\\dir\\now_OK', 'catdir()' ); |
97 | is( $MM->catdir( @path_eg ), |
98 | File::Spec->catdir( @path_eg ), |
99 | 'catdir() eq File::Spec->catdir()' ); |
100 | |
101 | # catfile() (calls MM_NW5->catdir) |
102 | push @path_eg, 'file.ext'; |
103 | |
104 | is( $MM->catfile( @path_eg ), |
105 | 'SYS\\trick\\dir\\now_OK\\file.ext', 'catfile()' ); |
106 | |
107 | is( $MM->catfile( @path_eg ), |
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? |
113 | # qw( TOUCH CHMOD CP RM_F RM_RF MV NOOP TEST_F LD AR LDLOADLIBS DEV_NUL ) |
114 | { |
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" ); |
121 | } |
122 | } |
123 | |
124 | # constants() |
125 | { |
126 | my $mm_w32 = bless { |
127 | NAME => 'TestMM_NW5', |
128 | VERSION => '1.00', |
129 | VERSION_FROM => 'TestMM_NW5', |
130 | PM => { 'MM_NW5.pm' => 1 }, |
131 | }, 'MM'; |
132 | |
133 | # XXX Hack until we have a proper init method. |
134 | # Flesh out some necessary keys in the MM object. |
135 | foreach my $key (qw(XS C O_FILES H HTMLLIBPODS HTMLSCRIPTPODS |
136 | MAN1PODS MAN3PODS PARENT_NAME)) { |
137 | $mm_w32->{$key} = ''; |
138 | } |
139 | my $s_PM = join( " \\\n\t", sort keys %{$mm_w32->{PM}} ); |
140 | my $k_PM = join( " \\\n\t", %{$mm_w32->{PM}} ); |
141 | |
142 | like( $mm_w32->constants(), |
143 | qr|^NAME\ =\ TestMM_NW5\s+VERSION\ =\ 1\.00.+ |
144 | MAKEMAKER\ =\ \Q$INC{'ExtUtils/MakeMaker.pm'}\E\s+ |
145 | MM_VERSION\ =\ \Q$ExtUtils::MakeMaker::VERSION\E.+ |
146 | VERSION_FROM\ =\ TestMM_NW5.+ |
147 | TO_INST_PM\ =\ \Q$s_PM\E\s+ |
148 | PM_TO_BLIB\ =\ \Q$k_PM\E |
149 | |xs, 'constants()' ); |
150 | |
151 | } |
152 | |
153 | # path() |
154 | my $had_path = exists $ENV{PATH}; |
155 | { |
156 | my @path_eg = ( qw( . .. ), 'SYS:\\Program Files' ); |
157 | local $ENV{PATH} = join ';', @path_eg; |
158 | ok( eq_array( [ $MM->path() ], [ @path_eg ] ), |
159 | 'path() [preset]' ); |
160 | } |
161 | # Bug in Perl. local $ENV{FOO} will not delete key afterwards. |
162 | delete $ENV{PATH} unless $had_path; |
163 | |
164 | # static_lib() should look into that |
165 | # dynamic_bs() should look into that |
166 | # dynamic_lib() should look into that |
167 | |
168 | # clean() |
169 | { |
170 | my $clean = $Config{cc} =~ /^gcc/i ? 'dll.base dll.exp' : '*.pdb'; |
171 | like( $MM->clean(), qr/^clean ::\s+\Q-$(RM_F) $clean\E\s+$/m, |
172 | 'clean() Makefile target' ); |
173 | } |
174 | |
479d2113 |
175 | |
176 | # init_linker |
f355267c |
177 | { |
178 | my $libperl = $Config{libperl} || 'libperl.a'; |
479d2113 |
179 | my $export = '$(BASEEXT).def'; |
180 | my $after = ''; |
181 | $MM->init_linker; |
f355267c |
182 | |
479d2113 |
183 | is( $MM->{PERL_ARCHIVE}, $libperl, 'PERL_ARCHIVE' ); |
184 | is( $MM->{PERL_ARCHIVE_AFTER}, $after, 'PERL_ARCHIVE_AFTER' ); |
185 | is( $MM->{EXPORT_LIST}, $export, 'EXPORT_LIST' ); |
f355267c |
186 | } |
187 | |
479d2113 |
188 | |
f355267c |
189 | # canonpath() |
190 | { |
191 | my $path = 'SYS:/TEMP'; |
192 | is( $MM->canonpath( $path ), File::Spec->canonpath( $path ), |
193 | 'canonpath() eq File::Spec->canonpath' ); |
194 | } |
195 | |
196 | # perl_script() |
197 | my $script_ext = ''; |
198 | my $script_name = 'mm_w32tmp'; |
199 | SKIP: { |
200 | local *SCRIPT; |
201 | skip( "Can't create temp file: $!", 4 ) |
202 | unless open SCRIPT, "> $script_name"; |
203 | print SCRIPT <<'EOSCRIPT'; |
204 | #! perl |
205 | __END__ |
206 | EOSCRIPT |
207 | skip( "Can't write to temp file: $!", 4 ) |
208 | unless close SCRIPT; |
209 | # now start tests: |
210 | is( $MM->perl_script( $script_name ), |
211 | "${script_name}$script_ext", "perl_script ($script_ext)" ); |
212 | |
213 | skip( "Can't rename temp file: $!", 3 ) |
214 | unless rename $script_name, "${script_name}.pl"; |
215 | $script_ext = '.pl'; |
216 | is( $MM->perl_script( $script_name ), |
217 | "${script_name}$script_ext", "perl_script ($script_ext)" ); |
218 | |
219 | skip( "Can't rename temp file: $!", 2 ) |
220 | unless rename "${script_name}$script_ext", "${script_name}.bat"; |
221 | $script_ext = '.bat'; |
222 | is( $MM->perl_script( $script_name ), |
223 | "${script_name}$script_ext", "perl_script ($script_ext)" ); |
224 | |
225 | skip( "Can't rename temp file: $!", 1 ) |
226 | unless rename "${script_name}$script_ext", "${script_name}.noscript"; |
227 | $script_ext = '.noscript'; |
228 | |
229 | isnt( $MM->perl_script( $script_name ), |
230 | "${script_name}$script_ext", |
231 | "not a perl_script anymore ($script_ext)" ); |
232 | is( $MM->perl_script( $script_name ), undef, |
233 | "perl_script ($script_ext) returns empty" ); |
234 | } |
235 | unlink "${script_name}$script_ext" if -f "${script_name}$script_ext"; |
236 | |
237 | |
238 | # pm_to_blib() |
239 | { |
240 | like( $MM->pm_to_blib(), |
241 | qr/^pm_to_blib: \Q$(TO_INST_PM)\E.+\Q$(TOUCH) \E\$@\s+$/ms, |
242 | 'pm_to_blib' ); |
243 | } |
244 | |
245 | # tool_autosplit() |
246 | { |
247 | my %attribs = ( MAXLEN => 255 ); |
248 | like( $MM->tool_autosplit( %attribs ), |
249 | qr/^\#\ Usage:\ \$\(AUTOSPLITFILE\) |
250 | \ FileToSplit\ AutoDirToSplitInto.+ |
251 | AUTOSPLITFILE\ =\ \$\(PERLRUN\)\ .+ |
252 | \$AutoSplit::Maxlen=$attribs{MAXLEN}; |
253 | /xms, |
254 | 'tool_autosplit()' ); |
255 | } |
256 | |
257 | # tools_other() |
258 | { |
259 | ( my $mm_w32 = bless { }, 'MM' )->init_others(); |
260 | |
261 | my $bin_sh = ( $Config{make} =~ /^dmake/i |
262 | ? "" : ($Config{sh} || 'cmd /c') . "\n" ); |
263 | $bin_sh = "SHELL = $bin_sh" if $bin_sh; |
264 | |
265 | my $tools = join "\n", map "$_ = $mm_w32->{ $_ }" |
266 | => qw(CHMOD CP LD MV NOOP RM_F RM_RF TEST_F TOUCH UMASK_NULL DEV_NULL); |
267 | |
268 | like( $mm_w32->tools_other(), |
269 | qr/^\Q$bin_sh$tools/m, |
270 | 'tools_other()' ); |
271 | }; |
272 | |
273 | # xs_o() should look into that |
274 | # top_targets() should look into that |
275 | |
f355267c |
276 | # dist_ci() should look into that |
277 | # dist_core() should look into that |
278 | |
279 | # pasthru() |
280 | { |
281 | my $pastru = "PASTHRU = " . ($Config{make} =~ /^nmake/i ? "-nologo" : ""); |
282 | is( $MM->pasthru(), $pastru, 'pasthru()' ); |
283 | } |
284 | |
285 | package FakeOut; |
286 | |
287 | sub TIEHANDLE { |
288 | bless(\(my $scalar), $_[0]); |
289 | } |
290 | |
291 | sub PRINT { |
292 | my $self = shift; |
293 | $$self .= shift; |
294 | } |
295 | |
296 | __END__ |
297 | |
298 | =head1 NAME |
299 | |
300 | MM_NW5.t - Tests for ExtUtils::MM_NW5 |
301 | |
302 | =head1 TODO |
303 | |
304 | - Methods to still be checked: |
305 | # static_lib() should look into that |
306 | # dynamic_bs() should look into that |
307 | # dynamic_lib() should look into that |
308 | # xs_o() should look into that |
309 | # top_targets() should look into that |
310 | # dist_ci() should look into that |
311 | # dist_core() should look into that |
312 | |
313 | =head1 AUTHOR |
314 | |
315 | 20011228 Abe Timmerman <abe@ztreet.demon.nl> |
316 | |
317 | =cut |