On Fri Jun 22 18:17:19 2007, [EMAIL PROTECTED] wrote: > Write unit tests for config/init/hints.pm, > the module whose functionality executes Parrot > configuration step init::hints. >
See patch attached. This provides one small refactoring to config/init/hints.pm to make it more testable, plus 3 test files. I'll apply this to trunk in about 3 days unless ($objection). kid51
Index: MANIFEST =================================================================== --- MANIFEST (revision 20840) +++ MANIFEST (working copy) @@ -1,7 +1,7 @@ # ex: set ro: # $Id$ # -# generated by tools/dev/mk_manifest_and_skip.pl Sat Aug 25 01:42:41 2007 UT +# generated by tools/dev/mk_manifest_and_skip.pl Sat Aug 25 17:08:42 2007 UT # # See tools/dev/install_files.pl for documentation on the # format of this file. @@ -2907,6 +2907,9 @@ t/configure/102-init_defaults.02.t [] t/configure/103-init_install.t [] t/configure/104-init_miniparrot.t [] +t/configure/105-init_hints.01.t [] +t/configure/105-init_hints.02.t [] +t/configure/105-init_hints.03.t [] t/configure/106-init_headers.t [] t/configure/base.t [] t/configure/config_steps.t [] Index: t/configure/105-init_hints.01.t =================================================================== --- t/configure/105-init_hints.01.t (revision 0) +++ t/configure/105-init_hints.01.t (revision 0) @@ -0,0 +1,88 @@ +#! perl +# Copyright (C) 2007, The Perl Foundation. +# $Id$ +# 105-init_hints.01.t + +use strict; +use warnings; +use Test::More tests => 17; +use Carp; +use Data::Dumper; +use lib qw( . lib ../lib ../../lib t/configure/testlib ); +use_ok('config::init::defaults'); +use_ok('config::init::install'); +use_ok('config::init::hints'); +use Parrot::Configure; +use Parrot::Configure::Options qw( process_options ); +use Parrot::IO::Capture::Mini; +use Parrot::Configure::Test qw( test_step_thru_runstep); + +my $args = process_options( { + argv => [ q{--verbose} ], + mode => q{configure}, +} ); + +my $conf = Parrot::Configure->new; + +test_step_thru_runstep($conf, q{init::defaults}, $args); +test_step_thru_runstep($conf, q{init::install}, $args); + +my ($task, $step_name, @step_params, $step, $ret); +my $pkg = q{init::hints}; + +$conf->add_steps($pkg); +$conf->options->set(%{$args}); + +$task = $conf->steps->[2]; +$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"); +# need to capture the --verbose output, because the fact that it does not end +# in a newline confuses Test::Harness +{ + my $tie_out = tie *STDOUT, "Parrot::IO::Capture::Mini" + or croak "Unable to tie"; + $ret = $step->runstep($conf); + my @more_lines = $tie_out->READLINE; + ok(@more_lines, "verbose output: hints were captured"); + ok(defined $ret, "$step_name runstep() returned defined value"); +} + +pass("Completed all tests in $0"); + +################### DOCUMENTATION ################### + +=head1 NAME + +105-init_hints.01.t - test config::init::hints + +=head1 SYNOPSIS + + % prove t/configure/105-init_hints.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::init::hints. + +=head1 AUTHOR + +James E Keenan + +=head1 SEE ALSO + +config::init::hints, 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/105-init_hints.01.t ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Index: t/configure/105-init_hints.02.t =================================================================== --- t/configure/105-init_hints.02.t (revision 0) +++ t/configure/105-init_hints.02.t (revision 0) @@ -0,0 +1,112 @@ +#! perl +# Copyright (C) 2007, The Perl Foundation. +# $Id$ +# 105-init_hints.02.t + +use strict; +use warnings; +use Test::More tests => 17; +use Carp; +use Cwd; +use File::Path (); +use File::Temp qw(tempdir); +use lib qw( . lib ../lib ../../lib t/configure/testlib ); +use_ok('config::init::defaults'); +use_ok('config::init::install'); +use_ok('config::init::hints'); +use Parrot::Configure; +use Parrot::Configure::Options qw( process_options ); +use Parrot::IO::Capture::Mini; +use Parrot::Configure::Test qw( test_step_thru_runstep); + +my $args = process_options( { + argv => [ q{--verbose} ], + mode => q{configure}, +} ); + +my $conf = Parrot::Configure->new; + +test_step_thru_runstep($conf, q{init::defaults}, $args); +test_step_thru_runstep($conf, q{init::install}, $args); + +my ($task, $step_name, @step_params, $step, $ret); +my $pkg = q{init::hints}; + +$conf->add_steps($pkg); +$conf->options->set(%{$args}); + +$task = $conf->steps->[2]; +$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 $cwd = cwd(); +{ + my $tdir = tempdir( CLEANUP => 1 ); + File::Path::mkpath( qq{$tdir/init/hints} ) + or croak "Unable to create directory for local hints"; + my $localhints = qq{$tdir/local.pm}; + open my $FH, '>', $localhints + or croak "Unable to open temp file for writing"; + print $FH <<END; +package init::hints::local; +use strict; +sub runstep { + return 1; +} +1; +END + close $FH or croak "Unable to close temp file after writing"; + unshift(@INC, $tdir); + + # need to capture the --verbose output, + # because the fact that it does not end + # in a newline confuses Test::Harness + { + my $tie_out = tie *STDOUT, "Parrot::IO::Capture::Mini" + or croak "Unable to tie"; + $ret = $step->runstep($conf); + my @more_lines = $tie_out->READLINE; + ok(@more_lines, "verbose output: hints were captured"); + ok(defined $ret, "$step_name runstep() returned defined value"); + } + unlink $localhints or croak "Unable to delete $localhints"; +} + +pass("Completed all tests in $0"); + +################### DOCUMENTATION ################### + +=head1 NAME + +105-init_hints.02.t - test config::init::hints + +=head1 SYNOPSIS + + % prove t/configure/105-init_hints.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::init::hints. + +=head1 AUTHOR + +James E Keenan + +=head1 SEE ALSO + +config::init::hints, 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/105-init_hints.02.t ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Index: t/configure/105-init_hints.03.t =================================================================== --- t/configure/105-init_hints.03.t (revision 0) +++ t/configure/105-init_hints.03.t (revision 0) @@ -0,0 +1,109 @@ +#! perl +# Copyright (C) 2007, The Perl Foundation. +# $Id$ +# 105-init_hints.03.t + +use strict; +use warnings; +use Test::More tests => 17; +use Carp; +use Cwd; +use File::Path (); +use File::Temp qw(tempdir); +use lib qw( . lib ../lib ../../lib t/configure/testlib ); +use_ok('config::init::defaults'); +use_ok('config::init::install'); +use_ok('config::init::hints'); +use Parrot::Configure; +use Parrot::Configure::Options qw( process_options ); +use Parrot::IO::Capture::Mini; +use Parrot::Configure::Test qw( test_step_thru_runstep); + +my $args = process_options( { + argv => [ q{--verbose} ], + mode => q{configure}, +} ); + +my $conf = Parrot::Configure->new; + +test_step_thru_runstep($conf, q{init::defaults}, $args); +test_step_thru_runstep($conf, q{init::install}, $args); + +my ($task, $step_name, @step_params, $step, $ret); +my $pkg = q{init::hints}; + +$conf->add_steps($pkg); +$conf->options->set(%{$args}); + +$task = $conf->steps->[2]; +$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 $cwd = cwd(); +{ + my $tdir = tempdir( CLEANUP => 1 ); + File::Path::mkpath( qq{$tdir/init/hints} ) + or croak "Unable to create directory for local hints"; + my $localhints = qq{$tdir/local.pm}; + open my $FH, '>', $localhints + or croak "Unable to open temp file for writing"; + print $FH <<END; +package init::hints::local; +use strict; +1; +END + close $FH or croak "Unable to close temp file after writing"; + unshift(@INC, $tdir); + + # need to capture the --verbose output, + # because the fact that it does not end + # in a newline confuses Test::Harness + { + my $tie_out = tie *STDOUT, "Parrot::IO::Capture::Mini" + or croak "Unable to tie"; + $ret = $step->runstep($conf); + my @more_lines = $tie_out->READLINE; + ok(@more_lines, "verbose output: hints were captured"); + ok(defined $ret, "$step_name runstep() returned defined value"); + } + unlink $localhints or croak "Unable to delete $localhints"; +} + +pass("Completed all tests in $0"); + +################### DOCUMENTATION ################### + +=head1 NAME + +105-init_hints.03.t - test config::init::hints + +=head1 SYNOPSIS + + % prove t/configure/105-init_hints.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::init::hints. + +=head1 AUTHOR + +James E Keenan + +=head1 SEE ALSO + +config::init::hints, 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/105-init_hints.03.t ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Index: config/init/hints.pm =================================================================== --- config/init/hints.pm (revision 20840) +++ config/init/hints.pm (working copy) @@ -48,13 +48,14 @@ $hints = "init::hints::local"; print "$hints " if $verbose; eval "use $hints"; + unless ($@) { $hints->runstep( $conf, @_ ) if $hints->can('runstep'); $hints_used++; } - if ( $hints_used == 0 ) { - print "(no hints) " if $verbose; + if ( $hints_used == 0 and $verbose ) { + print "(no hints) "; } print "]" if $verbose;