File Coverage

File:lib/Parrot/Configure/Test.pm
Coverage:95.5%

linestmtbrancondsubpodtimecode
1# Copyright (C) 2007, Parrot Foundation.
2package Parrot::Configure::Test;
3
72
72
72
245
103
263
use strict;
4
72
72
72
353
115
262
use 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);
12
72
72
72
343
120
427
use Carp;
13*ok = *Test::More::ok;
14*isa_ok = *Test::More::isa_ok;
15
72
72
72
446
101
280
use lib qw( lib );
16
72
72
72
516
118
444
use Parrot::Configure;
17
18my $stepnum = -1;
19
20sub stepnum {
21
4
0
13
    $stepnum++;
22
4
13
    return $stepnum;
23}
24
25sub test_step_thru_runstep {
26
4
1
19
    my ( $conf, $pkg, $args ) = @_;
27
4
15
    my ( $task, $step_name, $step, $ret );
28
29
4
24
    $conf->add_steps($pkg);
30
4
4
21
35
    $conf->options->set( %{$args} );
31
32
4
21
    $task = $conf->steps->[ stepnum() ];
33
4
23
    $step_name = $task->step;
34
35
4
40
    $step = $step_name->new();
36
4
33
    ok( defined $step, "$step_name constructor returned defined value" );
37
4
27
    isa_ok( $step, $step_name );
38
4
43
    ok( $step->description(), "$step_name has description" );
39
4
28
    $ret = $step->runstep($conf);
40
4
21
    ok( defined $ret, "$step_name runstep() returned defined value" );
41
4
49
    return $stepnum;
42}
43
44sub rerun_defaults_for_testing {
45
5
0
20
    my $conf = shift;
46
5
15
    my $args = shift;
47
5
48
    $conf->add_steps(q{init::defaults});
48
5
5
27
41
    $conf->options->set( %{$args} );
49
50
5
16
    my ( $task, $step_name, $step );
51
5
26
    $task = $conf->steps->[ -1 ];
52
5
29
    $step_name = $task->step;
53
54
5
64
    $step = $step_name->new();
55
5
37
    ok( defined $step, "$step_name constructor returned defined value" );
56
5
34
    isa_ok( $step, $step_name );
57
5
49
    ok( $step->description(), "$step_name has description" );
58
5
35
    my $ret = $step->runstep($conf);
59
5
16
    return $ret;
60}
61
62sub test_step_constructor_and_description {
63
176
0
534
    my $conf = shift;
64
176
852
    my $task = $conf->steps->[-1];
65
176
795
    my $step_name = $task->step;
66
176
971
    my $step = $step_name->new();
67
176
1116
    ok(defined $step, "$step_name constructor returned defined value");
68
176
934
    isa_ok($step, $step_name);
69
176
1522
    ok($step->description(), "$step_name has description");
70
176
763
    return $step;
71}
72
731;
74
75################### DOCUMENTATION ###################
76
77 - 162
=head1 NAME

Parrot::Configure::Test - subroutines used in F<t/configure/*> tests

=head1 SYNOPSIS

    use lib qw( lib );
    use Parrot::Configure::Test qw( test_step_thru_runstep );

Set-up for C<test_step_thru_runstep()>:

    $parrot_version = Parrot::BuildUtil::parrot_version();
    $args = process_options( {
        argv            => [ ],
        script          => $0,
        parrot_version  => $parrot_version,
} );

    $conf = Parrot::Configure->new;
    test_step_thru_runstep($conf, q{init::defaults}, $args);

=head1 DESCRIPTION

The subroutines in this package are used to simplify tests found in
F<t/configure/>.  Any subroutine in this package should be functional
(C<i.e.>, not object-oriented), be exported only on demand and have all its
arguments explicitly passed as arguments.

=head1 FUNCTIONS

=head2 C<test_step_thru_runstep()>

=over 4

=item * Purpose

Reduce code repeated in many test files in the F<t/configure/101+> series.
Execution of certain configuration steps depends upon successful
execution of some (though not necessarily all) of the preceding configuration
steps.  Hence, unit tests of the packages generating certain steps may require
execution of preceding steps in the test file.  Once you determine that you
need to execute one step as a prerequisite to another, you can provide that
step as an argument to C<test_step_thru_runstep()> and not worry about it
further.

=item * Arguments

List of three arguments:

=over 4

=item *

Parrot::Configure object

=item *

string holding the name of the step to be run

=item *

hash reference which is the output of
C<Parrot::Configure::Options::process_options()>.

=back

=item * Return Value

Returns the step number, but currently this is not used and needs
further exploration.

=item * Comment

Each invocation of C<test_step_thru_runstep()> runs 4 Test::More tests.

=back

=head1 AUTHORS

David H Adler and James E Keenan

=head1 SEE ALSO

F<Configure.pl>.

=cut
163
164# Local Variables:
165# mode: cperl
166# cperl-indent-level: 4
167# fill-column: 100
168# End:
169# vim: expandtab shiftwidth=4: