blib/lib/App/Test/Tapat.pm

filter: Statementstmt 41.6% 20 / 48 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 71.4% 5 / 7 Podpod 100% 2 / 2 totaltotal 36.4% 27 / 74 CC 8 SCAR 24.2
CC
8
Cov
32%
filename
20.0
parsetest
14.4
BEGIN
1.0
CRAP 11.2
↑ Summary
1 package App::Test::Tapat;
2  
3 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=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 2 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 2 has 'test_name' => (isa => 'Str', is => 'rw', default => 0);
38 2 has 'script' => (isa => 'Str', is => 'rw', default => 0);
39 2 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 0 ▶sub filename {
Subroutine filename: not called CC=4 SCAR=30.0
Pod documented
75
76 0 my ($self, $file) = @_;
77 0 $file = fileparse($file);
78 0 my ($script, $test_id) = split /_/, $file;
79 0 ▶ $self->script($script) || confess "Not sure how to assign script.";
Branch: 1 branch
BranchTrueFalseTotal
$self->script($script) or confess("Not sure how to assign script.") 0 0 0
80 0 ▶ $self->test_id($test_id) || confess "Not sure how to assign test_id.";
Branch: 1 branch
BranchTrueFalseTotal
$self->test_id($test_id) or confess("Not sure how to assign test_id.") 0 0 0
81 0 ▶ $self->test_name($file) || confess "Not sure how to assign filename.";
Branch: 1 branch
BranchTrueFalseTotal
$self->test_name($file) or confess("Not sure how to assign filename.") 0 0 0
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 0 ▶sub parsetest {
Subroutine parsetest: not called CC=5 SCAR=26.6
Pod documented
92 2 ▶ use TAP::Parser qw/all/;
Subroutine BEGIN: called CC=1 SCAR=0.0
93 2 ▶ use TAP::Parser::Aggregator qw/all/;
Subroutine BEGIN: called CC=1 SCAR=0.0
94 2 ▶ use Term::ANSIColor;
Subroutine BEGIN: called CC=1 SCAR=0.0
95 2 ▶ use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
96  
97 0 my ($self, $file) = @_;
98 0 my $planned = 0;
99 0 my $aggregate = TAP::Parser::Aggregator->new;
100  
101 # Create parser object
102 0 my $parser = TAP::Parser->new( { source => $file } );
103 0 $aggregate->start(); # start timer
104 0 $aggregate->add($file, $parser);
105  
106 0 ▶ while ( my $result = $parser->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $result = $parser->next) 0 0 0
107 0 my $out = $result->as_string;
108 0 print "$out\n";
109 0 ▶ if ($result->is_plan) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->is_plan) 0 0 0
110 0 $planned = $result->tests_planned;
111 }
112 }
113 0 $aggregate->stop(); # stop timer
114  
115 0 my $elapsed = $aggregate->elapsed_timestr();
116 0 my $failed = $parser->failed;
117 0 my $passed = $parser->passed;
118  
119 # If we ran all the tests, and they all passed
120 0 ▶ if ($parser->is_good_plan && ($passed - $failed == $planned)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser->is_good_plan and $passed - $failed == $planned) { } 0 0 0
Condition0%0/3
$parser->is_good_plan and $passed - $failed == $planned
!ll&&!rl&&r
000
MC/DC0%0/2
$parser->is_good_plan and $passed - $failed == $planned
$parser->is_good_plan $passed - $failed == $planned
Truth table0%0/3
A and B
A= $parser->is_good_planB= $passed - $failed == $planned
ABresult
0X0
100
111
121 0 print color 'green';
122 0 print "\n--==[ Passed all our planned tests, updating db for $self->{test_id} ]==--\n";
123 } else {
124 0 print color 'red';
125 0 print "\n--==[ ERROR in testing output. ]==--\n";
126 }
127 0 print "Elapsed time: $elapsed\nPassed: $passed\nFailed: $failed\n---\n";
128 0 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 2 1; # End of App::Test::Tapat
↑ Summary