The patch attached proposes a refactoring of Parrot configuration step
auto::alignptrs to make it more testable.  The patch also revises one
currently existing test file and adds two new test files.

As I've done with other configuration steps and their tests, the focus
of the refactoring has been to isolate the problematic (from a testing
point of view) C parts of the class's runstep() method from the more
purely Perl parts of the method.  Then we write tests for those internal
subroutines.

Because of this approach, I'm removing the TODO block inside
t/configure/124-auto_alignptrs-05.t.

Please review.  Thank you very much.

kid51
Index: MANIFEST
===================================================================
--- MANIFEST    (revision 24164)
+++ MANIFEST    (working copy)
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools/dev/mk_manifest_and_skip.pl Thu Dec 20 20:12:03 2007 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Sun Dec 23 04:43:19 2007 UT
 #
 # See tools/dev/install_files.pl for documentation on the
 # format of this file.
@@ -3169,6 +3169,8 @@
 t/configure/124-auto_alignptrs-03.t                         []
 t/configure/124-auto_alignptrs-04.t                         []
 t/configure/124-auto_alignptrs-05.t                         []
+t/configure/124-auto_alignptrs-06.t                         []
+t/configure/124-auto_alignptrs-07.t                         []
 t/configure/125-auto_headers-01.t                           []
 t/configure/125-auto_headers-02.t                           []
 t/configure/125-auto_headers-03.t                           []
Index: t/configure/124-auto_alignptrs-06.t
===================================================================
--- t/configure/124-auto_alignptrs-06.t (revision 0)
+++ t/configure/124-auto_alignptrs-06.t (revision 0)
@@ -0,0 +1,84 @@
+#! perl
+# Copyright (C) 2007, The Perl Foundation.
+# $Id$
+# 124-auto_alignptrs-06.t
+
+use strict;
+use warnings;
+use Test::More tests => 21;
+use Carp;
+use lib qw( lib t/configure/testlib );
+use_ok('config::init::defaults');
+use_ok('config::inter::progs');
+use_ok('config::auto::attributes');
+use_ok('config::auto::alignptrs');
+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 );
+test_step_thru_runstep( $conf, q{inter::progs}, $args );
+test_step_thru_runstep( $conf, q{auto::attributes}, $args );
+
+my $pkg = q{auto::alignptrs};
+
+$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 $align;
+eval { auto::alignptrs::_evaluate_ptr_alignment($conf, $align); };
+like($@, qr/Can't determine alignment!/,
+    "Got expected 'die' message");
+
+pass("Completed all tests in $0");
+
+################### DOCUMENTATION ###################
+
+=head1 NAME
+
+124-auto_alignptrs-06.t - test config::auto::alignptrs
+
+=head1 SYNOPSIS
+
+    % prove t/configure/124-auto_alignptrs-06.t
+
+=head1 DESCRIPTION
+
+The files in this directory test functionality used by F<Configure.pl>.
+
+The tests in this file test subroutines exported by config::auto::alignptrs.
+
+=head1 AUTHOR
+
+James E Keenan
+
+=head1 SEE ALSO
+
+config::auto::alignptrs, F<Configure.pl>.
+
+=cut
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Property changes on: t/configure/124-auto_alignptrs-06.t
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Index: t/configure/124-auto_alignptrs-07.t
===================================================================
--- t/configure/124-auto_alignptrs-07.t (revision 0)
+++ t/configure/124-auto_alignptrs-07.t (revision 0)
@@ -0,0 +1,87 @@
+#! perl
+# Copyright (C) 2007, The Perl Foundation.
+# $Id$
+# 124-auto_alignptrs-07.t
+
+use strict;
+use warnings;
+use Test::More tests => 23;
+use Carp;
+use lib qw( lib t/configure/testlib );
+use_ok('config::init::defaults');
+use_ok('config::inter::progs');
+use_ok('config::auto::attributes');
+use_ok('config::auto::alignptrs');
+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 );
+test_step_thru_runstep( $conf, q{inter::progs}, $args );
+test_step_thru_runstep( $conf, q{auto::attributes}, $args );
+
+my $pkg = q{auto::alignptrs};
+
+$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 ($results, $try_align, $align);
+is(auto::alignptrs::_evaluate_results(q{OK}, 2), 2,
+    "Got expected alignment");
+is(auto::alignptrs::_evaluate_results(q{OK align}, 2), undef,
+    "Got undef as expected");
+is(auto::alignptrs::_evaluate_results(q{foobar}, 2), undef,
+    "Got undef as expected");
+
+pass("Completed all tests in $0");
+
+################### DOCUMENTATION ###################
+
+=head1 NAME
+
+124-auto_alignptrs-07.t - test config::auto::alignptrs
+
+=head1 SYNOPSIS
+
+    % prove t/configure/124-auto_alignptrs-07.t
+
+=head1 DESCRIPTION
+
+The files in this directory test functionality used by F<Configure.pl>.
+
+The tests in this file test subroutines exported by config::auto::alignptrs.
+
+=head1 AUTHOR
+
+James E Keenan
+
+=head1 SEE ALSO
+
+config::auto::alignptrs, F<Configure.pl>.
+
+=cut
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Property changes on: t/configure/124-auto_alignptrs-07.t
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Index: t/configure/124-auto_alignptrs-05.t
===================================================================
--- t/configure/124-auto_alignptrs-05.t (revision 24164)
+++ t/configure/124-auto_alignptrs-05.t (working copy)
@@ -35,7 +35,7 @@
 $conf->options->set( %{$args} );
 
 my ( $task, $step_name, $step);
-$task        = $conf->steps->[3];
+$task        = $conf->steps->[-1];
 $step_name   = $task->step;
 
 $step = $step_name->new();
@@ -43,24 +43,10 @@
 isa_ok( $step, $step_name );
 ok( $step->description(), "$step_name has description" );
 
-TODO: {
-    # http://rt.perl.org/rt3/Ticket/Display.html?id=47391
-    local $TODO =
-        q<Reported failing where vendor-supplied Perl 5 Config.pm does not 
match true state of system available for Parrot configuration>;
-    {
-        $conf->data->set('ptr_alignment' => undef);
-        local $^O = q{linux} if $^O eq q{hpux};  ## no critic 
Variables::ProhibitConditionalDeclarations
-        my $ret;
-        eval { $ret = $step->runstep($conf); };
-        if ($@) {
-            like($@, qr/Can't determine alignment/, #'
-                "Got expected error message when runstep() failed");
-        } else {
-            like($step->result(), qr/bytes?/,
-                "Expected result was set");
-        }
-    }
-}
+my $align = 2;
+auto::alignptrs::_evaluate_ptr_alignment($conf, $align);
+is($conf->data->get( 'ptr_alignment' ), 2,
+    "Got expected pointer alignment");
 
 pass("Completed all tests in $0");
 
Index: config/auto/alignptrs.pm
===================================================================
--- config/auto/alignptrs.pm    (revision 24164)
+++ config/auto/alignptrs.pm    (working copy)
@@ -57,21 +57,39 @@
         cc_build();
         for my $try_align ( 64, 32, 16, 8, 4, 2, 1 ) {
             my $results = cc_run_capture($try_align);
-            if ( $results =~ /OK/ && $results !~ /align/i ) {
-                $align = $try_align;
-            }
+            $align = _evaluate_results($results, $try_align);
         }
         cc_clean();
 
-        die "Can't determine alignment!\n" unless defined $align;
-        $conf->data->set( ptr_alignment => $align );
+        _evaluate_ptr_alignment($conf, $align);
     }
 
+    $self->_finalize_result_str($align, $result_str);
+
+    return 1;
+}
+
+sub _evaluate_results {
+    my ($results, $try_align) = @_;
+    my $align;
+    if ( $results =~ /OK/ && $results !~ /align/i ) {
+        $align = $try_align;
+    }
+    return $align;
+}
+
+sub _evaluate_ptr_alignment {
+    my ($conf, $align) = @_;
+    die "Can't determine alignment!\n" unless defined $align;
+    $conf->data->set( ptr_alignment => $align );
+}
+
+sub _finalize_result_str {
+    my $self = shift;
+    my ($align, $result_str) = @_;
     $result_str .= " $align byte";
     $result_str .= "s" unless $align == 1;
     $self->set_result($result_str);
-
-    return 1;
 }
 
 1;

Reply via email to