[svn:parrot] r41440 - in branches/auto_frames_refactor: config/auto t/steps/auto

jkeenan at svn.parrot.org jkeenan at svn.parrot.org
Thu Sep 24 01:25:32 UTC 2009


Author: jkeenan
Date: Thu Sep 24 01:25:28 2009
New Revision: 41440
URL: https://trac.parrot.org/parrot/changeset/41440

Log:
Further refactoring to improve testability. Statement coverage up to 93%, which, given that we can't directly test the C code, is as about as good as we're going to do.

Modified:
   branches/auto_frames_refactor/config/auto/frames.pm
   branches/auto_frames_refactor/t/steps/auto/frames-01.t

Modified: branches/auto_frames_refactor/config/auto/frames.pm
==============================================================================
--- branches/auto_frames_refactor/config/auto/frames.pm	Wed Sep 23 23:26:07 2009	(r41439)
+++ branches/auto_frames_refactor/config/auto/frames.pm	Thu Sep 24 01:25:28 2009	(r41440)
@@ -33,6 +33,30 @@
 
     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 ) {
         $conf->data->set(
             cc_build_call_frames  => '-DCAN_BUILD_CALL_FRAMES',
@@ -61,34 +85,15 @@
         else {
             $conf->data->set( has_exec_protect => 0 );
         }
+        $self->set_result( 'yes' );
     }
     else {
-        $conf->data->set(
-            cc_build_call_frames  => '',
-        );
+        $conf->data->set( cc_build_call_frames  => '');
+        $self->set_result( 'no' );
     }
-
-    $self->set_result($can_build_call_frames?'yes':'no');
     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;
 
 # Local Variables:

Modified: branches/auto_frames_refactor/t/steps/auto/frames-01.t
==============================================================================
--- branches/auto_frames_refactor/t/steps/auto/frames-01.t	Wed Sep 23 23:26:07 2009	(r41439)
+++ branches/auto_frames_refactor/t/steps/auto/frames-01.t	Thu Sep 24 01:25:28 2009	(r41440)
@@ -5,7 +5,7 @@
 
 use strict;
 use warnings;
-use Test::More tests => 17;
+use Test::More tests => 23;
 use lib qw( lib t/configure/testlib );
 use_ok('config::init::defaults');
 use_ok('config::auto::frames');
@@ -13,7 +13,6 @@
 use Parrot::Configure::Options qw( process_options );
 use Parrot::Configure::Test qw(
     test_step_thru_runstep
-    rerun_defaults_for_testing
     test_step_constructor_and_description
 );
 
@@ -45,12 +44,13 @@
 ok( $ret, "runstep() returned true value" );
 ok( defined ( $step->result() ),
     "Got defined result" );
+is( $step->result(), 'yes', "Result is 'yes', as expected" );
 $conf->cc_clean();
-
+$step->set_result( undef );
 
 $conf->replenish($serialized);
 
-##### _call_frames_buildable() #####
+###### _call_frames_buildable() #####
 
 my $can_build_call_frames;
 
@@ -93,6 +93,29 @@
 ok( ! $can_build_call_frames,
     "_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 ###################
 
 =head1 NAME


More information about the parrot-commits mailing list