ExtUtils::MakeMaker 6.55_02
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / t / MM_Win32.t
index 846cca2..c779da2 100644 (file)
@@ -1,15 +1,22 @@
-#!perl
+#!/usr/bin/perl
 
 BEGIN {
-       chdir 't' if -d 't';
-       @INC = '../lib';
+    if( $ENV{PERL_CORE} ) {
+        chdir 't' if -d 't';
+        @INC = '../lib';
+    }
+    else {
+        unshift @INC, 't/lib';
+    }
 }
+chdir 't';
 
+use strict;
 use Test::More;
 
 BEGIN {
        if ($^O =~ /MSWin32/i) {
-               plan tests => 44;
+               plan tests => 49;
        } else {
                plan skip_all => 'This is not Win32';
        }
@@ -18,34 +25,27 @@ BEGIN {
 use Config;
 use File::Spec;
 use File::Basename;
-
-# Does this mimic ExtUtils::MakeMaker ok?
-{
-    @MM::ISA = qw(
-        ExtUtils::MM_Unix 
-        ExtUtils::Liblist::Kid 
-        ExtUtils::MakeMaker
-    );
-    # MM package faked up by messy MI entanglement
-    package MM;
-    sub DESTROY {}
-}
+use ExtUtils::MM;
 
 require_ok( 'ExtUtils::MM_Win32' );
 
-# test import of $Verbose and &neatvalue
-can_ok( 'MM', 'neatvalue' );
-is( $ExtUtils::MM_Win32::Verbose, $ExtUtils::MakeMaker::Verbose, 
-       'ExtUtils::MM_Win32 should import $Verbose from ExtUtils::MakeMaker' );
-
+# Dummy MM object until we have a real MM init method.
+my $MM = bless {
+                DIR     => [],
+                NOECHO  => '@',
+                XS      => {},
+                MAKEFILE => 'Makefile',
+                RM_RF   => 'rm -rf',
+                MV      => 'mv',
+                MAKE    => $Config{make}
+               }, 'MM';
 
-##### Start new tests at the top of MM_Win32
 
 # replace_manpage_separator() => tr|/|.|s ?
 {
     my $man = 'a/path/to//something';
     ( my $replaced = $man ) =~ tr|/|.|s;
-    is( MM->replace_manpage_separator( $man ),
+    is( $MM->replace_manpage_separator( $man ),
         $replaced, 'replace_manpage_separator()' );
 }
 
@@ -54,24 +54,28 @@ SKIP: {
     skip( '$ENV{COMSPEC} not set', 2 )
         unless $ENV{COMSPEC} =~ m!((?:[a-z]:)?[^|<>]+)!i;
     my $comspec = $1;
-    is( MM->maybe_command( $comspec ), 
+    is( $MM->maybe_command( $comspec ), 
         $comspec, 'COMSPEC is a maybe_command()' );
     ( my $comspec2 = $comspec ) =~ s|\..{3}$||;
-    like( MM->maybe_command( $comspec2 ), 
+    like( $MM->maybe_command( $comspec2 ), 
           qr/\Q$comspec/i, 
           'maybe_command() without extension' );
 }
+
+my $had_pathext = exists $ENV{PATHEXT};
 {
     local $ENV{PATHEXT} = '.exe';
-    ok( ! MM->maybe_command( 'not_a_command.com' ), 
+    ok( ! $MM->maybe_command( 'not_a_command.com' ), 
         'not a maybe_command()' );
 }
+# Bug in Perl.  local $ENV{FOO} won't delete the key afterward.
+delete $ENV{PATHEXT} unless $had_pathext;
 
 # file_name_is_absolute() [Does not support UNC-paths]
 {
-    ok( MM->file_name_is_absolute( 'C:/' ), 
+    ok( $MM->file_name_is_absolute( 'C:/' ), 
         'file_name_is_absolute()' );
-    ok( ! MM->file_name_is_absolute( 'some/path/' ),
+    ok( ! $MM->file_name_is_absolute( 'some/path/' ),
         'not file_name_is_absolute()' );
 
 }
@@ -81,7 +85,7 @@ SKIP: {
 {
     my $my_perl = $1 if $^X  =~ /(.*)/; # are we in -T or -t?
     my( $perl, $path ) = fileparse( $my_perl );
-    like( MM->find_perl( $], [ $perl ], [ $path ] ), 
+    like( $MM->find_perl( $], [ $perl ], [ $path ], 0 ),
           qr/^\Q$my_perl\E$/i, 'find_perl() finds this perl' );
 }
 
@@ -89,19 +93,19 @@ SKIP: {
 {
     my @path_eg = qw( c: trick dir/now_OK );
 
-    is( MM->catdir( @path_eg ), 
+    is( $MM->catdir( @path_eg ), 
          'C:\\trick\\dir\\now_OK', 'catdir()' );
-    is( MM->catdir( @path_eg ), 
+    is( $MM->catdir( @path_eg ), 
         File::Spec->catdir( @path_eg ), 
         'catdir() eq File::Spec->catdir()' );
 
 # catfile() (calls MM_Win32->catdir)
     push @path_eg, 'file.ext';
 
-    is( MM->catfile( @path_eg ),
+    is( $MM->catfile( @path_eg ),
         'C:\\trick\\dir\\now_OK\\file.ext', 'catfile()' );
 
-    is( MM->catfile( @path_eg ), 
+    is( $MM->catfile( @path_eg ), 
         File::Spec->catfile( @path_eg ), 
         'catfile() eq File::Spec->catfile()' );
 }
@@ -109,7 +113,7 @@ SKIP: {
 # init_others(): check if all keys are created and set?
 # qw( TOUCH CHMOD CP RM_F RM_RF MV NOOP TEST_F LD AR LDLOADLIBS DEV_NUL )
 {
-    my $mm_w32 = bless( {}, 'MM' );
+    my $mm_w32 = bless( { BASEEXT => 'Foo' }, 'MM' );
     $mm_w32->init_others();
     my @keys = qw( TOUCH CHMOD CP RM_F RM_RF MV NOOP 
                    TEST_F LD AR LDLOADLIBS DEV_NULL );
@@ -119,32 +123,49 @@ SKIP: {
 }
 
 # constants()
+# XXX this test is probably useless now that we can call individual
+# init_* methods and check the keys in $mm_w32 directly
 {
     my $mm_w32 = bless {
         NAME         => 'TestMM_Win32', 
         VERSION      => '1.00',
-        VERSION_FROM => 'TestMM_Win32',
         PM           => { 'MM_Win32.pm' => 1 },
     }, 'MM';
+
+    # XXX Hack until we have a proper init method.
+    # Flesh out some necessary keys in the MM object.
+    @{$mm_w32}{qw(XS MAN1PODS MAN3PODS)} = ({}) x 3;
+    @{$mm_w32}{qw(C O_FILES H)}          = ([]) x 3;
+    @{$mm_w32}{qw(PARENT_NAME)}          = ('') x 3;
+    $mm_w32->{FULLEXT} = 'TestMM_Win32';
+    $mm_w32->{BASEEXT} = 'TestMM_Win32';
+
+    $mm_w32->init_VERSION;
+    $mm_w32->init_linker;
+    $mm_w32->init_INST;
+    $mm_w32->init_xs;
+
     my $s_PM = join( " \\\n\t", sort keys %{$mm_w32->{PM}} );
     my $k_PM = join( " \\\n\t", %{$mm_w32->{PM}} );
 
-    like( $mm_w32->constants(),
-          qr/^NAME\ =\ TestMM_Win32\s+VERSION\ =\ 1\.00.+
-             MAKEMAKER\ =\ $INC{'ExtUtils\MakeMaker.pm'}\s+
-             MM_VERSION\ =\ $ExtUtils::MakeMaker::VERSION.+
-             VERSION_FROM\ =\ TestMM_Win32.+
-             TO_INST_PM\ =\ \Q$s_PM\E\s+
-             PM_TO_BLIB\ =\ \Q$k_PM\E
-          /xs, 'constants()' );
-
+    my $constants = $mm_w32->constants;
+
+    foreach my $regex (
+         qr|^NAME       \s* = \s* TestMM_Win32 \s* $|xms,
+         qr|^VERSION    \s* = \s* 1\.00 \s* $|xms,
+         qr|^MAKEMAKER  \s* = \s* \Q$INC{'ExtUtils/MakeMaker.pm'}\E \s* $|xms,
+         qr|^MM_VERSION \s* = \s* \Q$ExtUtils::MakeMaker::VERSION\E \s* $|xms,
+         qr|^TO_INST_PM \s* = \s* \Q$s_PM\E \s* $|xms,
+         qr|^PM_TO_BLIB \s* = \s* \Q$k_PM\E \s* $|xms,
+        )
+    {
+        like( $constants, $regex, 'constants() check' );
+    }
 }
 
 # path()
 {
-    my @path_eg = ( qw( . .. ), 'C:\\Program Files' );
-    local $ENV{PATH} = join ';', @path_eg;
-    ok( eq_array( [ MM->path() ], [ @path_eg ] ),
+    ok( eq_array( [ $MM->path() ], [ File::Spec->path ] ),
         'path() [preset]' );
 }
 
@@ -152,30 +173,23 @@ SKIP: {
 # dynamic_bs() should look into that
 # dynamic_lib() should look into that
 
-# clean()
-{
-    my $clean = $Config{cc} =~ /^gcc/i ? 'dll.base dll.exp' : '*.pdb';
-    like( MM->clean(), qr/^clean ::\s+\Q-$(RM_F) $clean\E\s+$/m,
-          'clean() Makefile target' );
-}
-
-# perl_archive()
-{
-    my $libperl = $Config{libperl} || 'libperl.a';
-    is( MM->perl_archive(), File::Spec->catfile('$(PERL_INC)', $libperl ),
-           'perl_archive() should respect libperl setting' );
-}
-
-# export_list
+# init_linker
 {
-    my $mm_w32 = bless { BASEEXT => 'someext' }, 'ExtUtils::MM_Win32';
-    is( $mm_w32->export_list(), 'someext.def', 'export_list()' );
+    my $libperl = File::Spec->catfile('$(PERL_INC)', 
+                                      $Config{libperl} || 'libperl.a');
+    my $export  = '$(BASEEXT).def';
+    my $after   = '';
+    $MM->init_linker;
+
+    is( $MM->{PERL_ARCHIVE},        $libperl,   'PERL_ARCHIVE' );
+    is( $MM->{PERL_ARCHIVE_AFTER},  $after,     'PERL_ARCHIVE_AFTER' );
+    is( $MM->{EXPORT_LIST},         $export,    'EXPORT_LIST' );
 }
 
 # canonpath()
 {
     my $path = 'c:\\Program Files/SomeApp\\Progje.exe';
-    is( MM->canonpath( $path ), File::Spec->canonpath( $path ),
+    is( $MM->canonpath( $path ), File::Spec->canonpath( $path ),
            'canonpath() eq File::Spec->canonpath' );
 }
 
@@ -193,110 +207,67 @@ EOSCRIPT
     skip( "Can't write to temp file: $!", 4 )
         unless close SCRIPT;
     # now start tests:
-    is( MM->perl_script( $script_name ), 
+    is( $MM->perl_script( $script_name ), 
         "${script_name}$script_ext", "perl_script ($script_ext)" );
 
     skip( "Can't rename temp file: $!", 3 )
         unless rename $script_name, "${script_name}.pl";
     $script_ext = '.pl';
-    is( MM->perl_script( $script_name ), 
+    is( $MM->perl_script( $script_name ), 
         "${script_name}$script_ext", "perl_script ($script_ext)" );
 
     skip( "Can't rename temp file: $!", 2 )
         unless rename "${script_name}$script_ext", "${script_name}.bat";
     $script_ext = '.bat';
-    is( MM->perl_script( $script_name ), 
+    is( $MM->perl_script( $script_name ), 
         "${script_name}$script_ext", "perl_script ($script_ext)" );
 
     skip( "Can't rename temp file: $!", 1 )
         unless rename "${script_name}$script_ext", "${script_name}.noscript";
     $script_ext = '.noscript';
 
-    isnt( MM->perl_script( $script_name ),
+    isnt( $MM->perl_script( $script_name ),
           "${script_name}$script_ext", 
           "not a perl_script anymore ($script_ext)" );
-    is( MM->perl_script( $script_name ), undef,
+    is( $MM->perl_script( $script_name ), undef,
         "perl_script ($script_ext) returns empty" );
 }
 unlink "${script_name}$script_ext" if -f "${script_name}$script_ext";
 
-
-# pm_to_blib()
-{
-    like( MM->pm_to_blib(),
-          qr/^pm_to_blib: \Q$(TO_INST_PM)\E.+\Q$(TOUCH) \E\$@\s+$/ms,
-          'pm_to_blib' );
-}
-
-# test_via_harness()
-{
-    like( MM->test_via_harness( $^X, 'MM_Win32.t' ),
-          qr/^\t\Q$^X\E \-Mblib.+"use Test::Harness.+MM_Win32.t\n$/,
-          'test_via_harness()' );
-}
-
-# tool_autosplit()
+# is_make_type()
 {
-    my %attribs = ( MAXLEN => 255 );
-    like( MM->tool_autosplit( %attribs ),
-          qr/^\#\ Usage:\ \$\(AUTOSPLITFILE\)
-             \ FileToSplit\ AutoDirToSplitInto.+
-             AUTOSPLITFILE\ =\ \$\(PERL\)\ 
-             "\-I\$\(PERL_ARCHLIB\)"\ "\-I\$\(PERL_LIB\)".+
-             \$AutoSplit::Maxlen=$attribs{MAXLEN};
-          /xms,
-          'tool_autosplit()' );
-}
-
-# tools_other()
-{
-    ( my $mm_w32 = bless { }, 'MM' )->init_others();
-        
-    my $bin_sh = ( $Config{make} =~ /^dmake/i 
-               ? "" : ($Config{sh} || 'cmd /c') . "\n" );
-    $bin_sh = "SHELL = $bin_sh" if $bin_sh;
-
-    my $tools = join "\n", map "$_ = $mm_w32->{ $_ }"
-       => qw(CHMOD CP LD MV NOOP RM_F RM_RF TEST_F TOUCH UMASK_NULL DEV_NULL);
-
-    like( $mm_w32->tools_other(),
-          qr/^\Q$bin_sh$tools/m,
-          'tools_other()' );
-};
+    # Check for literal nmake
+    SKIP: {
+        skip("Not using 'nmake'", 2) unless $Config{make} eq 'nmake';
+        ok(   $MM->is_make_type('nmake'), '->is_make_type(nmake) true'  );
+       ok( ! $MM->is_make_type('dmake'), '->is_make_type(dmake) false' );
+    }
 
-# xs_o() should look into that
-# top_targets() should look into that
+    # Check for literal nmake
+    SKIP: {
+        skip("Not using /nmake/", 2) unless $Config{make} =~ /nmake/;
+        ok(   $MM->is_make_type('nmake'), '->is_make_type(nmake) true'  );
+       ok( ! $MM->is_make_type('dmake'), '->is_make_type(dmake) false' );
+    }
 
-# htmlify_pods()
-{
-    my $mm_w32 = bless {
-        HTMLLIBPODS    => { 'MM_Win32.pm' => 1 },
-        HTMLSCRIPTPODS => { 'MM_Win32.t'  => 1 },
-        PERL_SRC       => undef,
-    }, 'MM';
-    my $pods = join " \\\n\t", keys %{$mm_w32->{HTMLLIBPODS}}, 
-                               keys %{$mm_w32->{HTMLSCRIPTPODS}};
+    # Check for literal dmake
+    SKIP: {
+        skip("Not using 'dmake'", 2) unless $Config{make} eq 'dmake';
+        ok(   $MM->is_make_type('dmake'), '->is_make_type(dmake) true'  );
+       ok( ! $MM->is_make_type('nmake'), '->is_make_type(nmake) false' );
+    }
 
-    my $pod2html_exe = $mm_w32->catfile($Config{scriptdirexp},'pod2html');
-    unless ( $pod2html_exe = $mm_w32->perl_script( $pod2html_exe ) ) {
-        $pod2html_exe = '-S pod2html';
+    # Check for literal dmake
+    SKIP: {
+        skip("Not using /dmake/", 2) unless $Config{make} =~ /dmake/;
+        ok(   $MM->is_make_type('dmake'), '->is_make_type(dmake) true'  );
+       ok( ! $MM->is_make_type('nmake'), '->is_make_type(nmake) false' );
     }
 
-    like( $mm_w32->htmlifypods(),
-          qr/^POD2HTML_EXE\ =\ \Q$pod2html_exe\E\n
-             POD2HTML\ =.+\n
-             htmlifypods\ :\ pure_all\ \Q$pods\E
-          /xs,
-          'htmlifypods() Makefile target' );
 }
 
-# manifypods()
-{
-    my $mm_w32 = bless { NOECHO    => '' }, 'MM';
-    like( $mm_w32->manifypods(),
-          qr/^\nmanifypods :\n\t\$\Q(NOOP)\E\n$/,
-          'manifypods() Makefile target' );
-}
+# xs_o() should look into that
+# top_targets() should look into that
 
 # dist_ci() should look into that
 # dist_core() should look into that
@@ -304,7 +275,7 @@ unlink "${script_name}$script_ext" if -f "${script_name}$script_ext";
 # pasthru()
 {
     my $pastru = "PASTHRU = " . ($Config{make} =~ /^nmake/i ? "-nologo" : "");
-    is( MM->pasthru(), $pastru, 'pasthru()' );
+    is( $MM->pasthru(), $pastru, 'pasthru()' );
 }
 
 package FakeOut;