Author: jkeenan Date: Sun Jan 6 05:39:52 2008 New Revision: 24598 Added: trunk/t/configure/143-auto_gmp-03.t (contents, props changed) Modified: trunk/MANIFEST trunk/config/auto/gmp.pm
Log: Refactor more code out of runstep() to make it more testable; create _evaluate_cc_run. Add 143-auto_gmp-03.t to test this code. Modified: trunk/MANIFEST ============================================================================== --- trunk/MANIFEST (original) +++ trunk/MANIFEST Sun Jan 6 05:39:52 2008 @@ -1,7 +1,7 @@ # ex: set ro: # $Id$ # -# generated by tools/dev/mk_manifest_and_skip.pl Sat Jan 5 17:12:09 2008 UT +# generated by tools/dev/mk_manifest_and_skip.pl Sun Jan 6 13:38:33 2008 UT # # See tools/dev/install_files.pl for documentation on the # format of this file. @@ -3276,6 +3276,7 @@ t/configure/142-auto_aio-04.t [] t/configure/143-auto_gmp-01.t [] t/configure/143-auto_gmp-02.t [] +t/configure/143-auto_gmp-03.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 Sun Jan 6 05:39:52 2008 @@ -26,6 +26,9 @@ $data{description} = q{Determining if your platform supports GMP}; $data{args} = [ qw( verbose without-gmp ) ]; $data{result} = q{}; + $data{cc_run_expected} = +"6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151 0\n"; + return \%data; } @@ -63,19 +66,17 @@ my $has_gmp = 0; if ( !$@ ) { my $test = $conf->cc_run(); - if ( $test eq -"6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151 0\n" - ) - { - $has_gmp = 1; - print " (yes) " if $verbose; - $self->set_result('yes'); - - $conf->data->set( - gmp => 'define', - HAS_GMP => $has_gmp, - ); - } +# if ( $test eq $self->{cc_run_expected}) { +# $has_gmp = 1; +# print " (yes) " if $verbose; +# $self->set_result('yes'); +# +# $conf->data->set( +# gmp => 'define', +# HAS_GMP => $has_gmp, +# ); +# } + $has_gmp = $self->_evaluate_cc_run( $conf, $test, $has_gmp, $verbose ); } unless ($has_gmp) { @@ -120,6 +121,21 @@ return 1; } +sub _evaluate_cc_run { + my ($self, $conf, $test, $has_gmp, $verbose) = @_; + if ( $test eq $self->{cc_run_expected} ) { + $has_gmp = 1; + print " (yes) " if $verbose; + $self->set_result('yes'); + + $conf->data->set( + gmp => 'define', + HAS_GMP => $has_gmp, + ); + } + return $has_gmp; +} + 1; # Local Variables: Added: trunk/t/configure/143-auto_gmp-03.t ============================================================================== --- (empty file) +++ trunk/t/configure/143-auto_gmp-03.t Sun Jan 6 05:39:52 2008 @@ -0,0 +1,120 @@ +#! perl +# Copyright (C) 2007, The Perl Foundation. +# $Id$ +# 143-auto_gmp-03.t + +use strict; +use warnings; +use Test::More tests => 19; +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); +use IO::CaptureOutput qw| capture |; + +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" ); + +my ($test, $has_gmp, $verbose); + +$test = $step->{cc_run_expected}; +$has_gmp = 0; +$verbose = undef; +$has_gmp = $step->_evaluate_cc_run($conf, $test, $has_gmp, $verbose); +is($step->result, 'yes', "Got expected result"); +is($conf->data->get('gmp'), 'define', "Expected value set for 'gmp'"); +is($conf->data->get('HAS_GMP'), 1, "Expected value set for 'HAS_GMP'"); +# prepare for next test +$conf->data->set('gmp' => undef); +$conf->data->set('HAS_GMP' => undef); +$step->set_result(undef); + +$test = '12345'; +$has_gmp = 0; +$verbose = undef; +$has_gmp = $step->_evaluate_cc_run($conf, $test, $has_gmp, $verbose); +ok(! defined($step->result), "Result undefined as expected"); +is($has_gmp, 0, "gmp status unchanged"); + +{ + my $stdout; + $test = $step->{cc_run_expected}; + $has_gmp = 0; + $verbose = 1; + capture( + sub { $has_gmp = + $step->_evaluate_cc_run($conf, $test, $has_gmp, $verbose); }, + \$stdout, + ); + is($step->result, 'yes', "Got expected result"); + is($conf->data->get('gmp'), 'define', "Expected value set for 'gmp'"); + is($conf->data->get('HAS_GMP'), 1, "Expected value set for 'HAS_GMP'"); + like($stdout, qr/\(yes\)/, "Got expected verbose output"); + # prepare for next test + $conf->data->set('gmp' => undef); + $conf->data->set('HAS_GMP' => undef); + $step->set_result(undef); +} + +pass("Completed all tests in $0"); + +################### DOCUMENTATION ################### + +=head1 NAME + +143-auto_gmp-03.t - test config::auto::gmp + +=head1 SYNOPSIS + + % prove t/configure/143-auto_gmp-03.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: