-
Notifications
You must be signed in to change notification settings - Fork 138
/
Test.pm
169 lines (122 loc) · 3.97 KB
/
Test.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# Copyright (C) 2007, Parrot Foundation.
package Parrot::Configure::Test;
use strict;
use warnings;
our ( @ISA, @EXPORT_OK );
@ISA = qw(Exporter);
@EXPORT_OK = qw(
test_step_thru_runstep
rerun_defaults_for_testing
test_step_constructor_and_description
);
use Carp;
*ok = *Test::More::ok;
*isa_ok = *Test::More::isa_ok;
use lib qw( lib );
use Parrot::Configure;
my $stepnum = -1;
sub stepnum {
$stepnum++;
return $stepnum;
}
sub test_step_thru_runstep {
my ( $conf, $pkg, $args ) = @_;
my ( $task, $step_name, $step, $ret );
$conf->add_steps($pkg);
$conf->options->set( %{$args} );
$task = $conf->steps->[ stepnum() ];
$step_name = $task->step;
$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" );
$ret = $step->runstep($conf);
ok( defined $ret, "$step_name runstep() returned defined value" );
return $stepnum;
}
sub rerun_defaults_for_testing {
my $conf = shift;
my $args = shift;
$conf->add_steps(q{init::defaults});
$conf->options->set( %{$args} );
my ( $task, $step_name, $step );
$task = $conf->steps->[ -1 ];
$step_name = $task->step;
$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 $ret = $step->runstep($conf);
return $ret;
}
sub test_step_constructor_and_description {
my $conf = shift;
my $task = $conf->steps->[-1];
my $step_name = $task->step;
my $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");
return $step;
}
1;
################### DOCUMENTATION ###################
=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
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4: