Author: jkeenan
Date: Fri Nov  2 16:25:49 2007
New Revision: 22665

Added:
   trunk/t/configure/131-auto_isreg-01.t   (contents, props changed)
   trunk/t/configure/131-auto_isreg-02.t   (contents, props changed)
   trunk/t/configure/131-auto_isreg-03.t   (contents, props changed)
Removed:
   trunk/t/configure/131-auto_isreg.t
Modified:
   trunk/MANIFEST
   trunk/config/auto/isreg.pm

Log:
config/auto/isreg.pm:  Refactored to increase testability.  Add 3 test
files; remove placeholder test file Updated MANIFEST.  Cf.:
https://rt.perl.org/rt3/Ticket/Display.html?id=43320.


Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST      (original)
+++ trunk/MANIFEST      Fri Nov  2 16:25:49 2007
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools/dev/mk_manifest_and_skip.pl Wed Oct 31 23:05:08 2007 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Thu Nov  1 01:49:58 2007 UT
 #
 # See tools/dev/install_files.pl for documentation on the
 # format of this file.
@@ -3067,7 +3067,9 @@
 t/configure/128-auto_va_ptr.t                               []
 t/configure/129-auto_pack.t                                 []
 t/configure/130-auto_format.t                               []
-t/configure/131-auto_isreg.t                                []
+t/configure/131-auto_isreg-01.t                             []
+t/configure/131-auto_isreg-02.t                             []
+t/configure/131-auto_isreg-03.t                             []
 t/configure/132-auto_jit-01.t                               []
 t/configure/133-gen_cpu.t                                   []
 t/configure/134-auto_funcptr.t                              []

Modified: trunk/config/auto/isreg.pm
==============================================================================
--- trunk/config/auto/isreg.pm  (original)
+++ trunk/config/auto/isreg.pm  Fri Nov  2 16:25:49 2007
@@ -33,19 +33,37 @@
 sub runstep {
     my ( $self, $conf ) = @_;
 
-    my $test = 0;
+    my $errormsg = _first_probe_for_isreg();
 
-    cc_gen('config/auto/isreg/test_c.in');
-    eval { cc_build(); };
-    unless ( $@ || cc_run() !~ /ok/ ) {
-        $test = 1;
+    if (! $errormsg) {
+        $errormsg = _second_probe_for_isreg();
     }
     cc_clean();
+    $self->_evaluate_isreg($conf, $errormsg);
+    return 1;
+}
 
+sub _first_probe_for_isreg {
+    my $errormsg;
+    cc_gen('config/auto/isreg/test_c.in');
+    eval { cc_build(); };
+    $errormsg = 1 if  $@;
+    return $errormsg;
+}
+
+sub _second_probe_for_isreg {
+    my $ccrunfailure;
+    $ccrunfailure++ if ( cc_run() !~ /ok/ );
+    return $ccrunfailure;
+}
+
+sub _evaluate_isreg {
+    my ($self, $conf, $anyerror) = @_;
+    my $test;
+    $test = (! defined $anyerror) ? 1 : 0;
     $conf->data->set( isreg => $test );
     print( $test ? " (Yep) " : " (no) " ) if $conf->options->get('verbose');
     $self->set_result( $test ? 'yes' : 'no' );
-
     return 1;
 }
 

Added: trunk/t/configure/131-auto_isreg-01.t
==============================================================================
--- (empty file)
+++ trunk/t/configure/131-auto_isreg-01.t       Fri Nov  2 16:25:49 2007
@@ -0,0 +1,75 @@
+#! perl
+# Copyright (C) 2007, The Perl Foundation.
+# $Id$
+# 131-auto_isreg-01.t
+
+use strict;
+use warnings;
+use Test::More tests => 11;
+use Carp;
+use lib qw( lib t/configure/testlib );
+use_ok('config::init::defaults');
+use_ok('config::auto::isreg');
+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 ($task, $step_name, @step_params, $step, $ret);
+my $pkg = q{auto::isreg};
+
+$conf->add_steps($pkg);
+$conf->options->set(%{$args});
+$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");
+
+ok($step->runstep($conf), "runstep() returned true value");
+
+pass("Completed all tests in $0");
+
+################### DOCUMENTATION ###################
+
+=head1 NAME
+
+131-auto_isreg-01.t - test config::auto::isreg
+
+=head1 SYNOPSIS
+
+    % prove t/configure/131-auto_isreg-01.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::isreg.
+
+=head1 AUTHOR
+
+James E Keenan
+
+=head1 SEE ALSO
+
+config::auto::isreg, F<Configure.pl>.
+
+=cut
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Added: trunk/t/configure/131-auto_isreg-02.t
==============================================================================
--- (empty file)
+++ trunk/t/configure/131-auto_isreg-02.t       Fri Nov  2 16:25:49 2007
@@ -0,0 +1,87 @@
+#! perl
+# Copyright (C) 2007, The Perl Foundation.
+# $Id$
+# 131-auto_isreg-02.t
+
+use strict;
+use warnings;
+use Test::More tests => 14;
+use Carp;
+use lib qw( lib t/configure/testlib );
+use_ok('config::init::defaults');
+use_ok('config::auto::isreg');
+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 ($task, $step_name, @step_params, $step, $ret);
+my $pkg = q{auto::isreg};
+
+$conf->add_steps($pkg);
+$conf->options->set(%{$args});
+$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";
+    my $anyerror;
+    ok($step->_evaluate_isreg($conf, $anyerror),
+        "_evaluate_isreg returned true value");
+    my @more_lines = $tie_out->READLINE;
+    ok( @more_lines, "verbose output captured" );
+    is($conf->data->get('isreg'), 1, "'isreg' set to true value as expected");
+    is($step->result, 'yes', "Got expected result");
+}
+untie *STDOUT;
+
+pass("Completed all tests in $0");
+
+################### DOCUMENTATION ###################
+
+=head1 NAME
+
+131-auto_isreg-02.t - test config::auto::isreg
+
+=head1 SYNOPSIS
+
+    % prove t/configure/131-auto_isreg-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::isreg.
+
+=head1 AUTHOR
+
+James E Keenan
+
+=head1 SEE ALSO
+
+config::auto::isreg, F<Configure.pl>.
+
+=cut
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Added: trunk/t/configure/131-auto_isreg-03.t
==============================================================================
--- (empty file)
+++ trunk/t/configure/131-auto_isreg-03.t       Fri Nov  2 16:25:49 2007
@@ -0,0 +1,87 @@
+#! perl
+# Copyright (C) 2007, The Perl Foundation.
+# $Id$
+# 131-auto_isreg-03.t
+
+use strict;
+use warnings;
+use Test::More tests => 14;
+use Carp;
+use lib qw( lib t/configure/testlib );
+use_ok('config::init::defaults');
+use_ok('config::auto::isreg');
+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 ($task, $step_name, @step_params, $step, $ret);
+my $pkg = q{auto::isreg};
+
+$conf->add_steps($pkg);
+$conf->options->set(%{$args});
+$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";
+    my $anyerror = 1;
+    ok($step->_evaluate_isreg($conf, $anyerror),
+        "_evaluate_isreg returned true value");
+    my @more_lines = $tie_out->READLINE;
+    ok( @more_lines, "verbose output captured" );
+    is($conf->data->get('isreg'), 0, "'isreg' set to false value as expected");
+    is($step->result, 'no', "Got expected result");
+}
+untie *STDOUT;
+
+pass("Completed all tests in $0");
+
+################### DOCUMENTATION ###################
+
+=head1 NAME
+
+131-auto_isreg-03.t - test config::auto::isreg
+
+=head1 SYNOPSIS
+
+    % prove t/configure/131-auto_isreg-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::isreg.
+
+=head1 AUTHOR
+
+James E Keenan
+
+=head1 SEE ALSO
+
+config::auto::isreg, F<Configure.pl>.
+
+=cut
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Reply via email to