Author: jkeenan
Date: Fri Nov  9 18:12:10 2007
New Revision: 22786

Added:
   trunk/t/configure/135-auto_cgoto-02.t   (contents, props changed)
   trunk/t/configure/135-auto_cgoto-03.t   (contents, props changed)
   trunk/t/configure/135-auto_cgoto-04.t   (contents, props changed)
Modified:
   trunk/MANIFEST
   trunk/config/auto/cgoto.pm
   trunk/t/configure/135-auto_cgoto-01.t

Log:
config/auto/cgoto.pm:  Applying patch submitted in
https://rt.perl.org/rt3/Ticket/Display.html?id=43348.  Unit tests and
slight refactoring to make class more testable.


Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST      (original)
+++ trunk/MANIFEST      Fri Nov  9 18:12:10 2007
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools/dev/mk_manifest_and_skip.pl Fri Nov  9 00:02:43 2007 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Sat Nov 10 01:52:43 2007 UT
 #
 # See tools/dev/install_files.pl for documentation on the
 # format of this file.
@@ -3082,6 +3082,9 @@
 t/configure/133-gen_cpu.t                                   []
 t/configure/134-auto_funcptr.t                              []
 t/configure/135-auto_cgoto-01.t                             []
+t/configure/135-auto_cgoto-02.t                             []
+t/configure/135-auto_cgoto-03.t                             []
+t/configure/135-auto_cgoto-04.t                             []
 t/configure/136-auto_inline-01.t                            []
 t/configure/136-auto_inline-02.t                            []
 t/configure/136-auto_inline-03.t                            []

Modified: trunk/config/auto/cgoto.pm
==============================================================================
--- trunk/config/auto/cgoto.pm  (original)
+++ trunk/config/auto/cgoto.pm  Fri Nov  9 18:12:10 2007
@@ -37,8 +37,15 @@
         return 1;
     }
 
-    my ( $cgoto, $verbose ) = $conf->options->get(qw(cgoto verbose));
+    my $test = _probe_for_cgoto( $conf->options->get('cgoto') );
 
+    $self->_evaluate_cgoto($conf, $test);
+
+    return 1;
+}
+
+sub _probe_for_cgoto {
+    my $cgoto = shift;
     my $test;
     if ( defined $cgoto ) {
         $test = $cgoto;
@@ -48,7 +55,12 @@
         $test = eval { cc_build(); 1; } || 0;
         cc_clean();
     }
+    return $test;
+}
 
+sub _evaluate_cgoto {
+    my ($self, $conf, $test) = @_;
+    my $verbose = $conf->options->get('verbose');
     if ($test) {
         $conf->data->set(
             TEMP_cg_h => '$(INC_DIR)/oplib/core_ops_cg.h 
$(INC_DIR)/oplib/core_ops_cgp.h',
@@ -88,8 +100,6 @@
         print " (no) " if $verbose;
         $self->set_result('no');
     }
-
-    return 1;
 }
 
 1;

Modified: trunk/t/configure/135-auto_cgoto-01.t
==============================================================================
--- trunk/t/configure/135-auto_cgoto-01.t       (original)
+++ trunk/t/configure/135-auto_cgoto-01.t       Fri Nov  9 18:12:10 2007
@@ -5,7 +5,7 @@
 
 use strict;
 use warnings;
-use Test::More tests => 12;
+use Test::More tests => 13;
 use Carp;
 use lib qw( lib t/configure/testlib );
 use_ok('config::init::defaults');
@@ -44,6 +44,7 @@
 ok( $ret, "$step_name runstep() returned true value" );
 is($step->result(), q{skipped}, "Expected result was set");
 
+pass("Keep Devel::Cover happy");
 pass("Completed all tests in $0");
 
 ################### DOCUMENTATION ###################

Added: trunk/t/configure/135-auto_cgoto-02.t
==============================================================================
--- (empty file)
+++ trunk/t/configure/135-auto_cgoto-02.t       Fri Nov  9 18:12:10 2007
@@ -0,0 +1,86 @@
+#! perl
+# Copyright (C) 2007, The Perl Foundation.
+# $Id$
+# 135-auto_cgoto-02.t
+
+use strict;
+use warnings;
+use Test::More tests => 18;
+use Carp;
+use lib qw( lib t/configure/testlib );
+use_ok('config::init::defaults');
+use_ok('config::auto::cgoto');
+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::cgoto};
+
+$conf->add_steps($pkg);
+$conf->options->set( %{$args} );
+
+my ( $task, $step_name, @step_params, $step);
+$task        = $conf->steps->[1];
+$step_name   = $task->step;
[EMAIL PROTECTED] = @{ $task->params };
+
+$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 $ret = $step->runstep($conf);
+ok( $ret, "$step_name runstep() returned true value" );
+ok(defined($step->result()), "A result was defined");
+ok(defined($conf->data->get('TEMP_cg_h')), "An attribute has been defined");
+ok(defined($conf->data->get('TEMP_cg_c')), "An attribute has been defined");
+ok(defined($conf->data->get('TEMP_cg_o')), "An attribute has been defined");
+ok(defined($conf->data->get('TEMP_cg_r')), "An attribute has been defined");
+ok(defined($conf->data->get('cg_flag')), "An attribute has been defined");
+
+pass("Keep Devel::Cover happy");
+pass("Completed all tests in $0");
+
+################### DOCUMENTATION ###################
+
+=head1 NAME
+
+135-auto_cgoto-02.t - test config::auto::cgoto
+
+=head1 SYNOPSIS
+
+    % prove t/configure/135-auto_cgoto-02.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::cgoto.
+
+=head1 AUTHOR
+
+James E Keenan
+
+=head1 SEE ALSO
+
+config::auto::cgoto, F<Configure.pl>.
+
+=cut
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Added: trunk/t/configure/135-auto_cgoto-03.t
==============================================================================
--- (empty file)
+++ trunk/t/configure/135-auto_cgoto-03.t       Fri Nov  9 18:12:10 2007
@@ -0,0 +1,103 @@
+#! perl
+# Copyright (C) 2007, The Perl Foundation.
+# $Id$
+# 135-auto_cgoto-03.t
+
+use strict;
+use warnings;
+use Test::More tests => 26;
+use Carp;
+use lib qw( lib t/configure/testlib );
+use_ok('config::init::defaults');
+use_ok('config::auto::cgoto');
+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::cgoto};
+
+$conf->add_steps($pkg);
+$conf->options->set( %{$args} );
+
+my ( $task, $step_name, @step_params, $step);
+$task        = $conf->steps->[1];
+$step_name   = $task->step;
[EMAIL PROTECTED] = @{ $task->params };
+
+$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" );
+
+$conf->options->set(cgoto => 1);
+is(auto::cgoto::_probe_for_cgoto($conf->options->get('cgoto')), 1,
+    "Got expected return value");
+$conf->options->set(cgoto => 0);
+is(auto::cgoto::_probe_for_cgoto($conf->options->get('cgoto')), 0,
+    "Got expected return value");
+$conf->options->set(cgoto => undef);
+ok(defined(auto::cgoto::_probe_for_cgoto($conf->options->get('cgoto'))), 
+    "Probe returned a defined value");
+
+$step->_evaluate_cgoto($conf, 1);
+ok($conf->data->get('TEMP_cg_h'), "An attribute was set to true value");
+ok($conf->data->get('TEMP_cg_c'), "An attribute was set to true value");
+ok($conf->data->get('TEMP_cg_o'), "An attribute was set to true value");
+ok($conf->data->get('TEMP_cg_r'), "An attribute was set to true value");
+ok($conf->data->get('cg_flag'), "An attribute was set to true value");
+is($step->result(), q{yes}, "Expected result was set");
+
+$step->_evaluate_cgoto($conf, 0);
+is($conf->data->get('TEMP_cg_h'), q{}, "An attribute was set to empty string");
+is($conf->data->get('TEMP_cg_c'), q{}, "An attribute was set to empty string");
+is($conf->data->get('TEMP_cg_o'), q{}, "An attribute was set to empty string");
+is($conf->data->get('TEMP_cg_r'), q{}, "An attribute was set to empty string");
+is($conf->data->get('cg_flag'), q{}, "An attribute was set to empty string");
+is($step->result(), q{no}, "Expected result was set");
+
+pass("Keep Devel::Cover happy");
+pass("Completed all tests in $0");
+
+################### DOCUMENTATION ###################
+
+=head1 NAME
+
+135-auto_cgoto-03.t - test config::auto::cgoto
+
+=head1 SYNOPSIS
+
+    % prove t/configure/135-auto_cgoto-03.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::cgoto.
+
+=head1 AUTHOR
+
+James E Keenan
+
+=head1 SEE ALSO
+
+config::auto::cgoto, F<Configure.pl>.
+
+=cut
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Added: trunk/t/configure/135-auto_cgoto-04.t
==============================================================================
--- (empty file)
+++ trunk/t/configure/135-auto_cgoto-04.t       Fri Nov  9 18:12:10 2007
@@ -0,0 +1,108 @@
+#! perl
+# Copyright (C) 2007, The Perl Foundation.
+# $Id$
+# 135-auto_cgoto-04.t
+
+use strict;
+use warnings;
+use Test::More tests => 25;
+use Carp;
+use lib qw( lib t/configure/testlib );
+use_ok('config::init::defaults');
+use_ok('config::auto::cgoto');
+use Parrot::Configure;
+use Parrot::Configure::Options qw( process_options );
+use Parrot::Configure::Test qw( test_step_thru_runstep);
+use Parrot::IO::Capture::Mini;
+
+my $args = process_options(
+    {
+        argv => [ q{--verbose} ],
+        mode => q{configure},
+    }
+);
+
+my $conf = Parrot::Configure->new;
+
+test_step_thru_runstep( $conf, q{init::defaults}, $args );
+
+my $pkg = q{auto::cgoto};
+
+$conf->add_steps($pkg);
+$conf->options->set( %{$args} );
+
+my ( $task, $step_name, @step_params, $step);
+$task        = $conf->steps->[1];
+$step_name   = $task->step;
[EMAIL PROTECTED] = @{ $task->params };
+
+$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 $tie_out = tie *STDOUT, "Parrot::IO::Capture::Mini"
+        or croak "Unable to tie";
+    $step->_evaluate_cgoto($conf, 1);
+    my @more_lines = $tie_out->READLINE;
+    ok( @more_lines, "verbose output captured" );
+    ok($conf->data->get('TEMP_cg_h'), "An attribute was set to true value");
+    ok($conf->data->get('TEMP_cg_c'), "An attribute was set to true value");
+    ok($conf->data->get('TEMP_cg_o'), "An attribute was set to true value");
+    ok($conf->data->get('TEMP_cg_r'), "An attribute was set to true value");
+    ok($conf->data->get('cg_flag'), "An attribute was set to true value");
+    is($step->result(), q{yes}, "Expected result was set");
+}
+untie *STDOUT;
+
+{
+    my $tie_out = tie *STDOUT, "Parrot::IO::Capture::Mini"
+        or croak "Unable to tie";
+    $step->_evaluate_cgoto($conf, 0);
+    my @more_lines = $tie_out->READLINE;
+    ok( @more_lines, "verbose output captured" );
+    is($conf->data->get('TEMP_cg_h'), q{}, "An attribute was set to empty 
string");
+    is($conf->data->get('TEMP_cg_c'), q{}, "An attribute was set to empty 
string");
+    is($conf->data->get('TEMP_cg_o'), q{}, "An attribute was set to empty 
string");
+    is($conf->data->get('TEMP_cg_r'), q{}, "An attribute was set to empty 
string");
+    is($conf->data->get('cg_flag'), q{}, "An attribute was set to empty 
string");
+    is($step->result(), q{no}, "Expected result was set");
+}
+untie *STDOUT;
+
+pass("Keep Devel::Cover happy");
+pass("Completed all tests in $0");
+
+################### DOCUMENTATION ###################
+
+=head1 NAME
+
+135-auto_cgoto-04.t - test config::auto::cgoto
+
+=head1 SYNOPSIS
+
+    % prove t/configure/135-auto_cgoto-04.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::cgoto.
+
+=head1 AUTHOR
+
+James E Keenan
+
+=head1 SEE ALSO
+
+config::auto::cgoto, F<Configure.pl>.
+
+=cut
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Reply via email to