line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Test::Tapat; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
38228
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
App::Test::Tapat - An automated testing framework |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Version 0.04 |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Please note that this should be considered a developer release. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
This module is designed to be a framework for automated testing. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use App::Test::Tapat; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# New Tapat object |
26
|
|
|
|
|
|
|
my $t = App::Test::Tapat->new; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Chop up test into consituent test bits |
29
|
|
|
|
|
|
|
$t->filename($test_file); |
30
|
|
|
|
|
|
|
print "-> Running $t->{test_name} at $time_now with test id: $t->{test_id}\n"; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Parse the test for TAP and output results |
33
|
|
|
|
|
|
|
$t->parsetest($test_file); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has 'test_name' => (isa => 'Str', is => 'rw', default => 0); |
38
|
|
|
|
|
|
|
has 'script' => (isa => 'Str', is => 'rw', default => 0); |
39
|
|
|
|
|
|
|
has 'test_id' => (isa => 'Int', is => 'rw', default => 0); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 DESCRIPTION |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Tapat aims to be an automated testing framework. It currently only provides a |
44
|
|
|
|
|
|
|
mechanism to run tests which contain TAP, receive the test's output, and |
45
|
|
|
|
|
|
|
relay that output further to a report and, in the future, a database. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Tapat is designed to be programming language agnostic. This means that you can |
48
|
|
|
|
|
|
|
write tests in any language that can produce TAP, and many languages can, |
49
|
|
|
|
|
|
|
including perl, python, php, bash, C/C++, Java, various SQL implementations, |
50
|
|
|
|
|
|
|
ruby, and any language that can create simple TAP output. (See the TAP wiki.) |
51
|
|
|
|
|
|
|
Once your tests are written, they are run by the tapat harness and reports |
52
|
|
|
|
|
|
|
are created. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
The goal is to allow testers to focus on their testing, not the mechanism or framework |
55
|
|
|
|
|
|
|
that surrounds their tests, enabling a simple drop-in mechanism for new automated |
56
|
|
|
|
|
|
|
tests to run inside of. So with Tapat, you get a parsing and reporting layer for |
57
|
|
|
|
|
|
|
your tests. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 METHODS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 filename |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Calling filename returns the name of the test script that will be parsed for |
64
|
|
|
|
|
|
|
TAP. It returns three constituent elements of the test file which will be used |
65
|
|
|
|
|
|
|
later: test_name, test_id and script. These constituent elements are built into |
66
|
|
|
|
|
|
|
the test name merely by convention. A test ought to have a name of test_1, (that |
67
|
|
|
|
|
|
|
is to say; alphanumeric characters followed by an underscore, followed by an |
68
|
|
|
|
|
|
|
integer.) This allows one to sort tests numerically and it is also what Tapat |
69
|
|
|
|
|
|
|
expects. As previously mentioned, it is only a convention, but hopefully a |
70
|
|
|
|
|
|
|
useful one. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub filename { |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my ($self, $file) = @_; |
77
|
|
|
|
|
|
|
$file = fileparse($file); |
78
|
|
|
|
|
|
|
my ($script, $test_id) = split /_/, $file; |
79
|
|
|
|
|
|
|
$self->script($script) || confess "Not sure how to assign script."; |
80
|
|
|
|
|
|
|
$self->test_id($test_id) || confess "Not sure how to assign test_id."; |
81
|
|
|
|
|
|
|
$self->test_name($file) || confess "Not sure how to assign filename."; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 parsetest |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
This is where the TAP from your test gets parsed. A timer is created here as |
87
|
|
|
|
|
|
|
well. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub parsetest { |
92
|
|
|
|
|
|
|
use TAP::Parser qw/all/; |
93
|
|
|
|
|
|
|
use TAP::Parser::Aggregator qw/all/; |
94
|
|
|
|
|
|
|
use Term::ANSIColor; |
95
|
|
|
|
|
|
|
use File::Basename; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my ($self, $file) = @_; |
98
|
|
|
|
|
|
|
my $planned = 0; |
99
|
|
|
|
|
|
|
my $aggregate = TAP::Parser::Aggregator->new; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Create parser object |
102
|
|
|
|
|
|
|
my $parser = TAP::Parser->new( { source => $file } ); |
103
|
|
|
|
|
|
|
$aggregate->start(); # start timer |
104
|
|
|
|
|
|
|
$aggregate->add($file, $parser); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
while ( my $result = $parser->next ) { |
107
|
|
|
|
|
|
|
my $out = $result->as_string; |
108
|
|
|
|
|
|
|
print "$out\n"; |
109
|
|
|
|
|
|
|
if ($result->is_plan) { |
110
|
|
|
|
|
|
|
$planned = $result->tests_planned; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
$aggregate->stop(); # stop timer |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
my $elapsed = $aggregate->elapsed_timestr(); |
116
|
|
|
|
|
|
|
my $failed = $parser->failed; |
117
|
|
|
|
|
|
|
my $passed = $parser->passed; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# If we ran all the tests, and they all passed |
120
|
|
|
|
|
|
|
if ($parser->is_good_plan && ($passed - $failed == $planned)) { |
121
|
|
|
|
|
|
|
print color 'green'; |
122
|
|
|
|
|
|
|
print "\n--==[ Passed all our planned tests, updating db for $self->{test_id} ]==--\n"; |
123
|
|
|
|
|
|
|
} else { |
124
|
|
|
|
|
|
|
print color 'red'; |
125
|
|
|
|
|
|
|
print "\n--==[ ERROR in testing output. ]==--\n"; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
print "Elapsed time: $elapsed\nPassed: $passed\nFailed: $failed\n---\n"; |
128
|
|
|
|
|
|
|
print color 'reset'; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 AUTHOR |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Jeremiah C. Foster, C<< <jeremiah at cpan.org> >> |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 BUGS |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Please report any bugs or feature requests to C<bug-app-test-tapat at rt.cpan.org>, or through |
139
|
|
|
|
|
|
|
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-Test-Tapat>. I will be notified, and then you'll |
140
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 SUPPORT |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
perldoc App::Test::Tapat |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
You can also look for information at: |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=over 4 |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item * Tapat's homepage on source forge |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
L<http://tapat.sourceforge.net> |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=App-Test-Tapat> |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
L<http://annocpan.org/dist/App-Test-Tapat> |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item * CPAN Ratings |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/App-Test-Tapat> |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item * Search CPAN |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
L<http://search.cpan.org/dist/App-Test-Tapat> |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=back |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Thanks to the Moose team, rjbs for Module::Starter, the TAP team, and Alias |
179
|
|
|
|
|
|
|
for giving us all a goal to aspire to. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Copyright 2008 Jeremiah C. Foster, all rights reserved. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
186
|
|
|
|
|
|
|
under the same terms as Perl itself. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=cut |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
1; # End of App::Test::Tapat |