1# Copyright (C) 2007, Parrot Foundation. 2package Parrot::Configure::Test; 3use strict; 4use warnings; 5our ( @ISA, @EXPORT_OK ); 6@ISA = qw(Exporter); 7@EXPORT_OK = qw( 8 test_step_thru_runstep 9 rerun_defaults_for_testing 10 test_step_constructor_and_description 11); 12use Carp; 13*ok = *Test::More::ok; 14*isa_ok = *Test::More::isa_ok; 15use lib qw( lib ); 16use Parrot::Configure; 17 18my $stepnum = -1; 19 20sub stepnum { 21 $stepnum++; 22 return $stepnum; 23} 24 25sub test_step_thru_runstep { 26 my ( $conf, $pkg, $args ) = @_; 27 my ( $task, $step_name, $step, $ret ); 28 29 $conf->add_steps($pkg); 30 $conf->options->set( %{$args} ); 31 32 $task = $conf->steps->[ stepnum() ]; 33 $step_name = $task->step; 34 35 $step = $step_name->new(); 36 ok( defined $step, "$step_name constructor returned defined value" ); 37 isa_ok( $step, $step_name ); 38 ok( $step->description(), "$step_name has description" ); 39 $ret = $step->runstep($conf); 40 ok( defined $ret, "$step_name runstep() returned defined value" ); 41 return $stepnum; 42} 43 44sub rerun_defaults_for_testing { 45 my $conf = shift; 46 my $args = shift; 47 $conf->add_steps(q{init::defaults}); 48 $conf->options->set( %{$args} ); 49 50 my ( $task, $step_name, $step ); 51 $task = $conf->steps->[ -1 ]; 52 $step_name = $task->step; 53 54 $step = $step_name->new(); 55 ok( defined $step, "$step_name constructor returned defined value" ); 56 isa_ok( $step, $step_name ); 57 ok( $step->description(), "$step_name has description" ); 58 my $ret = $step->runstep($conf); 59 return $ret; 60} 61 62sub test_step_constructor_and_description { 63 my $conf = shift; 64 my $task = $conf->steps->[-1]; 65 my $step_name = $task->step; 66 my $step = $step_name->new(); 67 ok(defined $step, "$step_name constructor returned defined value"); 68 isa_ok($step, $step_name); 69 ok($step->description(), "$step_name has description"); 70 return $step; 71} 72 731; 74 75################### DOCUMENTATION ################### 76 77=head1 NAME 78 79Parrot::Configure::Test - subroutines used in F<t/configure/*> tests 80 81=head1 SYNOPSIS 82 83 use lib qw( lib ); 84 use Parrot::Configure::Test qw( test_step_thru_runstep ); 85 86Set-up for C<test_step_thru_runstep()>: 87 88 $parrot_version = Parrot::BuildUtil::parrot_version(); 89 $args = process_options( { 90 argv => [ ], 91 script => $0, 92 parrot_version => $parrot_version, 93} ); 94 95 $conf = Parrot::Configure->new; 96 test_step_thru_runstep($conf, q{init::defaults}, $args); 97 98=head1 DESCRIPTION 99 100The subroutines in this package are used to simplify tests found in 101F<t/configure/>. Any subroutine in this package should be functional 102(C<i.e.>, not object-oriented), be exported only on demand and have all its 103arguments explicitly passed as arguments. 104 105=head1 FUNCTIONS 106 107=head2 C<test_step_thru_runstep()> 108 109=over 4 110 111=item * Purpose 112 113Reduce code repeated in many test files in the F<t/configure/101+> series. 114Execution of certain configuration steps depends upon successful 115execution of some (though not necessarily all) of the preceding configuration 116steps. Hence, unit tests of the packages generating certain steps may require 117execution of preceding steps in the test file. Once you determine that you 118need to execute one step as a prerequisite to another, you can provide that 119step as an argument to C<test_step_thru_runstep()> and not worry about it 120further. 121 122=item * Arguments 123 124List of three arguments: 125 126=over 4 127 128=item * 129 130Parrot::Configure object 131 132=item * 133 134string holding the name of the step to be run 135 136=item * 137 138hash reference which is the output of 139C<Parrot::Configure::Options::process_options()>. 140 141=back 142 143=item * Return Value 144 145Returns the step number, but currently this is not used and needs 146further exploration. 147 148=item * Comment 149 150Each invocation of C<test_step_thru_runstep()> runs 4 Test::More tests. 151 152=back 153 154=head1 AUTHORS 155 156David H Adler and James E Keenan 157 158=head1 SEE ALSO 159 160F<Configure.pl>. 161 162=cut 163 164# Local Variables: 165# mode: cperl 166# cperl-indent-level: 4 167# fill-column: 100 168# End: 169# vim: expandtab shiftwidth=4: 170