Author: jkeenan Date: Sat Jan 5 09:17:06 2008 New Revision: 24565 Added: trunk/t/configure/143-auto_gmp-02.t (contents, props changed) Modified: trunk/MANIFEST trunk/config/auto/gmp.pm trunk/t/configure/143-auto_gmp-01.t
Log: Refactor some internals of runstep() into _handle_mswin32() and _handle_darwin() to make OS-specific code more testable. Add new test file t/configure/143-auto_gmp-02.t to test these internal subs. Modified: trunk/MANIFEST ============================================================================== --- trunk/MANIFEST (original) +++ trunk/MANIFEST Sat Jan 5 09:17:06 2008 @@ -1,7 +1,7 @@ # ex: set ro: # $Id$ # -# generated by tools/dev/mk_manifest_and_skip.pl Sat Jan 5 14:38:15 2008 UT +# generated by tools/dev/mk_manifest_and_skip.pl Sat Jan 5 17:12:09 2008 UT # # See tools/dev/install_files.pl for documentation on the # format of this file. @@ -3275,6 +3275,7 @@ t/configure/142-auto_aio-03.t [] t/configure/142-auto_aio-04.t [] t/configure/143-auto_gmp-01.t [] +t/configure/143-auto_gmp-02.t [] t/configure/144-auto_readline-01.t [] t/configure/145-auto_gdbm-01.t [] t/configure/146-auto_snprintf-01.t [] Modified: trunk/config/auto/gmp.pm ============================================================================== --- trunk/config/auto/gmp.pm (original) +++ trunk/config/auto/gmp.pm Sat Jan 5 09:17:06 2008 @@ -36,7 +36,7 @@ qw| verbose without-gmp - | + | ); if ($without) { @@ -52,29 +52,11 @@ my $osname = $conf->data->get_p5('OSNAME'); - if ( $osname =~ /mswin32/i ) { - if ( $cc =~ /^gcc/i ) { - $conf->data->add( ' ', libs => '-lgmp' ); - } - else { - $conf->data->add( ' ', libs => 'gmp.lib' ); - } - } - else { - $conf->data->add( ' ', libs => '-lgmp' ); - } + _handle_mswin32($conf, $osname, $cc); # On OS X check the presence of the gmp header in the standard # Fink location. - if ( $osname =~ /darwin/ ) { - my $fink_lib_dir = $conf->data->get('fink_lib_dir'); - my $fink_include_dir = $conf->data->get('fink_include_dir'); - if ( -f "$fink_include_dir/gmp.h" ) { - $conf->data->add( ' ', linkflags => "-L$fink_lib_dir" ); - $conf->data->add( ' ', ldflags => "-L$fink_lib_dir" ); - $conf->data->add( ' ', ccflags => "-I$fink_include_dir" ); - } - } + _handle_darwin($conf, $osname); $conf->cc_gen('config/auto/gmp/gmp.in'); eval { $conf->cc_build(); }; @@ -108,6 +90,36 @@ return 1; } +sub _handle_mswin32 { + my ($conf, $osname, $cc) = @_; + if ( $osname =~ /mswin32/i ) { + if ( $cc =~ /^gcc/i ) { + $conf->data->add( ' ', libs => '-lgmp' ); + } + else { + $conf->data->add( ' ', libs => 'gmp.lib' ); + } + } + else { + $conf->data->add( ' ', libs => '-lgmp' ); + } + return 1; +} + +sub _handle_darwin { + my ($conf, $osname) = @_; + if ( $osname =~ /darwin/ ) { + my $fink_lib_dir = $conf->data->get('fink_lib_dir'); + my $fink_include_dir = $conf->data->get('fink_include_dir'); + if ( -f "$fink_include_dir/gmp.h" ) { + $conf->data->add( ' ', linkflags => "-L$fink_lib_dir" ); + $conf->data->add( ' ', ldflags => "-L$fink_lib_dir" ); + $conf->data->add( ' ', ccflags => "-I$fink_include_dir" ); + } + } + return 1; +} + 1; # Local Variables: Modified: trunk/t/configure/143-auto_gmp-01.t ============================================================================== --- trunk/t/configure/143-auto_gmp-01.t (original) +++ trunk/t/configure/143-auto_gmp-01.t Sat Jan 5 09:17:06 2008 @@ -16,8 +16,7 @@ =for hints_for_testing The documentation for this package is skimpy; please try to improve it, e.g., by providing a link to an introduction -to the GNU MP library. Please consider the issues raised in -http://rt.perl.org/rt3/Ticket/Display.html?id=43134. +to the GNU MP library. =cut @@ -38,7 +37,7 @@ $conf->options->set( %{$args} ); my ( $task, $step_name, $step); -$task = $conf->steps->[1]; +$task = $conf->steps->[-1]; $step_name = $task->step; $step = $step_name->new(); Added: trunk/t/configure/143-auto_gmp-02.t ============================================================================== --- (empty file) +++ trunk/t/configure/143-auto_gmp-02.t Sat Jan 5 09:17:06 2008 @@ -0,0 +1,153 @@ +#! perl +# Copyright (C) 2007, The Perl Foundation. +# $Id$ +# 143-auto_gmp-02.t + +use strict; +use warnings; +use Test::More tests => 31; +use Carp; +use Cwd; +use File::Temp qw( tempdir ); +use lib qw( lib t/configure/testlib ); +use_ok('config::init::defaults'); +use_ok('config::auto::gmp'); +use Parrot::Configure; +use Parrot::Configure::Options qw( process_options ); +use Parrot::Configure::Test qw( test_step_thru_runstep); + +my $args = process_options( + { + argv => [ ], + mode => q{configure}, + } +); + +my $conf = Parrot::Configure->new; + +test_step_thru_runstep( $conf, q{init::defaults}, $args ); + +my $pkg = q{auto::gmp}; + +$conf->add_steps($pkg); +$conf->options->set( %{$args} ); + +my ( $task, $step_name, $step); +$task = $conf->steps->[-1]; +$step_name = $task->step; + +$step = $step_name->new(); +ok( defined $step, "$step_name constructor returned defined value" ); +isa_ok( $step, $step_name ); +ok( $step->description(), "$step_name has description" ); + +# Mock values for OS and C-compiler +my ($osname, $cc); +$osname = 'mswin32'; +$cc = 'gcc'; +ok(auto::gmp::_handle_mswin32($conf, $osname, $cc), + "_handle_mswin32() returned true value"); +like($conf->data->get( 'libs' ), qr/-lgmp/, + "'libs' modified as expected"); + +$osname = 'mswin32'; +$cc = 'cc'; +ok(auto::gmp::_handle_mswin32($conf, $osname, $cc), + "_handle_mswin32() returned true value"); +like($conf->data->get( 'libs' ), qr/gmp\.lib/, + "'libs' modified as expected"); + +$osname = 'foobar'; +$cc = undef; +ok(auto::gmp::_handle_mswin32($conf, $osname, $cc), + "_handle_mswin32() returned true value"); +like($conf->data->get( 'libs' ), qr/-lgmp/, + "'libs' modified as expected"); + +my ($flagsbefore, $flagsafter); +$osname = 'foobar'; +$flagsbefore = $conf->data->get( 'linkflags' ); +ok(auto::gmp::_handle_darwin($conf, $osname), + "handle_darwin() returned true value"); +$flagsafter = $conf->data->get( 'linkflags' ); +is($flagsbefore, $flagsafter, "No change in linkflags, as expected"); + +my $cwd = cwd(); +{ + my $tdir = tempdir( CLEANUP => 1 ); + ok(chdir $tdir, "Able to change to temporary directory"); + ok( (mkdir 'lib'), "Able to make lib directory"); + ok( (mkdir 'include'), "Able to make include directory"); + $conf->data->set('fink_lib_dir' => qq{$tdir/lib}); + $conf->data->set('fink_include_dir' => qq{$tdir/include}); + $osname = 'darwin'; + $flagsbefore = $conf->data->get( 'linkflags' ); + ok(auto::gmp::_handle_darwin($conf, $osname), + "handle_darwin() returned true value"); + $flagsafter = $conf->data->get( 'linkflags' ); + is($flagsbefore, $flagsafter, "No change in linkflags, as expected"); + + ok(chdir $cwd, "Able to change back to original directory after testing"); +} + +{ + my $tdir2 = tempdir( CLEANUP => 1 ); + ok(chdir $tdir2, "Able to change to temporary directory"); + ok( (mkdir 'lib'), "Able to make lib directory"); + ok( (mkdir 'include'), "Able to make include directory"); + my $libdir = qq{$tdir2/lib}; + my $includedir = qq{$tdir2/include}; + $conf->data->set('fink_lib_dir' => $libdir); + $conf->data->set('fink_include_dir' => $includedir); + my $foo = qq{$includedir/gmp.h}; + open my $FH, ">", $foo or croak "Could not open for writing"; + print $FH "Hello world\n"; + close $FH or croak "Could not close after writing"; + + $osname = 'darwin'; + $flagsbefore = $conf->data->get( 'linkflags' ); + ok(auto::gmp::_handle_darwin($conf, $osname), + "handle_darwin() returned true value"); + $flagsafter = $conf->data->get( 'linkflags' ); + isnt($flagsbefore, $flagsafter, "Change in linkflags, as expected"); + like($conf->data->get( 'linkflags' ), qr/-L$libdir/, + "'linkflags' modified as expected"); + + ok(chdir $cwd, "Able to change back to original directory after testing"); +} + +pass("Completed all tests in $0"); + +################### DOCUMENTATION ################### + +=head1 NAME + +143-auto_gmp-02.t - test config::auto::gmp + +=head1 SYNOPSIS + + % prove t/configure/143-auto_gmp-02.t + +=head1 DESCRIPTION + +The files in this directory test functionality used by F<Configure.pl>. + +The tests in this file test config::auto::gmp in the case where the +C<--without-gmp> option is set. + +=head1 AUTHOR + +James E Keenan + +=head1 SEE ALSO + +config::auto::gmp, F<Configure.pl>. + +=cut + +# Local Variables: +# mode: cperl +# cperl-indent-level: 4 +# fill-column: 100 +# End: +# vim: expandtab shiftwidth=4: