diff options
author | Michael G. Schwern <schwern@pobox.com> | 2002-03-28 23:12:47 -0500 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2002-03-29 14:45:52 +0000 |
commit | f6d6199cd6711f5e8a8e6c1a57445fa6f848c822 (patch) | |
tree | a3b30650d6c0eec8c7513c42453ae2e7f28cc5b2 /t/lib | |
parent | 798fbbe475389cc5bd681489265a68eee841b426 (diff) | |
download | perl-f6d6199cd6711f5e8a8e6c1a57445fa6f848c822.tar.gz |
MakeMaker sync 5.48_03 -> 5.53_01
Message-ID: <20020329091247.GA7432@blackrider>
(with two nits: (1) change lib/Extutils/Command/MM.pm
in MANIFEST to be lib/ExtUtils/Command/MM.pm (2) Add
@INC to compile.t)
p4raw-id: //depot/perl@15599
Diffstat (limited to 't/lib')
-rw-r--r-- | t/lib/MakeMaker/Test/Utils.pm | 212 | ||||
-rw-r--r-- | t/lib/TieOut.pm | 6 |
2 files changed, 218 insertions, 0 deletions
diff --git a/t/lib/MakeMaker/Test/Utils.pm b/t/lib/MakeMaker/Test/Utils.pm new file mode 100644 index 0000000000..b1de088c83 --- /dev/null +++ b/t/lib/MakeMaker/Test/Utils.pm @@ -0,0 +1,212 @@ +package MakeMaker::Test::Utils; + +use File::Spec; +use strict; +use Config; + +use vars qw($VERSION @ISA @EXPORT); + +require Exporter; +@ISA = qw(Exporter); + +$VERSION = 0.01; + +@EXPORT = qw(which_perl perl_lib makefile_name makefile_backup + make make_run make_macro + ); + +my $Is_VMS = $^O eq 'VMS'; + + +=head1 NAME + +MakeMaker::Test::Utils - Utility routines for testing MakeMaker + +=head1 SYNOPSIS + + use MakeMaker::Test::Utils; + + my $perl = which_perl; + perl_lib; + + my $makefile = makefile_name; + my $makefile_back = makefile_backup; + + my $make = make; + my $make_run = make_run; + make_macro($make, $targ, %macros); + +=head1 DESCRIPTION + +A consolidation of little utility functions used through out the +MakeMaker test suite. + +=head2 Functions + +The following are exported by default. + +=over 4 + +=item B<which_perl> + + my $perl = which_perl; + +Returns a path to perl which is safe to use in a command line, no +matter where you chdir to. + +=cut + +sub which_perl { + my $perl = $^X; + $perl ||= 'perl'; + + # VMS should have 'perl' aliased properly + return $perl if $Is_VMS; + + $perl = File::Spec->rel2abs( $perl ); + + unless( -x $perl ) { + # $^X was probably 'perl' + foreach my $path (File::Spec->path) { + $perl = File::Spec->catfile($path, $^X); + last if -x $perl; + } + } + + return $perl; +} + +=item B<perl_lib> + + perl_lib; + +Sets up environment variables so perl can find its libraries. + +=cut + +my $old5lib = $ENV{PERL5LIB}; +my $had5lib = exists $ENV{PERL5LIB}; +sub perl_lib { + # perl-src/lib/ExtUtils/t/Foo + my $lib = $ENV{PERL_CORE} ? qq{../../../lib} + # ExtUtils-MakeMaker/t/Foo + : qq{../blib/lib}; + $lib = File::Spec->rel2abs($lib); + my @libs = ($lib); + push @libs, $ENV{PERL5LIB} if exists $ENV{PERL5LIB}; + $ENV{PERL5LIB} = join($Config{path_sep}, @libs); + unshift @INC, $lib; +} + +END { + if( $had5lib ) { + $ENV{PERL5LIB} = $old5lib; + } + else { + delete $ENV{PERL5LIB}; + } +} + + +=item B<makefile_name> + + my $makefile = makefile_name; + +MakeMaker doesn't always generate 'Makefile'. It returns what it +should generate. + +=cut + +sub makefile_name { + return $Is_VMS ? 'Descrip.MMS' : 'Makefile'; +} + +=item B<makefile_backup> + + my $makefile_old = makefile_backup; + +Returns the name MakeMaker will use for a backup of the current +Makefile. + +=cut + +sub makefile_backup { + my $makefile = makefile_name; + return $Is_VMS ? $makefile : "$makefile.old"; +} + +=item B<make> + + my $make = make; + +Returns a good guess at the make to run. + +=cut + +sub make { + my $make = $Config{make}; + $make = $ENV{MAKE} if exists $ENV{MAKE}; + + return $make; +} + +=item B<make_run> + + my $make_run = make_run; + +Returns the make to run as with make() plus any necessary switches. + +=cut + +sub make_run { + my $make = make; + $make .= ' -nologo' if $make eq 'nmake'; + + return $make; +} + +=item B<make_macro> + + my $make_cmd = make_macro($make, $target, %macros); + +Returns the command necessary to run $make on the given $target using +the given %macros. + + my $make_test_verbose = make_macro(make_run(), 'test', + TEST_VERBOSE => 1); + +This is important because VMS's make utilities have a completely +different calling convention than Unix or Windows. + +%macros is actually a list of tuples, so the order will be preserved. + +=cut + +sub make_macro { + my($make, $target) = (shift, shift); + + my $is_mms = $make =~ /^MM(K|S)/i; + + my $cmd = $make; + my $macros = ''; + while( my($key,$val) = splice(@_, 0, 2) ) { + if( $is_mms ) { + $macros .= qq{/macro="$key=$val"}; + } + else { + $macros .= qq{ $key=$val}; + } + } + + return $is_mms ? "$make$macros $target" : "$make $target $macros"; +} + +=back + +=head1 AUTHOR + +Michael G Schwern <schwern@pobox.com> + +=cut + +1; diff --git a/t/lib/TieOut.pm b/t/lib/TieOut.pm index 0da80cbb0e..072e8fdef6 100644 --- a/t/lib/TieOut.pm +++ b/t/lib/TieOut.pm @@ -9,6 +9,12 @@ sub PRINT { $$self .= join('', @_); } +sub PRINTF { + my $self = shift; + my $fmt = shift; + $$self .= sprintf $fmt, @_; +} + sub read { my $self = shift; return substr($$self, 0, length($$self), ''); |