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