Author: jkeenan Date: Tue Nov 13 19:37:38 2007 New Revision: 22826 Added: trunk/t/configure/141-auto_env-01.t (contents, props changed) trunk/t/configure/141-auto_env-02.t (contents, props changed) trunk/t/configure/141-auto_env-03.t (contents, props changed) Removed: trunk/t/configure/141-auto_env.t Modified: trunk/MANIFEST trunk/config/auto/env.pm
Log: Applying patch submitted in http://rt.perl.org/rt3//Ticket/Display.html?id=43332: refactoring of Parrot configuration step auto::env to increase testability. New test files which improve coverage. Modified: trunk/MANIFEST ============================================================================== --- trunk/MANIFEST (original) +++ trunk/MANIFEST Tue Nov 13 19:37:38 2007 @@ -1,7 +1,7 @@ # ex: set ro: # $Id$ # -# generated by tools/dev/mk_manifest_and_skip.pl Mon Nov 12 17:39:49 2007 UT +# generated by tools/dev/mk_manifest_and_skip.pl Wed Nov 14 03:10:35 2007 UT # # See tools/dev/install_files.pl for documentation on the # format of this file. @@ -3098,7 +3098,9 @@ t/configure/139-auto_signal-01.t [] t/configure/140-auto_socklen_t-01.t [] t/configure/140-auto_socklen_t-02.t [] -t/configure/141-auto_env.t [] +t/configure/141-auto_env-01.t [] +t/configure/141-auto_env-02.t [] +t/configure/141-auto_env-03.t [] t/configure/142-auto_aio.t [] t/configure/143-auto_gmp-01.t [] t/configure/144-auto_readline.t [] Modified: trunk/config/auto/env.pm ============================================================================== --- trunk/config/auto/env.pm (original) +++ trunk/config/auto/env.pm Tue Nov 13 19:37:38 2007 @@ -9,6 +9,10 @@ Determining if the C library has C<setenv()> and C<unsetenv()>. +More information about these functions can be found at +L<http://www.gnu.org/software/libc/manual/html_node/Environment-Access.html>, +among other locations. + =cut package auto::env; @@ -32,8 +36,6 @@ sub runstep { my ( $self, $conf ) = ( shift, shift ); - my $verbose = $conf->options->get('verbose'); - my ( $setenv, $unsetenv ) = ( 0, 0 ); cc_gen('config/auto/env/test_setenv.in'); @@ -49,6 +51,14 @@ } cc_clean(); + $self->_evaluate_env($conf, $setenv, $unsetenv); + + return 1; +} + +sub _evaluate_env { + my ($self, $conf, $setenv, $unsetenv) = @_; + my $verbose = $conf->options->get('verbose'); $conf->data->set( setenv => $setenv, unsetenv => $unsetenv @@ -70,8 +80,6 @@ print " (no) " if $verbose; $self->set_result('no'); } - - return 1; } 1; Added: trunk/t/configure/141-auto_env-01.t ============================================================================== --- (empty file) +++ trunk/t/configure/141-auto_env-01.t Tue Nov 13 19:37:38 2007 @@ -0,0 +1,77 @@ +#! perl +# Copyright (C) 2007, The Perl Foundation. +# $Id$ +# 141-auto_env-01.t + +use strict; +use warnings; +use Test::More tests => 12; +use Carp; +use lib qw( lib t/configure/testlib ); +use_ok('config::init::defaults'); +use_ok('config::auto::env'); +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::env}; + +$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("Keep Devel::Cover happy"); +pass("Completed all tests in $0"); + +################### DOCUMENTATION ################### + +=head1 NAME + +141-auto_env-01.t - test config::auto::env + +=head1 SYNOPSIS + + % prove t/configure/141-auto_env-01.t + +=head1 DESCRIPTION + +The files in this directory test functionality used by F<Configure.pl>. + +The tests in this file test subroutines found in config::auto::env in +its most ordinary usage. + +=head1 AUTHOR + +James E Keenan + +=head1 SEE ALSO + +config::auto::env, F<Configure.pl>. + +=cut + +# Local Variables: +# mode: cperl +# cperl-indent-level: 4 +# fill-column: 100 +# End: +# vim: expandtab shiftwidth=4: Added: trunk/t/configure/141-auto_env-02.t ============================================================================== --- (empty file) +++ trunk/t/configure/141-auto_env-02.t Tue Nov 13 19:37:38 2007 @@ -0,0 +1,98 @@ +#! perl +# Copyright (C) 2007, The Perl Foundation. +# $Id$ +# 141-auto_env-02.t + +use strict; +use warnings; +use Test::More tests => 15; +use Carp; +use lib qw( lib t/configure/testlib ); +use_ok('config::init::defaults'); +use_ok('config::auto::env'); +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::env}; + +$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 ($setenv, $unsetenv); + +$setenv = 1; +$unsetenv = 1; +$step->_evaluate_env($conf, $setenv, $unsetenv); +is($step->result(), q{both}, "Got expected result"); + +$setenv = 1; +$unsetenv = 0; +$step->_evaluate_env($conf, $setenv, $unsetenv); +is($step->result(), q{setenv}, "Got expected result"); + +$setenv = 0; +$unsetenv = 1; +$step->_evaluate_env($conf, $setenv, $unsetenv); +is($step->result(), q{unsetenv}, "Got expected result"); + +$setenv = 0; +$unsetenv = 0; +$step->_evaluate_env($conf, $setenv, $unsetenv); +is($step->result(), q{no}, "Got expected result"); + +pass("Keep Devel::Cover happy"); +pass("Completed all tests in $0"); + +################### DOCUMENTATION ################### + +=head1 NAME + +141-auto_env-02.t - test config::auto::env + +=head1 SYNOPSIS + + % prove t/configure/141-auto_env-02.t + +=head1 DESCRIPTION + +The files in this directory test functionality used by F<Configure.pl>. + +The tests in this file test config::auto::env::_evaluate_env(), an +internal subroutine, in the various permutations of having or lacking +C<setenv> and C<unsetenv>. + +=head1 AUTHOR + +James E Keenan + +=head1 SEE ALSO + +config::auto::env, F<Configure.pl>. + +=cut + +# Local Variables: +# mode: cperl +# cperl-indent-level: 4 +# fill-column: 100 +# End: +# vim: expandtab shiftwidth=4: Added: trunk/t/configure/141-auto_env-03.t ============================================================================== --- (empty file) +++ trunk/t/configure/141-auto_env-03.t Tue Nov 13 19:37:38 2007 @@ -0,0 +1,121 @@ +#! perl +# Copyright (C) 2007, The Perl Foundation. +# $Id$ +# 141-auto_env-03.t + +use strict; +use warnings; +use Test::More tests => 19; +use Carp; +use lib qw( lib t/configure/testlib ); +use_ok('config::init::defaults'); +use_ok('config::auto::env'); +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::env}; + +$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 ($setenv, $unsetenv); + +{ + my $tie_out = tie *STDOUT, "Parrot::IO::Capture::Mini" + or croak "Unable to tie"; + $setenv = 1; + $unsetenv = 1; + $step->_evaluate_env($conf, $setenv, $unsetenv); + like($tie_out->READLINE, qr/both/, "Got expected verbose output"); + is($step->result(), q{both}, "Got expected result"); +} +untie *STDOUT; + +{ + my $tie_out = tie *STDOUT, "Parrot::IO::Capture::Mini" + or croak "Unable to tie"; + $setenv = 1; + $unsetenv = 0; + $step->_evaluate_env($conf, $setenv, $unsetenv); + like($tie_out->READLINE, qr/setenv/, "Got expected verbose output"); + is($step->result(), q{setenv}, "Got expected result"); +} +untie *STDOUT; + +{ + my $tie_out = tie *STDOUT, "Parrot::IO::Capture::Mini" + or croak "Unable to tie"; + $setenv = 0; + $unsetenv = 1; + $step->_evaluate_env($conf, $setenv, $unsetenv); + like($tie_out->READLINE, qr/unsetenv/, "Got expected verbose output"); + is($step->result(), q{unsetenv}, "Got expected result"); +} +untie *STDOUT; + +{ + my $tie_out = tie *STDOUT, "Parrot::IO::Capture::Mini" + or croak "Unable to tie"; + $setenv = 0; + $unsetenv = 0; + $step->_evaluate_env($conf, $setenv, $unsetenv); + like($tie_out->READLINE, qr/no/, "Got expected verbose output"); + is($step->result(), q{no}, "Got expected result"); +} +untie *STDOUT; + +pass("Keep Devel::Cover happy"); +pass("Completed all tests in $0"); + +################### DOCUMENTATION ################### + +=head1 NAME + +141-auto_env-03.t - test config::auto::env + +=head1 SYNOPSIS + + % prove t/configure/141-auto_env-03.t + +=head1 DESCRIPTION + +The files in this directory test functionality used by F<Configure.pl>. + +The tests in this file test config::auto::env in verbose mode. + +=head1 AUTHOR + +James E Keenan + +=head1 SEE ALSO + +config::auto::env, F<Configure.pl>. + +=cut + +# Local Variables: +# mode: cperl +# cperl-indent-level: 4 +# fill-column: 100 +# End: +# vim: expandtab shiftwidth=4: