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