Skip to content

Commit

Permalink
Further refactoring to improve testability. Statement coverage up to …
Browse files Browse the repository at this point in the history
…93%, which, given that we can't directly test the C code, is as about as good as we're going to do.

git-svn-id: https://svn.parrot.org/parrot/branches/auto_frames_refactor@41440 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
jkeenan committed Sep 24, 2009
1 parent a237060 commit 9330765
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 26 deletions.
49 changes: 27 additions & 22 deletions config/auto/frames.pm
Expand Up @@ -33,6 +33,30 @@ sub runstep {


my $can_build_call_frames = _call_frames_buildable($conf); my $can_build_call_frames = _call_frames_buildable($conf);


$self->_handle_can_build_call_frames( $conf, $can_build_call_frames );

return 1;
}

sub _call_frames_buildable {
my $conf = shift;
my $osname = $conf->data->get('osname');
my $cpuarch = $conf->data->get('cpuarch');
my $nvsize = $conf->data->get('nvsize');
my $can_build_call_frames;

if (defined $conf->options->get('buildframes')) {
$can_build_call_frames = $conf->options->get('buildframes');
}
else {
$can_build_call_frames = ($nvsize == 8 && $cpuarch eq 'i386'
&& $osname ne 'darwin');
}
return $can_build_call_frames;
}

sub _handle_can_build_call_frames {
my ($self, $conf, $can_build_call_frames) = @_;
if ( $can_build_call_frames ) { if ( $can_build_call_frames ) {
$conf->data->set( $conf->data->set(
cc_build_call_frames => '-DCAN_BUILD_CALL_FRAMES', cc_build_call_frames => '-DCAN_BUILD_CALL_FRAMES',
Expand Down Expand Up @@ -61,34 +85,15 @@ sub runstep {
else { else {
$conf->data->set( has_exec_protect => 0 ); $conf->data->set( has_exec_protect => 0 );
} }
$self->set_result( 'yes' );
} }
else { else {
$conf->data->set( $conf->data->set( cc_build_call_frames => '');
cc_build_call_frames => '', $self->set_result( 'no' );
);
} }

$self->set_result($can_build_call_frames?'yes':'no');
return 1; return 1;
} }


sub _call_frames_buildable {
my $conf = shift;
my $osname = $conf->data->get('osname');
my $cpuarch = $conf->data->get('cpuarch');
my $nvsize = $conf->data->get('nvsize');
my $can_build_call_frames;

if (defined $conf->options->get('buildframes')) {
$can_build_call_frames = $conf->options->get('buildframes');
}
else {
$can_build_call_frames = ($nvsize == 8 && $cpuarch eq 'i386'
&& $osname ne 'darwin');
}
return $can_build_call_frames;
}

1; 1;


# Local Variables: # Local Variables:
Expand Down
31 changes: 27 additions & 4 deletions t/steps/auto/frames-01.t
Expand Up @@ -5,15 +5,14 @@


use strict; use strict;
use warnings; use warnings;
use Test::More tests => 17; use Test::More tests => 23;
use lib qw( lib t/configure/testlib ); use lib qw( lib t/configure/testlib );
use_ok('config::init::defaults'); use_ok('config::init::defaults');
use_ok('config::auto::frames'); use_ok('config::auto::frames');
use Parrot::Configure; use Parrot::Configure;
use Parrot::Configure::Options qw( process_options ); use Parrot::Configure::Options qw( process_options );
use Parrot::Configure::Test qw( use Parrot::Configure::Test qw(
test_step_thru_runstep test_step_thru_runstep
rerun_defaults_for_testing
test_step_constructor_and_description test_step_constructor_and_description
); );


Expand Down Expand Up @@ -45,12 +44,13 @@ my $ret = $step->runstep($conf);
ok( $ret, "runstep() returned true value" ); ok( $ret, "runstep() returned true value" );
ok( defined ( $step->result() ), ok( defined ( $step->result() ),
"Got defined result" ); "Got defined result" );
is( $step->result(), 'yes', "Result is 'yes', as expected" );
$conf->cc_clean(); $conf->cc_clean();

$step->set_result( undef );


$conf->replenish($serialized); $conf->replenish($serialized);


##### _call_frames_buildable() ##### ###### _call_frames_buildable() #####


my $can_build_call_frames; my $can_build_call_frames;


Expand Down Expand Up @@ -93,6 +93,29 @@ $can_build_call_frames = auto::frames::_call_frames_buildable($conf);
ok( ! $can_build_call_frames, ok( ! $can_build_call_frames,
"_call_frames_buildable() returned false value, as expected (i386/linux/4)" ); "_call_frames_buildable() returned false value, as expected (i386/linux/4)" );


##### _handle_call_frames_buildable() #####

$conf->data->set( nvsize => 8 );
$conf->data->set( cpuarch => 'i386' );
$conf->data->set( osname => 'linux' );

my $rv;

$can_build_call_frames = 0;

$rv = $step->_handle_can_build_call_frames( $conf, $can_build_call_frames );
ok( $rv, "_handle_can_build_call_frames() returned true value" );
ok( ! $conf->data->get( 'cc_build_call_frames'),
"cc_build_call_frames not set to true, as expected" );
ok( ! defined( $conf->data->get( 'has_exec_protect' ) ),
"has_exec_protect undefined, as expected" );
is( $step->result(), 'no', "Result is 'no', as expected" );

$conf->data->set( 'cc_build_call_frames' => undef );
$conf->data->set( 'has_exec_protect' => undef );

pass("Completed all tests in $0");

################### DOCUMENTATION ################### ################### DOCUMENTATION ###################


=head1 NAME =head1 NAME
Expand Down

0 comments on commit 9330765

Please sign in to comment.