Updated Module::Build to 0.36
[p5sagit/p5-mst-13.2.git] / cpan / ExtUtils-MakeMaker / t / MM_NW5.t
1 #!/usr/bin/perl
2
3 BEGIN {
4     unshift @INC, 't/lib';
5 }
6 chdir 't';
7
8
9 use Test::More;
10
11 BEGIN {
12         if ($^O =~ /NetWare/i) {
13                 plan tests => 39;
14         } else {
15                 plan skip_all => 'This is not NW5';
16         }
17 }
18
19 use Config;
20 use File::Spec;
21 use File::Basename;
22 use ExtUtils::MM;
23
24 require_ok( 'ExtUtils::MM_NW5' );
25
26 # Dummy MM object until we have a real MM init method.
27 my $MM = bless {
28                 DIR     => [],
29                 NOECHO  => '@',
30                 XS      => {},
31                 MAKEFILE => 'Makefile',
32                 RM_RF   => 'rm -rf',
33                 MV      => 'mv',
34                }, 'MM';
35
36
37 # replace_manpage_separator() => tr|/|.|s ?
38 {
39     my $man = 'a/path/to//something';
40     ( my $replaced = $man ) =~ tr|/|.|s;
41     is( $MM->replace_manpage_separator( $man ),
42         $replaced, 'replace_manpage_separator()' );
43 }
44
45 # maybe_command()
46 SKIP: {
47     skip( '$ENV{COMSPEC} not set', 2 )
48         unless $ENV{COMSPEC} =~ m!((?:[a-z]:)?[^|<>]+)!i;
49     my $comspec = $1;
50     is( $MM->maybe_command( $comspec ), 
51         $comspec, 'COMSPEC is a maybe_command()' );
52     ( my $comspec2 = $comspec ) =~ s|\..{3}$||;
53     like( $MM->maybe_command( $comspec2 ), 
54           qr/\Q$comspec/i, 
55           'maybe_command() without extension' );
56 }
57
58 my $had_pathext = exists $ENV{PATHEXT};
59 {
60     local $ENV{PATHEXT} = '.exe';
61     ok( ! $MM->maybe_command( 'not_a_command.com' ), 
62         'not a maybe_command()' );
63 }
64 # Bug in Perl.  local $ENV{FOO} won't delete the key afterward.
65 delete $ENV{PATHEXT} unless $had_pathext;
66
67 # file_name_is_absolute() [Does not support UNC-paths]
68 {
69     ok( $MM->file_name_is_absolute( 'SYS:/' ), 
70         'file_name_is_absolute()' );
71     ok( ! $MM->file_name_is_absolute( 'some/path/' ),
72         'not file_name_is_absolute()' );
73
74 }
75
76 # find_perl() 
77 # Should be able to find running perl... $^X is OK on NW5
78 {
79     my $my_perl = $1 if $^X  =~ /(.*)/; # are we in -T or -t?
80     my( $perl, $path ) = fileparse( $my_perl );
81     like( $MM->find_perl( $], [ $perl ], [ $path ] ), 
82           qr/^\Q$my_perl\E$/i, 'find_perl() finds this perl' );
83 }
84
85 # catdir() (calls MM_NW5->canonpath)
86 {
87     my @path_eg = qw( SYS trick dir/now_OK );
88
89     is( $MM->catdir( @path_eg ), 
90          'SYS\\trick\\dir\\now_OK', 'catdir()' );
91     is( $MM->catdir( @path_eg ), 
92         File::Spec->catdir( @path_eg ), 
93         'catdir() eq File::Spec->catdir()' );
94
95 # catfile() (calls MM_NW5->catdir)
96     push @path_eg, 'file.ext';
97
98     is( $MM->catfile( @path_eg ),
99         'SYS\\trick\\dir\\now_OK\\file.ext', 'catfile()' );
100
101     is( $MM->catfile( @path_eg ), 
102         File::Spec->catfile( @path_eg ), 
103         'catfile() eq File::Spec->catfile()' );
104 }
105
106 # init_others(): check if all keys are created and set?
107 # qw( TOUCH CHMOD CP RM_F RM_RF MV NOOP TEST_F LD AR LDLOADLIBS DEV_NUL )
108 {
109     my $mm_w32 = bless( {}, 'MM' );
110     $mm_w32->init_others();
111     my @keys = qw( TOUCH CHMOD CP RM_F RM_RF MV NOOP 
112                    TEST_F LD AR LDLOADLIBS DEV_NULL );
113     for my $key ( @keys ) {
114         ok( $mm_w32->{ $key }, "init_others: $key" );
115     }
116 }
117
118 # constants()
119 {
120     my $mm_w32 = bless {
121         NAME         => 'TestMM_NW5', 
122         VERSION      => '1.00',
123         VERSION_FROM => 'TestMM_NW5',
124         PM           => { 'MM_NW5.pm' => 1 },
125     }, 'MM';
126
127     # XXX Hack until we have a proper init method.
128     # Flesh out some necessary keys in the MM object.
129     foreach my $key (qw(XS C O_FILES H HTMLLIBPODS HTMLSCRIPTPODS
130                         MAN1PODS MAN3PODS PARENT_NAME)) {
131         $mm_w32->{$key} = '';
132     }
133     my $s_PM = join( " \\\n\t", sort keys %{$mm_w32->{PM}} );
134     my $k_PM = join( " \\\n\t", %{$mm_w32->{PM}} );
135
136     like( $mm_w32->constants(),
137           qr|^NAME\ =\ TestMM_NW5\s+VERSION\ =\ 1\.00.+
138              MAKEMAKER\ =\ \Q$INC{'ExtUtils/MakeMaker.pm'}\E\s+
139              MM_VERSION\ =\ \Q$ExtUtils::MakeMaker::VERSION\E.+
140              VERSION_FROM\ =\ TestMM_NW5.+
141              TO_INST_PM\ =\ \Q$s_PM\E\s+
142              PM_TO_BLIB\ =\ \Q$k_PM\E
143           |xs, 'constants()' );
144
145 }
146
147 # path()
148 my $had_path = exists $ENV{PATH};
149 {
150     my @path_eg = ( qw( . .. ), 'SYS:\\Program Files' );
151     local $ENV{PATH} = join ';', @path_eg;
152     ok( eq_array( [ $MM->path() ], [ @path_eg ] ),
153         'path() [preset]' );
154 }
155 # Bug in Perl.  local $ENV{FOO} will not delete key afterwards.
156 delete $ENV{PATH} unless $had_path;
157
158 # static_lib() should look into that
159 # dynamic_bs() should look into that
160 # dynamic_lib() should look into that
161
162 # clean()
163 {
164     my $clean = $Config{cc} =~ /^gcc/i ? 'dll.base dll.exp' : '*.pdb';
165     like( $MM->clean(), qr/^clean ::\s+\Q-$(RM_F) $clean\E\s+$/m,
166           'clean() Makefile target' );
167 }
168
169
170 # init_linker
171 {
172     my $libperl = $Config{libperl} || 'libperl.a';
173     my $export  = '$(BASEEXT).def';
174     my $after   = '';
175     $MM->init_linker;
176
177     is( $MM->{PERL_ARCHIVE},        $libperl,   'PERL_ARCHIVE' );
178     is( $MM->{PERL_ARCHIVE_AFTER},  $after,     'PERL_ARCHIVE_AFTER' );
179     is( $MM->{EXPORT_LIST},         $export,    'EXPORT_LIST' );
180 }
181
182
183 # canonpath()
184 {
185     my $path = 'SYS:/TEMP';
186     is( $MM->canonpath( $path ), File::Spec->canonpath( $path ),
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:
204     is( $MM->perl_script( $script_name ), 
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';
210     is( $MM->perl_script( $script_name ), 
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';
216     is( $MM->perl_script( $script_name ), 
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
223     isnt( $MM->perl_script( $script_name ),
224           "${script_name}$script_ext", 
225           "not a perl_script anymore ($script_ext)" );
226     is( $MM->perl_script( $script_name ), undef,
227         "perl_script ($script_ext) returns empty" );
228 }
229 unlink "${script_name}$script_ext" if -f "${script_name}$script_ext";
230
231
232 # pm_to_blib()
233 {
234     like( $MM->pm_to_blib(),
235           qr/^pm_to_blib: \Q$(TO_INST_PM)\E.+\Q$(TOUCH) \E\$@\s+$/ms,
236           'pm_to_blib' );
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\ =\ \$\(PERLRUN\)\ .+
246              \$AutoSplit::Maxlen=$attribs{MAXLEN};
247           /xms,
248           'tool_autosplit()' );
249 }
250
251
252 # xs_o() should look into that
253 # top_targets() should look into that
254
255 # dist_ci() should look into that
256 # dist_core() should look into that
257
258 # pasthru()
259 {
260     my $pastru = "PASTHRU = " . ($Config{make} =~ /^nmake/i ? "-nologo" : "");
261     is( $MM->pasthru(), $pastru, 'pasthru()' );
262 }
263
264 package FakeOut;
265
266 sub TIEHANDLE {
267         bless(\(my $scalar), $_[0]);
268 }
269
270 sub PRINT {
271         my $self = shift;
272         $$self .= shift;
273 }
274
275 __END__
276
277 =head1 NAME
278
279 MM_NW5.t - Tests for ExtUtils::MM_NW5
280
281 =head1 TODO
282
283  - Methods to still be checked:
284  # static_lib() should look into that
285  # dynamic_bs() should look into that
286  # dynamic_lib() should look into that
287  # xs_o() should look into that
288  # top_targets() should look into that
289  # dist_ci() should look into that
290  # dist_core() should look into that
291
292 =head1 AUTHOR
293
294 20011228 Abe Timmerman <abe@ztreet.demon.nl>
295
296 =cut